Felipe
17-06-2007 12:14:10
I only translate my character, but i dont known how rotate my character
Help me?
my code:
My rigid body
------------------------------------------------------------------------
ent = mSceneMgr->createEntity( name, "robot.mesh" );
node = mSceneMgr->getRootSceneNode()->createChildSceneNode( name );
node->attachObject( ent );
node->setScale( Vector3(0.05,0.05,0.05));
ent->setMaterialName( "Examples/Robot" );
ent->setNormaliseNormals(true);
Ogre::Vector3 size2(2.0,0.5,2.0);
// again, make the collision shape.
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,2,1) );
// then make the rigid body.
body2 = new OgreNewt::Body( m_World, col );
body2->setUserData( this );
//no longer need the collision shape object
delete col;
Ogre::Real mass = size2.x * size2.y * size2.z * 2.5;
Ogre::Vector3 inertia(1.0,1.0,1.0);
body2->setMassMatrix( mass, inertia );
body2->setAutoFreeze(1);
// attach to the scene node.
body2->attachToNode( node );
// this is a standard callback that simply add a gravitational force (-9.8*mass) to the body.
body2->setCustomForceAndTorqueCallback<OgreNewtonFrameListener>( &OgreNewtonFrameListener::ForceCallback_CollisionBody, this );
// set the initial orientation and velocity!
body2->setPositionOrientation( Ogre::Vector3(5.0,-4.9,0.0), Ogre::Quaternion::IDENTITY );
OgreNewt::BasicJoints::UpVector* uv = new OgreNewt::BasicJoints::UpVector( m_World, body2, Ogre::Vector3( Ogre::Vector3::UNIT_Y) );
---------------------------------
my keyboard event
------------------------------------------------
if (mKeyboard->isKeyDown(OIS::KC_I))
addForce2.z -= 20.0;
if (mKeyboard->isKeyDown(OIS::KC_K))
addForce2.z += 20.0;
if (mKeyboard->isKeyDown(OIS::KC_J))
addForce2.x -= 20.0;
if (mKeyboard->isKeyDown(OIS::KC_L))
addForce2.x += 20.0;
addForce(addForce2);
-----------------------------------
my method ForceCallback
void OgreNewtonFrameListener::ForceCallback_CollisionBody(OgreNewt::Body * me)
{
//Reset to 0;
mForce = Vector3(0,0,0);
//Add x and z then * by rotation
mForce.x += adjForce.x;
mForce.y += adjForce.y;
mForce.z += adjForce.z;
//mForce = mDirection * mForce;
me->addForce(mForce);
}
help me please!!!
Help me?
my code:
My rigid body
------------------------------------------------------------------------
ent = mSceneMgr->createEntity( name, "robot.mesh" );
node = mSceneMgr->getRootSceneNode()->createChildSceneNode( name );
node->attachObject( ent );
node->setScale( Vector3(0.05,0.05,0.05));
ent->setMaterialName( "Examples/Robot" );
ent->setNormaliseNormals(true);
Ogre::Vector3 size2(2.0,0.5,2.0);
// again, make the collision shape.
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( m_World, Ogre::Vector3(1,2,1) );
// then make the rigid body.
body2 = new OgreNewt::Body( m_World, col );
body2->setUserData( this );
//no longer need the collision shape object
delete col;
Ogre::Real mass = size2.x * size2.y * size2.z * 2.5;
Ogre::Vector3 inertia(1.0,1.0,1.0);
body2->setMassMatrix( mass, inertia );
body2->setAutoFreeze(1);
// attach to the scene node.
body2->attachToNode( node );
// this is a standard callback that simply add a gravitational force (-9.8*mass) to the body.
body2->setCustomForceAndTorqueCallback<OgreNewtonFrameListener>( &OgreNewtonFrameListener::ForceCallback_CollisionBody, this );
// set the initial orientation and velocity!
body2->setPositionOrientation( Ogre::Vector3(5.0,-4.9,0.0), Ogre::Quaternion::IDENTITY );
OgreNewt::BasicJoints::UpVector* uv = new OgreNewt::BasicJoints::UpVector( m_World, body2, Ogre::Vector3( Ogre::Vector3::UNIT_Y) );
---------------------------------
my keyboard event
------------------------------------------------
if (mKeyboard->isKeyDown(OIS::KC_I))
addForce2.z -= 20.0;
if (mKeyboard->isKeyDown(OIS::KC_K))
addForce2.z += 20.0;
if (mKeyboard->isKeyDown(OIS::KC_J))
addForce2.x -= 20.0;
if (mKeyboard->isKeyDown(OIS::KC_L))
addForce2.x += 20.0;
addForce(addForce2);
-----------------------------------
my method ForceCallback
void OgreNewtonFrameListener::ForceCallback_CollisionBody(OgreNewt::Body * me)
{
//Reset to 0;
mForce = Vector3(0,0,0);
//Add x and z then * by rotation
mForce.x += adjForce.x;
mForce.y += adjForce.y;
mForce.z += adjForce.z;
//mForce = mDirection * mForce;
me->addForce(mForce);
}
help me please!!!