Elimentz
12-05-2010 19:55:35
Hi,
I managed to include OgreNewt in my project, but I'm having some trouble with generating forces. My game is a golf simulation, so an event (e.g. a mouse click) is a stick hitting the ball, which in turn should move the ball with a certain force. Now, I managed to apply some force to my ball, but only by building the force gradually: while holding the mouse button, the ball moves faster and faster; when I release the mouse button, no force is applied and the ball continues to roll until it stops
But that's not what I want... what I need is to generate more force by holding the right mouse button and instantly shoot the ball simply by clicking the left mouse button.
This is what I'm doing right now:
thx in advance
I managed to include OgreNewt in my project, but I'm having some trouble with generating forces. My game is a golf simulation, so an event (e.g. a mouse click) is a stick hitting the ball, which in turn should move the ball with a certain force. Now, I managed to apply some force to my ball, but only by building the force gradually: while holding the mouse button, the ball moves faster and faster; when I release the mouse button, no force is applied and the ball continues to roll until it stops
But that's not what I want... what I need is to generate more force by holding the right mouse button and instantly shoot the ball simply by clicking the left mouse button.
This is what I'm doing right now:
if( leftMouseClicked() )
{
OgreNewtBody->setCustomForceAndTorqueCallback<Entity>(&Entity::applyForceCallback, this);
}
else
{
OgreNewtBody->setStandardForceCallback();
}
void CustomEntity::applyForceCallback( OgreNewt::Body *OgreNewtBody, float timeStep, int threadIndex )
{
Ogre::Vector3 force(-400,0,0);
Ogre::Vector3 pointToApply(0,0,0);
Ogre::Vector3 inertia;
Ogre::Real mass;
OgreNewtBody->getMassMatrix(mass, inertia);
OgreNewtBody->addGlobalForce( force, pointToApply );
// Add gravity
Ogre::Vector3 gravity = Ogre::Vector3(0,-9.8,0) * mass;
OgreNewtBody->addForce(gravity);
}
thx in advance