my OgreNewt::Body slides when I apply a force

Felipe

23-06-2007 02:18:28

my OgreNewt::Body slides when I apply a force in it, what I do to not slide ?

--------------
my code:

Ogre::Vector3 dir, vec;
Ogre::Quaternion camorient = msnCam->getWorldOrientation();
vec = Ogre::Vector3(0,0,-1);

dir = camorient * vec;

Ogre::String name;

name = " Body2 "+Ogre::StringConverter::toString( 1 );

ent = mSceneMgr->createEntity( name, "ninja.mesh" );

node = mSceneMgr->getRootSceneNode()->createChildSceneNode( name );

node->attachObject( ent );

node->pitch(Ogre::Radian(Math::PI));


node->setScale( Vector3(0.02,0.02,0.02));


ent->setMaterialName( "Examples/Ninja" );
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,0.05,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(0);

// 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_CollisionBody0, 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) );

Ogre::Vector3 myEntityPos = node->getPosition();
Ogre::Quaternion dirVector = node->getOrientation();

------



void OgreNewtonFrameListener::ForceCallback_CollisionBody0(OgreNewt::Body * me)
{
//Reset to 0;
mForce = Vector3(0,0,0);
mAnimationState = ent->getAnimationState( "Walk" );
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );

//Add x and z then * by rotation
mForce.x += adjForce.x;
mForce.y += adjForce.y;
mForce.z += adjForce.z;


me->setOmega(me->getOgreNode()->getOrientation() * Vector3 (0, mForce.x, 0));
//me->addTorque( me->getOgreNode()->getOrientation() * Vector3 (0, mForce.x, 0)); //even better way to make look up/down work!


me->addGlobalForce( me->getOgreNode()->getOrientation() * Vector3(0, 0, mForce.z), me->getOgreNode()->getPosition());
Ogre::Vector3 gravity = Ogre::Vector3(0,-9.8,0) * 1.0;
me->addForce( gravity );

}