Jump to content



Rigid Body physics

  • You cannot reply to this topic
3 replies to this topic

#1 marcus12   Members   -  Reputation: 118

Like
0Likes
Like

Posted 07 February 2012 - 12:57 PM

Hi,
I am trying to understand rigid body mechanincs in order to implement it in my game.

I want to find out what are the properties that needs to be defined for a Rigid body so that
it can show proper collision mechanism.

eg: If I have a couple of rectangular boxes placed in a position and then I pass on a moving
ball towards it, when the ball collides with these boxes, the boxes should fall or displace
depending on the force. Similar to the kind of effect seen in a Bowling game.

I want to know how this collision can be implemented. I have declared a class with Rigidbody
properties containing

class RigidBody
{
double Mass;
vector3 Position;
Vector3 CalculateLinearVel();
Vector3 CalculateAngularVel();
vector<Vector3> normals;
}


What calculation should I have to do in order to have a proper result.

All suggestions are welcome...

Ad:

#2 l0k0   Members   -  Reputation: 104

Like
0Likes
Like

Posted 07 February 2012 - 09:15 PM

There are a number of ways you could define a rigid body depending on your needs/use cases. Some physics engines like Havok, actually have entirely seperate objects for each rigid body motion "type". However, since you are clearly interested in rolling your own here are some suggestions. What matters below is conceptual. If you used SIMD types instead that would obviously be the better way to go. However, the following is just as valid:

class RigidBody {
	// more or less required
	Quaternion orientation;
	Vector3 position;
	Vector3 force;
	Vector3 torque;
	Vector3 acceleration;
	float mass;
	Shape *shape;
	// commonly included
	Matrix worldMatrix; // or some other 'transform type'
	Matrix inverseInertia; // same as above, assuming your solver is euler  
	float inverseMass; // for speedier calculations
   // see below for more possibilities
};

There are a number of other things that you might also want to include. Honestly, the full list is more or less endless. Here are some that are more common:

- Variables for linear and angular damping (also commonly called drag, usually a float between 0 and 1)
- Variables for sleeping (see disclaimer below)
- Pointer(s) to the shapes. Remember, you ultimately have to link rigid body data to collision geometry one way or another. I'm not quite sure why you just have the normals. In my above example I have a single shape pointer, but you might want to make that a list the way box2d does. There are numerous cases where compound rigid bodies can be quite useful.
- Flags for all kinds of things. Take a look at Box2D and the way they use bitfields to store 'frozen rotation' flags and the like.

I would strongly reccomend you avoid any sleeping early in development. Make sure the simulation is stable first. Honestly, if this is just focused on a bowling game, a lot of the bullet points are totally unecessary (except perhaps the damping). If you like to learn through code samples which are 3D, I'd reccomend looking at cyclone physics. Not because it is better than Bulletor Havok, but because it is deliberately designed as a learning resource with beginners in mind.
<shameless blog plug>
A Floating Point
</shameless blog plug>

#3 l0k0   Members   -  Reputation: 104

Like
0Likes
Like

Posted 07 February 2012 - 09:28 PM

Assuming a euler solver, the gist of it will usually resemble the following:

acceleration += force * inverseMass;
Vector3 invAccel = inverseInertia * torque;
velocity += accel * dt;
rotation += angularAcceleration * dt;
// damping here if used
position += velocity * dt;
orientation += rotation * dt;
// update matrices
// clear forces 

Again, the resources are out there if you want more verbose source code.
<shameless blog plug>
A Floating Point
</shameless blog plug>

#4 marcus12   Members   -  Reputation: 118

Like
0Likes
Like

Posted 07 February 2012 - 10:02 PM

View Postl0k0, on 07 February 2012 - 09:28 PM, said:

Assuming a euler solver, the gist of it will usually resemble the following:

acceleration += force * inverseMass;
Vector3 invAccel = inverseInertia * torque;
velocity += accel * dt;
rotation += angularAcceleration * dt;
// damping here if used
position += velocity * dt;
orientation += rotation * dt;
// update matrices
// clear forces

Again, the resources are out there if you want more verbose source code.

Hi,
Thank you for the suggestion...I have more or less defined my Rigid body class in similar way.

I am using it for a 3d purpose and want to use Verlet integration instead.

Also my present problem is how to solve the Collision mechanism for the whole objects around like
when the ball strikes the rectangulat box and when the boxes collide each other while they fall
and displaces etc.

How to keep track of these collisions






We are working on generating results for this topic
PARTNERS