[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The inheritance hierarchy for bodies looks something like this:
ctPhysicalEntity => ctWorld => ctArticulatedBody => ctDynamicEntity => ctSoftBody => ctRigidBody |
Here is a brief summary of the various bodies:
ctPhysicalEntity
ctArticulatedBody
ctDynamicEntity
ctSoftBody
ctRigidBody
Let's look at `ctRigidBody'. Probably the most common type of body. Any solid object without moving parts is most likely a rigid body. The best way to create one and add it to a world is like so:
ctWorld phyz_world; ctRigidBody* rb = ctRigidBody::new_ctRigidBody(); phyz_world.add_rigidbody(rb); |
This will set up reference frame correctly. Creating a rigid-body with the C++ `new' operator will not do so.
Now you need to specify some properties: position, mass, and an inertia tensor. Note: Be sure you set the mass before calculating the `I_tensor', since `I_tensor' is dependent upon mass.
rb->set_m(15.0); // Set mass. rb->set_pos(0, 10, 0); // Set position. // Defaults to zero if you omit following step. rb->set_v(ctVector3(1, 0, 0)); // Calculate inertia tensor of a rectangular block. rb->calc_simple_I_tensor(0.2, 0.4, 0.2); |
That last step will calculate an inertia tensor for a solid rectangular block of uniform density, with dimensions of width 0.2, height 0.4 and depth 0.2 (x,y,z). An inertia tensor is used to calculate the response to angular forces and impulses. Every shape of object has a different type of inertia tensor. You must set a mass before you specify the inertia tensor.
You can set the orientation of the body directly (by setting the transformation matrix), or like so:
// Axis around which to rotate body. ctVector3 rotaxisxy(1, 1, 0); rb->rotate_around_line(rotaxisy, degree_to_rad(45)); |
Angular velocity is specified by a vector that points in the direction of the axis of rotation. The magnitude of that vector determines how fast it rotates.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |