IBethune
2005.03.24, 06:42 PM
I have implemented a simple 'bouncy block' program using the Newton physics SDK, but I have a few problems.
Firstly, when a block drops ontothe platform, it appears to settle a bit, but then sometimes 'jumps' back up into the air (in an obviously unphysical kind of way). Secondly, is there a way to set an object as static e.g. the ground? so that objects will collide and bounce off it, but it will never move?
Have a look at the demo http://www.pyramid-productions.net/Trucks.tgz (1.76 MB) to see what I mean - hopefully I will have managed to package up all the frameworks correctly this time :wacko:
The (hopefully relevant) code is:
int defaultID;
box = new NewtonBody*[2];
speed = 0.0;
steer = 0.0;
NewtonCollision* collision;
world = NewtonCreate(NULL,NULL);
// Setup default material
defaultID = NewtonMaterialGetDefaultGroupID(world);
NewtonMaterialSetDefaultSoftness (world, defaultID, defaultID, 0.05f);
NewtonMaterialSetDefaultElasticity (world, defaultID, defaultID, 1.0f);
NewtonMaterialSetDefaultCollidable (world, defaultID, defaultID, 1);
NewtonMaterialSetDefaultFriction (world, defaultID, defaultID, 1.0f, 0.5f);
// set the linear solver model for faster speed
NewtonSetSolverModel (world, 8);
// set the adpative friction model for faster speed
NewtonSetFrictionModel (world, 1);
// create the collision shape
collision = NewtonCreateBox (world, 10.0f, 10.0f, 10.0f, NULL);
// create the rigid body
box[0] = NewtonCreateBody (world, collision);
// Get rid of the collision
NewtonReleaseCollision (world, collision);
// set the body mass and inertia
NewtonBodySetMassMatrix (box[0], 5.0f, 1.0f, 1.0f, 1.0f);
// set the transformation matrix
dMatrix matrix = GetIdentityMatrix();
matrix.m_posit.m_x = 0.0f;
matrix.m_posit.m_y = 0.0f;
matrix.m_posit.m_z = 50.0f;
PrintMatrix(matrix);
NewtonBodySetMatrix (box[0], &matrix[0][0]);
// animate the body by setting the angular veocity
dVector omega (1.0f, 1.0f, 1.0f);
NewtonBodySetOmega (box[0], &omega[0]);
// Set the physics callback
NewtonBodySetForceAndTorqueCallback (box[0], PhysicsApplyForceAndTorque);
NewtonBodySetMaterialGroupID(box[0], defaultID);
NewtonBodySetLinearDamping(box[0], 0.0f);
float damp[3] = {0.0f, 0.0f, 0.0f};
NewtonBodySetAngularDamping(box[0], damp);
// Create the floor
// create the collision shape
collision = NewtonCreateBox (world, 100.0f, 100.0f, 1.0f, NULL);
// create the rigid body
box[1] = NewtonCreateBody (world, collision);
// Get rid of the collision
NewtonReleaseCollision (world, collision);
// set the body mass and inertia
//NewtonBodySetMassMatrix (box[1], 1000000.0f, 1000000.0f, 10000000.0f, 1000000.0f);
// set the transformation matrix
matrix = GetIdentityMatrix();
matrix.m_posit.m_x = 0.0f;
matrix.m_posit.m_y = 0.0f;
matrix.m_posit.m_z = -0.5f;
PrintMatrix(matrix);
NewtonBodySetMatrix (box[1], &matrix[0][0]);
NewtonBodySetMaterialGroupID(box[1], defaultID);
...
void PhysicsApplyForceAndTorque (const NewtonBody* body)
{
float mass, Ixx, Iyy, Izz;
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
float force[4] = {0.0f, 0.0f, -mass * 9.8f};
NewtonBodyAddForce (body, force);
}
Any light on this would be great.
Cheers
- Iain
Firstly, when a block drops ontothe platform, it appears to settle a bit, but then sometimes 'jumps' back up into the air (in an obviously unphysical kind of way). Secondly, is there a way to set an object as static e.g. the ground? so that objects will collide and bounce off it, but it will never move?
Have a look at the demo http://www.pyramid-productions.net/Trucks.tgz (1.76 MB) to see what I mean - hopefully I will have managed to package up all the frameworks correctly this time :wacko:
The (hopefully relevant) code is:
int defaultID;
box = new NewtonBody*[2];
speed = 0.0;
steer = 0.0;
NewtonCollision* collision;
world = NewtonCreate(NULL,NULL);
// Setup default material
defaultID = NewtonMaterialGetDefaultGroupID(world);
NewtonMaterialSetDefaultSoftness (world, defaultID, defaultID, 0.05f);
NewtonMaterialSetDefaultElasticity (world, defaultID, defaultID, 1.0f);
NewtonMaterialSetDefaultCollidable (world, defaultID, defaultID, 1);
NewtonMaterialSetDefaultFriction (world, defaultID, defaultID, 1.0f, 0.5f);
// set the linear solver model for faster speed
NewtonSetSolverModel (world, 8);
// set the adpative friction model for faster speed
NewtonSetFrictionModel (world, 1);
// create the collision shape
collision = NewtonCreateBox (world, 10.0f, 10.0f, 10.0f, NULL);
// create the rigid body
box[0] = NewtonCreateBody (world, collision);
// Get rid of the collision
NewtonReleaseCollision (world, collision);
// set the body mass and inertia
NewtonBodySetMassMatrix (box[0], 5.0f, 1.0f, 1.0f, 1.0f);
// set the transformation matrix
dMatrix matrix = GetIdentityMatrix();
matrix.m_posit.m_x = 0.0f;
matrix.m_posit.m_y = 0.0f;
matrix.m_posit.m_z = 50.0f;
PrintMatrix(matrix);
NewtonBodySetMatrix (box[0], &matrix[0][0]);
// animate the body by setting the angular veocity
dVector omega (1.0f, 1.0f, 1.0f);
NewtonBodySetOmega (box[0], &omega[0]);
// Set the physics callback
NewtonBodySetForceAndTorqueCallback (box[0], PhysicsApplyForceAndTorque);
NewtonBodySetMaterialGroupID(box[0], defaultID);
NewtonBodySetLinearDamping(box[0], 0.0f);
float damp[3] = {0.0f, 0.0f, 0.0f};
NewtonBodySetAngularDamping(box[0], damp);
// Create the floor
// create the collision shape
collision = NewtonCreateBox (world, 100.0f, 100.0f, 1.0f, NULL);
// create the rigid body
box[1] = NewtonCreateBody (world, collision);
// Get rid of the collision
NewtonReleaseCollision (world, collision);
// set the body mass and inertia
//NewtonBodySetMassMatrix (box[1], 1000000.0f, 1000000.0f, 10000000.0f, 1000000.0f);
// set the transformation matrix
matrix = GetIdentityMatrix();
matrix.m_posit.m_x = 0.0f;
matrix.m_posit.m_y = 0.0f;
matrix.m_posit.m_z = -0.5f;
PrintMatrix(matrix);
NewtonBodySetMatrix (box[1], &matrix[0][0]);
NewtonBodySetMaterialGroupID(box[1], defaultID);
...
void PhysicsApplyForceAndTorque (const NewtonBody* body)
{
float mass, Ixx, Iyy, Izz;
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
float force[4] = {0.0f, 0.0f, -mass * 9.8f};
NewtonBodyAddForce (body, force);
}
Any light on this would be great.
Cheers
- Iain