Arkasha
16-05-2006 23:24:06
Hey,
I tried to work out a PlayerForceCallback Method, it works ok but still is glitched :
I am trying to use two thrusters to move the player like a helicopter like in the OgreNewt wiki http://walaber.com/newton_wiki/index.php?title=How_can_I_control_an_object_using_a_physics_engine%3F but i am very unhappy with
body->setOmega( Vector3::ZERO );
to stop rotating though...
I also kindda guessing when I am using the damping...
Anyway, I hope some of you can use it and perhaps others may help me improve it!
I tried to work out a PlayerForceCallback Method, it works ok but still is glitched :
void TocNewtonForceAndTorqueCallback::PlayerRelativeForceCallback( OgreNewt::Body *body ){
int playerDirState;
int playerRotateState;
int const ROTATION_SPEED = 2; // must be positive
int const SPEED = 10;
Ogre::Real mass;
Ogre::Vector3 inertia;
Ogre::Quaternion orient;
Ogre::Vector3 pos;
body->getPositionOrientation( pos, orient );
body->getMassMatrix( mass, inertia );
//Gravity
Ogre::Vector3 gravity( 0, -9.8, 0 );
Ogre::Vector3 f1( 0, 0, 0 );
Ogre::Vector3 f2( 0, 0, 0 );
Player* player = (Player*) body->getUserData();
playerDirState = player->getDirState();
playerRotateState = player->getRotateState();
body->setAngularDamping( Ogre::Vector3( Ogre::Vector3( 50, 50, 50 ) ) );
body->setLinearDamping( 50 );
// Stop rotating
if( playerRotateState == Player::ROTATE_STATE_IDLE )
{
body->setOmega( Vector3::ZERO );
}
// turn right
if( playerRotateState == Player::ROTATE_STATE_RIGHT )
{
f1.z += 0.5;
f2.z -= 0.5;
}
// turn left
if( playerRotateState == Player::ROTATE_STATE_LEFT )
{
f1.z -= 0.5;
f2.z += 0.5;
}
// be idle
if( playerDirState == Player::DIR_STATE_IDLE)
{
}
// go forwards
if( playerDirState == Player::DIR_STATE_FORWARDS)
{
f1.z += SPEED;
f2.z += SPEED;
}
// go backwards
if( playerDirState == Player::DIR_STATE_BACKWARDS)
{
f1.z -= SPEED;
f2.z -= SPEED;
}
Vector3 centerPos( 0, 0, 0 );
Vector3 leftThrust( 5, 0, 0 );
Vector3 rightThrust( -5, 0, 0 );
body->addLocalForce( f1* mass , leftThrust );
body->addLocalForce( f2* mass , rightThrust );
body->addLocalForce( gravity* mass , centerPos );
}
I am trying to use two thrusters to move the player like a helicopter like in the OgreNewt wiki http://walaber.com/newton_wiki/index.php?title=How_can_I_control_an_object_using_a_physics_engine%3F but i am very unhappy with
body->setOmega( Vector3::ZERO );
to stop rotating though...
I also kindda guessing when I am using the damping...
Anyway, I hope some of you can use it and perhaps others may help me improve it!