i am trying to integrate my engine which is based on directX DXUT with this physics engine.
and i am stucked at the newtonupdate being not able to call the callback function settransformcallback .
i am following the samples. i am now at the 102 adding rigid body sample.
i have my code uploaded here.
http://www.mediafire.com/?uuwohwmy0jj
if you guys dont wanna bother the download, here is the code.
- Code: Select all
rigidbodyutil.cpp
// Transform callback to set the matrix of a the visual entity
static void SetTransformCallback (const NewtonBody* body, const dFloat* matrix, int threadIndex)
{
CMeshInstance* ent;
// Get the position from the matrix
dVector posit (matrix[12], matrix[13], matrix[14], 1.0f);
dQuaternion rotation;
// we will ignore the Rotation part of matrix and use the quaternion rotation stored in the body
NewtonBodyGetRotation(body, &rotation.m_q0);
// get the entity associated with this rigid body
ent = (CMeshInstance*) 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.
ent->setPrevPosition(ent->getPosition());
ent->setPrevRotationFromQuaternion(ent->getDQRotation());
//create temp quaternion with d3dxquaternion format
D3DXQUATERNION tempQ(rotation.m_q1,rotation.m_q2,rotation.m_q3,rotation.m_q0);
if (D3DXQuaternionDot(&ent->getQRotation(),&tempQ) < 0.0f) {
dQuaternion tempQ = ent->getDQRotation();
tempQ.Scale(-1.0f);
ent->setPrevRotationFromQuaternion(tempQ);
}
// set the new position and orientation for this entity
ent->setPosition(D3DXVECTOR3(posit.m_x,posit.m_y,posit.m_z));
ent->setRotationFromQuaternion(rotation);
}
and this is the createrigidbody that actually set the settransformcallback
- Code: Select all
rigidbodyutil.cpp
NewtonBody* CreateRigidBody (NewtonWorld* world, CTerrain* ent, NewtonCollision* collision, dFloat mass)
{
dVector minBox;
dVector maxBox;
dVector origin;
dVector inertia;
NewtonBody* body;
body = NewtonCreateBody (world, collision);
NewtonBodySetDestructorCallback (body, DestroyBodyCallback);
NewtonBodySetUserData (body, ent);
dMatrix matrix (ent->getQRotation(), ent->GetPosition());
NewtonBodySetMatrix (body, &matrix[0][0]);
NewtonConvexCollisionCalculateInertialMatrix (collision, &inertia[0], &origin[0]);
NewtonBodySetMassMatrix (body, mass, mass * inertia.m_x, mass * inertia.m_y, mass * inertia.m_z);
NewtonBodySetCentreOfMass (body, &origin[0]);
NewtonBodySetForceAndTorqueCallback (body, ApplyForceAndTorqueCallback);
NewtonBodySetTransformCallback (body, SetTransformCallback);
return body;
}
and this is the code that is representing createscene in the sample
- Code: Select all
void CPlayState::createScene(){
NewtonBody* floorBody;
NewtonBody* carBody;
NewtonBody* boxBody;
NewtonCollision* shape;
// crate physics//////////////////////////////////
// floor physics//////////////////////////////////
// add static floor Physics
shape = CreateNewtonBox (g_world, &m_terrain, 0);
floorBody = CreateRigidBody (g_world, &m_terrain, shape, 0.0f);
NewtonReleaseCollision (g_world, shape);
// set the Transformation Matrix for this rigid body
dMatrix matrix (m_terrain.getQRotation(), m_terrain.GetPosition() );
NewtonBodySetMatrix (floorBody, &matrix[0][0]);
// now we will use the properties of this body to set a proper world size.
dVector minBox;
dVector maxBox;
NewtonCollisionCalculateAABB (shape, &matrix[0][0], &minBox[0], &maxBox[0]);
// add a body with a box shape
shape = CreateNewtonBox (g_world, CMeshCall::getInstance()->getMeshByIndex(CRATE_ID_START), 0);
boxBody = CreateRigidBody (g_world, CMeshCall::getInstance()->getMeshByIndex(CRATE_ID_START), shape, 10.0f);
NewtonReleaseCollision (g_world, shape);
}
and this is when i call the newtonupdate.
the breakpoint is not stopping when i put breakpoint sign inside the SetTransformCallback() in rigidbodyutil.cpp
- Code: Select all
while ((loops < MAX_PHYSICS_LOOPS) && (g_timeAccumulator >= DEMO_FPS_IN_MICROSECUNDS))
{
loops ++;
// sample time before the Update
g_physicTime = game->GetTimeInMicrosenconds();
NewtonUpdate (g_world, (1.0f / DEMO_PHYSICS_FPS));
// calculate the time spent in the physical Simulation
g_physicTime = game->GetTimeInMicrosenconds() - g_physicTime;
// subtract time from time accumulator
g_timeAccumulator -= DEMO_FPS_IN_MICROSECUNDS;
physicTime ++;
physicLoopsTimeAcc += g_physicTime;
}