Hi,
I've not been around much to hassle people for the last few months because I've been working on other (non Box2D-specific) parts of my game, but you'll be pleased/annoyed to know that I'm back, and I could use some help getting fluids interacting with rigid bodies. There was a long thread about fluid physics (viewtopic.php?t=574) which resulted in me writing custom non-Box2D physics for fluids (the short version of the story is that Box2D is set up to deal with rigid bodies and as such just isn't sufficienty optimised to do lots of fluids - this is no criticism of Box2D, you use different tools for different jobs). However, I am still using Box2D to represent all of the static and dynamic rigid bodies in the world, so I need to find a way to get them to interact with the fluid nicely (things floating, getting swept away in floods, displacing fluid, etc). I've got a description of an algorithm from the paper I've been referring to to implement the fluids, but I'm not sure how to get it working in Box2D, which is where you nice people come in.
This is the paper: http://www.iro.umontreal.ca/labs/infogr ... S/pvfs.pdf
It's well worth a read, for those interested. What I'm trying to get working is section 6.1 of the paper - there's a diagram, a list of the equations, and an outline of the algorithm there which explains the method, and is what I'm trying to get working. There are a few parts where I'm not clear on how I should go about the implementation, and as a result of not knowing what I'm doing, the fluid either has no discernible effect on rigid bodies, or it causes them to spin around like crazy and go completely out of control. I'm also not sure how buoyancy is supposed to work, since the equations for the fluid particles do away with any concept of mass.
1 - The paper says that the particle velocity is calculated "using the difference between the current and previous particle positions". So, by subtracting the particle's position this frame from its position last frame. I'm not sure if it's quite that simple, though - my particles use Verlet integration, so velocity is calculated from the difference in positions between timesteps (rather than Euler, where newPos = oldPos + (velocity * dt)). I don't know whether to use this calculated velocity or just a simple subtraction, or if dt needs to play a part in that.
2 - The paper then says "We then compute the particle relative velocity v = vi - vp, where vp is the body velocity at the contact point". I'm using pBody->GetLinearVelocityFromWorldPoint() for that, but it's not clear to me whether the "contact point" means the world position of an intersecting particle, or the position on an edge of the body where the particle would have first collided with it, if the particles were using continuous physics. Again, I don't know if dt needs to be included in this relative velocity calculation.
3 - The paper then talks about seperating the relative velocity into normal and tangential components in order to compute an "impulse" and adding this "impulse" into force and torque buffers, which will be used to compute changes to the linear and angular velocity of the rigid body. This confuses the hell out of me. I struggle with understanding the difference between impulses and forces, but if we take the paper at face value as meaning an impulse, pBody->ApplyImpulse() doesn't touch the torque of an object, it directly affects the angular velocity (and results in uncontrollably spinning objects). So should I be ignoring the paper's terminology and calling pBody->ApplyForce() instead, because that updates the torque rather than the angular velocity directly? ApplyForce() seems to have very little impact on the bodies at all.
Sorry if this isn't entirely Box2D-specific. I just wanted to get an idea about how people might use Box2D in conjunction with an algorithm like this.
I've not been around much to hassle people for the last few months because I've been working on other (non Box2D-specific) parts of my game, but you'll be pleased/annoyed to know that I'm back, and I could use some help getting fluids interacting with rigid bodies. There was a long thread about fluid physics (viewtopic.php?t=574) which resulted in me writing custom non-Box2D physics for fluids (the short version of the story is that Box2D is set up to deal with rigid bodies and as such just isn't sufficienty optimised to do lots of fluids - this is no criticism of Box2D, you use different tools for different jobs). However, I am still using Box2D to represent all of the static and dynamic rigid bodies in the world, so I need to find a way to get them to interact with the fluid nicely (things floating, getting swept away in floods, displacing fluid, etc). I've got a description of an algorithm from the paper I've been referring to to implement the fluids, but I'm not sure how to get it working in Box2D, which is where you nice people come in.
This is the paper: http://www.iro.umontreal.ca/labs/infogr ... S/pvfs.pdf
It's well worth a read, for those interested. What I'm trying to get working is section 6.1 of the paper - there's a diagram, a list of the equations, and an outline of the algorithm there which explains the method, and is what I'm trying to get working. There are a few parts where I'm not clear on how I should go about the implementation, and as a result of not knowing what I'm doing, the fluid either has no discernible effect on rigid bodies, or it causes them to spin around like crazy and go completely out of control. I'm also not sure how buoyancy is supposed to work, since the equations for the fluid particles do away with any concept of mass.
1 - The paper says that the particle velocity is calculated "using the difference between the current and previous particle positions". So, by subtracting the particle's position this frame from its position last frame. I'm not sure if it's quite that simple, though - my particles use Verlet integration, so velocity is calculated from the difference in positions between timesteps (rather than Euler, where newPos = oldPos + (velocity * dt)). I don't know whether to use this calculated velocity or just a simple subtraction, or if dt needs to play a part in that.
2 - The paper then says "We then compute the particle relative velocity v = vi - vp, where vp is the body velocity at the contact point". I'm using pBody->GetLinearVelocityFromWorldPoint() for that, but it's not clear to me whether the "contact point" means the world position of an intersecting particle, or the position on an edge of the body where the particle would have first collided with it, if the particles were using continuous physics. Again, I don't know if dt needs to be included in this relative velocity calculation.
3 - The paper then talks about seperating the relative velocity into normal and tangential components in order to compute an "impulse" and adding this "impulse" into force and torque buffers, which will be used to compute changes to the linear and angular velocity of the rigid body. This confuses the hell out of me. I struggle with understanding the difference between impulses and forces, but if we take the paper at face value as meaning an impulse, pBody->ApplyImpulse() doesn't touch the torque of an object, it directly affects the angular velocity (and results in uncontrollably spinning objects). So should I be ignoring the paper's terminology and calling pBody->ApplyForce() instead, because that updates the torque rather than the angular velocity directly? ApplyForce() seems to have very little impact on the bodies at all.
Sorry if this isn't entirely Box2D-specific. I just wanted to get an idea about how people might use Box2D in conjunction with an algorithm like this.
