joint problem

TomTomson

06-08-2009 11:48:00

Hi guys,

I am a beginner with OGRE and PhysiX and try to play a little with joints. My "simulation" is doing fine as long as I do not use joints, means objects are falling down (great I know...). Now I want to implement a fixed joint between 2 boxes. After I run the simulation (gScene->simulate(6.0f/60.0f) I always get a wrong quaternion back ( actor->getGlobalOrientationQuat(); ) Wrong means QNANO and then OGRE is giving assertion fault...


Here is my code:

//global var
static NxPhysicsSDK* gPhysicsSDK = NULL;
static NxScene* gScene = NULL;
SceneNode *box1;
SceneNode *box2;
bool mRun=true;
NxActor* leg1 = NULL;
NxActor* leg2 = NULL;
CEGUI::Window* StatusLine;
NxD6Joint* d6Joint=NULL;


void createScene(void)
{
...

NxBodyDesc bodyDesc;
bodyDesc.linearVelocity = NxVec3(0.0f,0.0f,0.0f);
bodyDesc.angularDamping = 0.1f;
bodyDesc.linearDamping= 0.1f;
NxBoxShapeDesc boxDesc;
boxDesc.dimensions = NxVec3(0.5f, 0.5f, 25.0f);
boxDesc.materialIndex= newMaterial->getMaterialIndex();
NxActorDesc actorDesc;
actorDesc.setToDefault();
actorDesc.shapes.pushBack(&boxDesc);
actorDesc.body = &bodyDesc;
actorDesc.density = 1.0f;
actorDesc.name ="leg11";
//leg1->setSolverIterationCount(128);
leg1=gScene->createActor(actorDesc);

actorDesc.setToDefault();
bodyDesc.linearVelocity = NxVec3(0.0f,0.0f,0.0f);
bodyDesc.angularDamping = 0.1f;
bodyDesc.linearDamping= 0.1f;
boxDesc.dimensions = NxVec3(0.5f, 0.5f, 25.0f);
boxDesc.materialIndex= newMaterial->getMaterialIndex();
actorDesc.shapes.pushBack(&boxDesc);
actorDesc.body = &bodyDesc;
actorDesc.density = 10.0f;
actorDesc.name ="leg12";
leg2=gScene->createActor(actorDesc);

NxD6JointDesc d6Desc;
d6Desc.setToDefault();
d6Desc.actor[0] =leg1;
d6Desc.actor[1] =leg2;
NxVec3 globalAnchor(0.0f, 0.0f, 0.0f);
NxVec3 globalAxis(0.0f,0.0f,1.0f);
d6Desc.setGlobalAnchor(leg1->getGlobalPosition());//important when DOFs are unlocked.
d6Desc.setGlobalAxis(globalAxis);
d6Desc.twistMotion = NX_D6JOINT_MOTION_LOCKED;//create a fixed joint.
d6Desc.swing1Motion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.swing2Motion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.xMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.yMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.zMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.projectionMode = NX_JPM_POINT_MINDIST;
d6Joint=(NxD6Joint *)gScene->createJoint(d6Desc);
}

void reset(){

NxQuat quat;
quat.w=0;
quat.x=0;
quat.y=0;
quat.z=0;

if(leg1->getName()=="leg11"){
leg1->setGlobalOrientationQuat(quat);
NxVec3 vel(0.0f,0.0f,0.0f);
leg1->setLinearVelocity(vel);
leg1->setAngularVelocity(vel);
NxVec3 pos(0.0f,10.0f,0.0f);
leg1->setGlobalPosition(pos);

//actor->addTorque(NxVec3(100.0f, 100.0f, 100.0f),NX_FORCE,true);
//actor->addLocalForceAtLocalPos(NxVec3(-1600.0f, 0.0f, 0.0f),NxVec3(0.0f, 0.0f, 0.0f),NX_FORCE,true);
//actor->addForceAtPos(NxVec3(-159.50f, 0.0f, 0.0f),NxVec3(20.0f, 25.0f, 0.0f),NX_FORCE,true);
}
if(leg2->getName()=="leg12"){
//quat.w=sqrt(0.5f);
//quat.x=sqrt(0.5f);
leg2->setGlobalOrientationQuat(quat);
NxVec3 vel(0.0f,0.0f,0.0f);
leg2->setLinearVelocity(vel);
leg2->setAngularVelocity(vel);
NxVec3 pos(10.0f,10.0f,0.0f);
leg2->setGlobalPosition(pos);

//actor->addTorque(NxVec3(100.0f, 100.0f, 100.0f),NX_FORCE,true);
//actor->addLocalForceAtLocalPos(NxVec3(700.0f, 0.0f, 0.0f),NxVec3(25.0f, 0.0f, 0.0f),NX_FORCE,true);
//actor->addForceAtPos(NxVec3(695.0f, 0.0f, 0.0f),NxVec3(0.0f, 50.0f, 0.0f),NX_FORCE,true);
}
}
bool frameStarted(const FrameEvent &evt)
{
if(mMouse)
mMouse->capture();
if(mKeyboard)
mKeyboard->capture();
mCamNode->translate(mDirection * evt.timeSinceLastFrame, Node::TS_LOCAL);
if (mRun) gScene->simulate(6.0f/60.0f);
NxVec3 pos;
NxQuat quat;
if(leg1->getName()=="leg11"){
pos=leg1->getGlobalPosition();
quat=leg1->getGlobalOrientationQuat();

char buffer[200];
//sprintf( buffer, "x= %f y= %f z= %f",pos.x, pos.y, pos.z );// C4996

//StatusLine->setText(buffer);
box1->setOrientation(quat.w,quat.x,quat.y,quat.z); //here comes the assertion fault box1->setPosition(pos.x,pos.y,pos.z);
}
if(leg2->getName()=="leg12"){
pos=leg2->getGlobalPosition();
quat=leg2->getGlobalOrientationQuat();
char buffer[200];
NxMat34 pose=leg2->getGlobalPose();
sprintf( buffer, "x= %f y= %f z= %f",pose.t.x, pose.t.y, pose.t.z );// C4996

StatusLine->setText(buffer); // here you see QNANO on the screen
//box2->setOrientation(quat.w,quat.x,quat.y,quat.z);
//box2->setPosition(pos.x,pos.y,pos.z);
}
// Fetch simulation results
gScene->flushStream();
gScene->fetchResults(NX_RIGID_BODY_FINISHED, true);

return mContinue;
}



Thanks for your Help
Tom