Get roll of a node (airplane)

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Get roll of a node (airplane)

Post by Brainsaw »

Hi,

I have ran into a problem and can't seem to find a solution due to my mathematical skills (aka "not existing"). I have my node (an airplane) with a foreward vector and now I want to know how to get the rotation around this axis (I also have the up and sidewards vectors of course). Can anyone give me a hint? Thanks in advance.
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

Hmm ... thought about it for some time ... maybe it's possible to get a quaternion with the transformed foreward axis as rotation axis. How would I go transform the translation of the node into a quaternion with an axis I define? Is this the way to go?
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

You can set up your quaternion rotation by using quaternion::fromAngleAxis(...)
You can pass your normalized forward vector as the rotation axis and pass the desired rotation angle

I think that about covers it, no?
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

No exactly. I want it the other way round. I have my foreward axis and want to query the rotation around this axis. Airplane movement is calculated by the ODE, so no need to do anything there, I just want to implement a simple autopilot that first of all keeps the roll around zero. I hope someone knows a solution for this :?
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

Ok, I misunderstood that one :D
Let me ponder over that one for a while...
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

edit2: realized i'm stupid =d
Last edited by Luben on Thu Jun 02, 2011 12:31 pm, edited 2 times in total.
If you don't have anything nice to say, don't say anything at all.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Can't you just use the getAngleWithYZ function (or any other combination which fits your requirements)? The upvector should have the angle you're looking for with that plane.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Get roll of a node (airplane)

Post by smso »

There is the up-vector in the world space and that of the node in the local space. Is the angle between them the roll angle?
What if the airplane pitched down by 90 degrees and did no rolling?

On the other hand, I think the value of roll, yaw and pitch can be found more easily if the yaw, pitch and roll actions of the airplane are decoupled by using empty scene nodes. The Hierarchy may look like:
rootEmpty => yawEmpty => pitchEmpty => rollEmpty => airplane

Code Snippets:

Code: Select all

scene::ISceneNode* rootEmpty = smgr->addEmptySceneNode(0);
scene::ISceneNode* yawEmpty = smgr->addEmptySceneNode(rootEmpty);
scene::ISceneNode* pitchEmpty = smgr->addEmptySceneNode(yawEmpty);
scene::ISceneNode* rollEmpty = smgr->addEmptySceneNode(pitchEmpty);

scene::ISceneNode* airplane = smgr->addMeshSceneNode(smgr->getMesh("..."), rollEmpty);


// rootEmpty is responsible for translation only and rollEmpty is for rotation about the Z-axis only, etc.

rollEmpty->setRotation(core::vector3df(0.0f, 0.0f, -3.5f));
// f32 rollAngleDegs = rollEmpty->getRotation().Z;
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

Thanks for the replies. I figured out how to do it. I take the transformed up and side-vectors, set the Y of the side vector to "0" and calculate the angle between the two (OK, I could use the side-vector twice, once with Y=0 so that I don't have to subtract 90 from the result to get zero when the plane isn't rolling).

Code: Select all

      //notes: m_pPlaneBody is the actual physical plane
      //and m_pAero is the calculation node for the
      //aerodynamic part which also holds the up and
      //sidewards vectors
      core::vector3df vInv=m_pPlaneBody->getRotation();

      vInv=vInv.invert();

      core::vector3df vUp=vInv.rotationToDirection(m_pAero->getUpward  ()),
                      vSi=vInv.rotationToDirection(m_pAero->getSideward());

      vSi.Y=0.0f;

      vUp.normalize();
      vSi.normalize();

      f32 fRollAngle=acosf(vUp.dotProduct(vSi))*180/M_PI;
      f32 fARoll=fRollAngle-90.0f;
Using this and some more math (which is all new to me ;) ) I was able to implement an autopilot feature in the IrrOdeCar demo. The big fun yesterday was to start all four planes, activate their autopilots, sit back and watch :D

This implementation works for most cases, but before enabling the autopilot you should get the rollangle around 0, too much rolling "confuses" the autopilot.
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Post Reply