Moderator: Alain
walaber wrote:I kind of like "OgreNewt"
vioid ThrottleUp()
{
Ogre::Matrix3 m3;
Ogre::Quaternion q;
MySpaceShip->ThrottleSetting +=0.1;
if (MySpaceShip->ThrottleSetting > 1.0f) MySpaceShip->ThrottleSetting = 1.0f;
// get vector of ship and apply force
// Get the current orientation of the ship.
q = MySpaceShip->NodeShipControl->getOrientation();
// Convert the Quaternion to a matrix3
q.ToRotationMatrix(m3);
// Apply the thrust
MySpaceShip->DirectionalForce = m3 *
Ogre::Vector3(0, 0, (MySpaceShip->ThrottleSetting * MySpaceShip->Thrust()));
} // ThrottleUp
SpaceShipApplyForceAndTorqueCallBack (const NewtonBody* nBody)
{
float mass=0, Ixx=0, Iyy=0, Izz=0;
Ogre::Vector3 Oforce(0,0,0), Otorque(0,0,0);
Ogre::Vector3 Gravity = Ogre::Vector3 NEWTON_DEFAULT_GRAVITY;
NewtonBodyGetMassMatrix (nBody, &mass, &Ixx, &Iyy, &Izz);
// Apply force
Oforce = SpaceShip->DirectionalForce;
float Nforce[] = {(Gravity.x * mass) + Oforce.x,(Gravity.y * mass) + Oforce.y,(Gravity.z * mass) + Oforce.z};
NewtonBodyAddForce(nBody,Nforce);
// Apply Torque
Otorque = SpaceShip->RotationalForce;
float Ntorque[] = {Otorque.x, Otorque.y, Otorque.z};
NewtonBodyAddTorque(nBody,Ntorque);
} // SpaceShipApplyForceAndTorqueCallBack
SpaceShipTransformCallback (const NewtonBody* nBody, const float* nMatrix)
{
Ogre::Quaternion Oquat;
Ogre::Vector3 Opos;
......(code cut out).....
// Translate Newton Matrix to Ogre Quaternian and Vector 3
MatrixToQuatPos(nMatrix, Oquat, Opos);
// Position the node
SpaceShip->NodeShipControl->setOrientation(Oquat); // set Orientation (rotation)
SpaceShip->NodeShipControl->setPosition(Opos); // set position
} // SpaceShipTransformCallback
However, it only moves in ONE direction. Even if I turn the ship to another heading the applied force vector is not changing.
I think I figured out that the scale between netwon and ogre is 1:1
did you write a routine to draw the newton collision meshes in ogre?
Users browsing this forum: No registered users and 4 guests