I have tried manually setting elasticity. Setting it to 0 somewhat reduces how high the ball bounces, but it still bounces forever.
I should also note, if I change the sphere to a box, it works fine.
Here is the Newton related code (Im using Newton with Irrlicht):
- Code: Select all
nWorld=NewtonCreate();
//ADD GROUND
ISceneNode* mapNode=smgr->addCubeSceneNode(10,0,-1,vector3df(0),vector3df(0),vector3df(1,0.1,1));
NewtonBody* mapBody=NewtonCreateBody(nWorld,NewtonCreateBox(nWorld,10,1,10,0,NULL),&mapNode->getAbsoluteTransformation().pointer()[0]);
UserData* userData = new UserData;//struct for holding Irrlicht ISceneNode*
userData->node=mapNode;
NewtonBodySetUserData(mapBody,userData);
//ADD SPHERE
ISceneNode* node=smgr->addSphereSceneNode(1,8,0,-1,vector3df(0,1,0),vector3df(0),vector3df(1,1,1));
NewtonBody* nodeBody=NewtonCreateBody(nWorld,NewtonCreateSphere(nWorld,1,1,1,0,NULL),&node->getAbsoluteTransformation().pointer()[0]);
NewtonBodySetMassMatrix(nodeBody,1,1,1,1);
NewtonBodySetForceAndTorqueCallback(nodeBody,NewtonApplyForceAndTorqueCallback);
NewtonBodySetTransformCallback(nodeBody,NewtonSetTransformCallback);
userData = new UserData;
userData->node=node;
NewtonBodySetUserData(nodeBody,userData);
.....
NewtonUpdate(nWorld,17); //This is in a loop that is called 60 times per second
and here are the callbacks
- Code: Select all
void World::NewtonSetTransformCallback(const NewtonBody* body, const float* matrix, int threadIndex){
void* data= NewtonBodyGetUserData(body);
UserData* userData=(UserData*)data;
ISceneNode* node = (ISceneNode*)userData->node;
matrix4 mat;
mat.setM(matrix);
node->setPosition(mat.getTranslation());
node->setRotation(mat.getRotationDegrees());
}
void World::NewtonApplyForceAndTorqueCallback(const NewtonBody* body,float timestep, int threadIndex){
float force[] = {0,-5,0};
NewtonBodyAddForce(body,&force[0]);
}