deshan
08-05-2009 21:00:20
Hi
I have a problem related to the structure of the a scenenode attached to a OgreNewt::Body. I have created a floor node and a another node to attach another entity(Ogre Ninja). But when I tried to make a force to the OgreNewt::Body along +z axis or -x axis the object does not move. And it moves for -z and +x axis. I cannot understand how they behave very complicated,
This is my code, GameApplication::myCallBackFunction commented the situation where the object does move and does not move
please help me.
I have a problem related to the structure of the a scenenode attached to a OgreNewt::Body. I have created a floor node and a another node to attach another entity(Ogre Ninja). But when I tried to make a force to the OgreNewt::Body along +z axis or -x axis the object does not move. And it moves for -z and +x axis. I cannot understand how they behave very complicated,
This is my code, GameApplication::myCallBackFunction commented the situation where the object does move and does not move
void GameApplication::cretaPhysicsAppliedNodes(Ogre::SceneNode* node)
{
// CREATE FLOOR OBJECT
Ogre::Vector3 size(10000.0f,1.0f,10000.0f);
Ogre::Entity* ent1 = mSceneMgr->createEntity( "floorobj", "box.mesh" );
node->attachObject( ent1 );
node->setScale( size );
// collision object represents the shape
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box( mWorld, size );
// create rigid body object from collision object
OgreNewt::Body* floorbody = new OgreNewt::Body( mWorld, col );
floorbody->attachToNode( node );
floorbody->setPositionOrientation( Ogre::Vector3(0.0f,0.0f,0.0f), Ogre::Quaternion::IDENTITY );
delete col;
// CREATE NINJA OBJECT
size = Ogre::Vector3( 1, 1, 1 );
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("NinjaNode");
ent1 = mSceneMgr->createEntity("Ninja", "ninja.mesh");
node->attachObject( ent1 );
node->setScale(size);
// rigid body.
col = new OgreNewt::CollisionPrimitives::Box( mWorld,size );
OgreNewt::Body* ninjaBody = new OgreNewt::Body( mWorld, col );
ninjaBody->attachToNode( node );
// initial position
ninjaBody->setPositionOrientation( Ogre::Vector3(0,100,0), Ogre::Quaternion::IDENTITY );
delete col;
Ogre::Real mass = 75.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( mass, node->getScale());
ninjaBody->setMassMatrix( mass, inertia );
ninjaBody->setAutoFreeze(0);
ninjaBody->setStandardForceCallback();
ninjaBody->setCustomForceAndTorqueCallback(boost::bind(&GameApplication::myCallBackFunction,this,_1));
}
void GameApplication::myCallBackFunction(OgreNewt::Body* body)
{
/* object move */ body->addForce(Ogre::Vector3(2000, -100, 0 ));
/* object move */ // body->addForce(Ogre::Vector3(0, -100, 2000 ));
/* object does not move */ // body->addForce(Ogre::Vector3(-2000, -100, 0 ));
/* object does not move */ // body->addForce(Ogre::Vector3(0, -100, -2000 ));
}
please help me.