Move body with ....

iversons

24-10-2006 17:31:44

In ogrenewt, it is not recommend to use setPosition and setVelocity to move any bodies.

But, how can we move the body so? : :roll:

ProfesorX

24-10-2006 20:48:00

Define a forcecallback function, use a vector to represent the force, and use the Body::addForce() method, for example if you check Body::standardForceCallback, there is an example in how you can add a simple gravity force:


void Body::standardForceCallback( OgreNewt::Body* me )
{
//apply a simple gravity force.
Ogre::Real mass;
Ogre::Vector3 inertia;

me->getMassMatrix(mass, inertia);
Ogre::Vector3 force(0,-9.8,0);
force *= mass;

me->addForce( force );

}


In this case, since you apply a constant force, the object continued accelerating. If you want something more complex, that is, a force that does not continue increasing the acceleration, you must decide wich is the maximum speed you wish, get the actual speed, and subtract it to the speed that you wish, also you must define in which direction you are going to apply the force. In case you want to stop, you should make the m_MyVel = 0. Next i put some code, so you can get the idea.


Ogre::Real mass;
Ogre::Vector3 inertia;
me->getMassMatrix(mass, inertia);

Ogre::Vector3 m_direction(0, 0, -1)
Ogre::Vector3 V0 = me->getVelocity();
Ogre::Vector3 V1(m_direction * m_MyVel);
Ogre::Vector3 force = (V1 - V0);
force *= mass;
me->addForce(force1);


Also, i found this thread very useful to help me understand forcecallbacks or do your own forcecallback search:

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=2110&start=0

iversons

25-10-2006 16:41:12

Actually i don't really understand the velocity and the force relationship
why force = v1-v0????