Newton weirdness

Member
Posts: 156
Joined: 2002.10
Post: #1
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:

PHP Code:
int defaultID;
    
    
box = new NewtonBody*[2];
    
    
speed 0.0;
    
steer 0.0;
    
    
NewtonCollisioncollision;
    
    
world NewtonCreate(NULL,NULL);
    
    
// Setup default material
    
    
defaultID NewtonMaterialGetDefaultGroupID(world);
    
NewtonMaterialSetDefaultSoftness (worlddefaultIDdefaultID0.05f);
    
NewtonMaterialSetDefaultElasticity (worlddefaultIDdefaultID1.0f);
    
NewtonMaterialSetDefaultCollidable (worlddefaultIDdefaultID1);
    
NewtonMaterialSetDefaultFriction (worlddefaultIDdefaultID1.0f0.5f);    
    
    
    
// set the linear solver model for faster speed 
    
NewtonSetSolverModel (world8);
    
    
// set the adpative friction model for faster speed 
    
NewtonSetFrictionModel (world1);
    
    
// create the collision shape
    
collision NewtonCreateBox (world10.0f10.0f10.0fNULL); 
    
    
// create the rigid body
    
box[0] = NewtonCreateBody (worldcollision);
    
    
// Get rid of the collision
    
NewtonReleaseCollision (worldcollision);
    
    
// set the body mass and inertia
    
NewtonBodySetMassMatrix (box[0], 5.0f1.0f1.0f1.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.0f1.0f1.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.0f0.0f0.0f};
    
NewtonBodySetAngularDamping(box[0], damp);
    
    
// Create the floor
    
    // create the collision shape
    
collision NewtonCreateBox (world100.0f100.0f1.0fNULL); 
    
    
// create the rigid body
    
box[1] = NewtonCreateBody (worldcollision);
    
    
// Get rid of the collision
    
NewtonReleaseCollision (worldcollision);
    
    
// 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 NewtonBodybody)
{
    
float massIxxIyyIzz;
    
    
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
    
float force[4] = {0.0f0.0f, -mass 9.8f};
    
NewtonBodyAddForce (bodyforce);



Any light on this would be great.

Cheers

- Iain
Quote this message in a reply
Luminary
Posts: 5,131
Joined: 2002.04
Post: #2
To make an object static, don't set its mass matrix. The default has infinite mass and infinite rotational inertia.

As for the bounciness, I haven't seen it myself. You might need to up the auto-freeze threshold, or you might need to up your physics framerate. In my current experiment, 60Hz physics let a block fall through another one, where 100Hz was fine. YMMV.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #3
I eventually found that the combination of low 'softness' with high 'elasticity' is bad for stability of the system. I've gone with softness=0.15 and elasticity=0.4, which is actually pretty realistic.

I need to work out the moments of inertia of the principle axes of a cube also, as setting these too low causes the cube to spin easily when it collides. I'll try to figure it out.

- Iain
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #4
If my maths is good, I calculated the moment of inertia of the principal axes of a cube to be

Ix = M*(y^2 + z^2)/12

and similarly for the other axes.

- Iain
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Strange Newton Error Nick 19 8,110 Jul 17, 2005 01:49 AM
Last Post: OneSadCookie
  [ANN] Multithreaded Newton demo OneSadCookie 16 7,621 May 12, 2005 10:52 PM
Last Post: AnotherJake
  Squirrel Physics Kit vs. Newton blobbo 3 3,917 Apr 22, 2005 06:22 AM
Last Post: blobbo