CodeZealot
04-01-2012 17:23:19
Hi guys,
I was hoping someone would be able to point me in the right direction as to how to control a flying object using NxOgre. I am not looking for complex
flight dynamics such as lift and drag; the Airplane simply needs to move in the direction it's facing (similar to a spaceship, except that I will later add
forces for deceleration and gravity), with its orientation being controlled by a joystick. Previously, I was just using Ogre3D's translations and rotations,
so I need to convert the movement of the Airplane to use NxOgre. Here are my problems explained in detail:
My joystick with multiple axes has its input passed to the Airplane class in the following method:
rotX, rotY, and rotZ are the angles to pitch, yaw and roll by respectively, with transZ being the amount to speed up or slow down by in the direction faced.
I previously used Ogre3D's SceneNode::pitch, yaw, roll functions to orient the Airplane, but have now been using Critter::Body::addTorque() like so:
to achieve the same effect. Unfortunately, it tends to be quite clunky to control and some of the rotations get skewed - for example, the rotY axis actually
pitches the plane sometimes. I have also tried using Critter::Body::setGlobalOrientation and Critter::Body::setGlobalOrientationQuat (I'm not quite sure how
to use Matrix33/44 and quaternions for orientations anyway) but these methods make the Airplane rotate in a very jittery way.
Also, I previously accelerated the Plane in the direction it was facing by using translations:
But now have tried to use Critter::Body::addLocalForce():
or Critter::Body::setLinearVelocity():
However, neither of these actually make the Airplane move in the direction its facing. The Airplane will move forwards, but once it turns, it
still moves in the direction it was pointing initially. I tried getting the orientation in Vec3 form, so that I could setLinearVelocity to (orientation * speed),
but I couldn't figure out how to get what I needed from getGlobalOrientation() and getGlobalOrientationQuat().
So, to my questions -
Question 1:
What would be the best way to get as close to the functionality of pitch, yaw and roll for orienting my Airplane, given axis data in the form of floats?
Question 2:
How can I make the Airplane constantly move in the direction it's facing, controlling the speed with another axis' data (float between 0.0 and 1.0)?
I have done extensive forum searches to see could I find the answers I'm looking for, but I can't find many posts relating directly to these issues.
Any help would be greatly appreciated.
Thanks.
I was hoping someone would be able to point me in the right direction as to how to control a flying object using NxOgre. I am not looking for complex
flight dynamics such as lift and drag; the Airplane simply needs to move in the direction it's facing (similar to a spaceship, except that I will later add
forces for deceleration and gravity), with its orientation being controlled by a joystick. Previously, I was just using Ogre3D's translations and rotations,
so I need to convert the movement of the Airplane to use NxOgre. Here are my problems explained in detail:
My joystick with multiple axes has its input passed to the Airplane class in the following method:
void Airplane::injectJoystick(float rotX, float rotY, float rotZ, float transZ)
rotX, rotY, and rotZ are the angles to pitch, yaw and roll by respectively, with transZ being the amount to speed up or slow down by in the direction faced.
I previously used Ogre3D's SceneNode::pitch, yaw, roll functions to orient the Airplane, but have now been using Critter::Body::addTorque() like so:
// I have alternated between using this:
m_body->addTorque(NxOgre::Vec3(rotX, -rotY, rotZ));
// or this:
m_body->addLocalTorque(NxOgre::Vec3(rotX, -rotY, rotZ));
to achieve the same effect. Unfortunately, it tends to be quite clunky to control and some of the rotations get skewed - for example, the rotY axis actually
pitches the plane sometimes. I have also tried using Critter::Body::setGlobalOrientation and Critter::Body::setGlobalOrientationQuat (I'm not quite sure how
to use Matrix33/44 and quaternions for orientations anyway) but these methods make the Airplane rotate in a very jittery way.
Also, I previously accelerated the Plane in the direction it was facing by using translations:
// In Airplane::injectJoystick(float rotX, float rotY, float rotZ, float transZ)
// ...
m_speed = transZ;
// In Airplane::update(Ogre::Real timeSinceLastFrame)
// ...
m_sceneNode->translate(0, 0, timeSinceLastFrame * m_speed, Ogre::Node::TS_LOCAL);
But now have tried to use Critter::Body::addLocalForce():
// In Airplane::injectJoystick(float rotX, float rotY, float rotZ, float transZ)
// ...
m_body->addLocalForce(NxOgre::Vec3(0.0f, 0.0f, -transZ));
or Critter::Body::setLinearVelocity():
// In Airplane::injectJoystick(float rotX, float rotY, float rotZ, float transZ)
// ...
m_speed += transZ;
// In Airplane::update(Ogre::Real timeSinceLastFrame)
// ...
m_body->setLinearVelocity(0.0f, 0.0f, m_speed);
However, neither of these actually make the Airplane move in the direction its facing. The Airplane will move forwards, but once it turns, it
still moves in the direction it was pointing initially. I tried getting the orientation in Vec3 form, so that I could setLinearVelocity to (orientation * speed),
but I couldn't figure out how to get what I needed from getGlobalOrientation() and getGlobalOrientationQuat().
So, to my questions -
Question 1:
What would be the best way to get as close to the functionality of pitch, yaw and roll for orienting my Airplane, given axis data in the form of floats?
Question 2:
How can I make the Airplane constantly move in the direction it's facing, controlling the speed with another axis' data (float between 0.0 and 1.0)?
I have done extensive forum searches to see could I find the answers I'm looking for, but I can't find many posts relating directly to these issues.
Any help would be greatly appreciated.
Thanks.