[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Physics module status note, more things...



Hey there, Greg!

Yep, I did a test implementation of both drag and bouyancy and it looked 
nice, but had a bad flaw: it didn't take not of contact points. Granted, 
contact points aren't important when the object is fully submerged, but
once on the surface it's needed to calculate displacement and rotational
velocity.

In my experiment the boxes floating on top of water would be tilted the 
angle they had when rotation was stopped (due to drag). So, even though my 
test looked good under water it sucked when floating.
I wasn't sure how to overcome this problem so I scrapped it all until 
someone more capable than me takes a look at it.

Here's a few things that might be useful to anybody who has a go with this:

1) Drag is calculated using the fluid viscosity and the surface area 
  exposed in the linear velocity direction, i.e the surface that hits the 
  water head on. Drag is applied in direct opposite to the linear velocity 
  and may be equal to linear velocity (like with viscoisity 1.0, i.e 
  solid), but never more. (just keeping it simple)
  You might also want to take in account the body friction of the solid,
  maybe you're making a shaved vs hairy swimmers game? :)

2) Bouyancy is calculated using standard displacement, but for 2D instead of 
  3D, basically density * area. Density is mass / area. The way I solved 
  this was to be practical. To make things easy I decided that the area 
  would remain if density or mass was changed, just so I, as a game 
  programmer, didn't have to do any density or mass calculations in game
  code.

  body.mass = 100 # set density to mass / area, area remains the same
  body.density = 10 # set mass to density * area, area remains the same
  body.shape.size = 50,50 # sets mass to density * area, density remains

  This solved a lot of problems, but I had to add width and height to
  the shape or reverse the rotational transformation, this needs to
  be solved nicer. Maybe cache width and height in the shape?

  This worked great aside from the fact that the whole area was used
  instead of calculating the submerged area only. This will be vital
  for correct floating.

If someone who is more capable would have go at implementing viscosity 
support and rudimentary support for netwonian fluid bodies I think it
can be done with ease and without disrupting the current implementation
of solids too much. I definately think this is the more simple and usable 
way to do it than adding general dampers to the world or single bodies.

I think this would be very useful for making games, maybe the characters 
will finally float instead of dying when hitting water? :)

/Peter


On 2008-08-18 (Mon) 13:17, Greg Ewing wrote:
> Peter Gebauer wrote:
>
>> In our simple simulation a constant drag force applied in opposite to  
>> gravity should be sufficient
>
> No, that won't work, because the object will still accelerate
> indefinitely, or decelerate until it stops completely, whereas
> it should reach some terminal velocity.
>
>> we don't have to take in account all the other details of non-solid 
>> friction.
>
> It doesn't have to be complicated, just a force proportional
> to the velocity of the object, with a coefficient depending
> on the fluid and the object concerned.
>
> -- 
> Greg
>
>