I'm developing a test Game using Newton Game Dynamics and Ogre3d. I've set all Callbacks correctly and there should be 2 objects, one should falling down to the other. But when I starts the Game there happens.... Nothing! The Objects appear, but they float in the air.
Thats the simplified code:
Create Scene:
- Code: Select all
void Game::createScene(void)
{
NewtonCollision* shape;
World = NewtonCreate ();
NewtonSetPlatformArchitecture (World, 0);
Ogre::Vector3 minSize (-500000.0f, -500000.0f, -500000.0f);
Ogre::Vector3 maxSize ( 500000.0f, 500000.0f, 500000.0f);
NewtonSetWorldSize (World, &minSize[0], &maxSize[0]);
NewtonSetSolverModel (World, 0);
Ogre::Vector3 size(2500,2500,2500);
Ogre::Entity* Map = mSceneMgr->createEntity("Map", MapName);
Ogre::SceneNode* MapNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("MapNode",Ogre::Vector3(0,-842,0));
MapNode->attachObject(Map);
MapNode->scale(2500, 2500, 2500 );
Ogre::Entity* PlayerAct = mSceneMgr->createEntity("Player", PlayerName);
Ogre::SceneNode* PlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("PlayerNode",Ogre::Vector3(500,500,500));
PlayerNode->attachObject(PlayerAct);
size = Ogre::Vector3(1,1,1);
mSceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1));
Ogre::Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);
shape = CreateNewtonBox (World, MapNode, 0);
floorBody = CreateRigidBody (World, MapNode, shape, 0.0f);
NewtonReleaseCollision (World, shape);
Ogre::Matrix4 matrix (MapNode->getOrientation());
matrix.setTrans (MapNode->getPosition());
NewtonBodySetMatrix (floorBody, &matrix[0][0]);
shape = CreateNewtonBox (World, PlayerNode, 1);
playerBody = CreateRigidBody (World, PlayerNode, shape, 0.0f);
NewtonReleaseCollision (World, shape);
Ogre::Matrix4 matrix2 (MapNode->getOrientation());
matrix2.setTrans (MapNode->getPosition());
NewtonBodySetMatrix (playerBody, &matrix2[0][0]);
}
Update Physics,called each Frame:
- Code: Select all
void Game::Physic(Ogre::FrameEvent evt)
{
NewtonUpdate (World,evt.timeSinceLastFrame);
}
- Code: Select all
NewtonCollision* CreateNewtonBox (NewtonWorld* world, Ogre::SceneNode* nod, int shapeId)
{
Ogre::Vector3 minBox;
Ogre::Vector3 maxBox;
Ogre::AxisAlignedBox box;
box=nod->_getWorldAABB();
minBox = box.getMinimum();
maxBox = box.getMaximum();
Ogre::Vector3 size (maxBox - minBox);
Ogre::Vector3 origin ((maxBox + minBox)* 0.5f);
Ogre::Matrix4 offset= Ogre::Matrix4::IDENTITY;
offset.setTrans(origin);
return NewtonCreateBox (world, size.x, size.y, size.z, shapeId, &offset[0][0]);
}
- Code: Select all
NewtonBody* CreateRigidBody (NewtonWorld* world, Ogre::SceneNode* ent, NewtonCollision* collision, dFloat mass)
{
Ogre::Vector3 minBox;
Ogre::Vector3 maxBox;
Ogre::Vector3 origin;
Ogre::Vector3 inertia;
NewtonBody* body;
Ogre::Matrix4 mat;
mat=Ogre::Matrix4::IDENTITY;
body = NewtonCreateBody (world, collision,&mat[0][0]);
NewtonBodySetDestructorCallback (body, DestroyBodyCallback);
NewtonBodySetUserData (body, ent);
Ogre::Matrix4 matrix (ent->getOrientation());
matrix.setTrans(ent->getPosition());
NewtonBodySetMatrix (body, &matrix[0][0]);
NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);
NewtonBodySetMassMatrix (body, mass, mass * inertia.x, mass * inertia.y, mass * inertia.z);
NewtonBodySetCentreOfMass (body, &origin[0]);
NewtonBodySetForceAndTorqueCallback (body, ApplyForceAndTorqueCallback);
NewtonBodySetTransformCallback (body, SetTransformCallback);
return body;
}
My Callbacks:
- Code: Select all
void SetTransformCallback (const NewtonBody* body, const dFloat* matrix, int threadIndex)
{
Ogre::SceneNode* ent;
Ogre::Vector3 oldposition;
Ogre::Quaternion oldrotation;
// Get the position from the matrix
Ogre::Vector3 posit (matrix[12], matrix[13], matrix[14]);
Ogre::Quaternion rotation;
Ogre::Radian rad;
// we will ignore the Rotation part of matrix and use the quaternion rotation stored in the body
rad = rotation.getPitch();
float f = rad.valueRadians();
NewtonBodyGetRotation(body,&f);
// get the entity associated with this rigid body
ent = (Ogre::SceneNode*) NewtonBodyGetUserData(body);
// since this tutorial run the physics and a different fps than the Graphics
// we need to save the entity current transformation state before updating the new state.
oldposition = ent->getPosition();
oldrotation = ent->getOrientation();
if (ent->getOrientation().Dot(rotation) < 0.0f) {
oldrotation*(-1.0f);
}
// set the new position and orientation for this entity
ent->setPosition(posit);
ent->setOrientation(rotation);
}
- Code: Select all
void DestroyBodyCallback (const NewtonBody* body)
{
}
- Code: Select all
void ApplyForceAndTorqueCallback (const NewtonBody* body, dFloat timestep, int threadIndex)
{
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
dFloat mass;
// for this tutorial the only external force in the Gravity
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
Ogre::Vector3 gravityForce (0.0f, mass * -10, 0.0f);
NewtonBodyAddForce(body, &gravityForce[0]);
}
I set one breakpoint on each callback in my IDE (VC++ 2010) and they are not reached.

Cookiezzz