# Rigid Body physics

This topic is 2499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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...

##### Share on other sites
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 Bullet or Havok, but because it is deliberately designed as a learning resource with beginners in mind.

##### Share on other sites
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.

##### Share on other sites

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

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633677
• Total Posts
3013281
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!