Page 1 of 1
Get roll of a node (airplane)
Posted: Wed Jun 01, 2011 6:13 am
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.
Posted: Wed Jun 01, 2011 1:09 pm
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?
Posted: Wed Jun 01, 2011 1:17 pm
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?
Posted: Wed Jun 01, 2011 1:41 pm
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

Posted: Wed Jun 01, 2011 1:48 pm
by Radikalizm
Ok, I misunderstood that one

Let me ponder over that one for a while...
Posted: Wed Jun 01, 2011 2:28 pm
by Luben
edit2: realized i'm stupid =d
Posted: Wed Jun 01, 2011 3:54 pm
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.
Get roll of a node (airplane)
Posted: Wed Jun 01, 2011 6:44 pm
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;
Posted: Fri Jun 03, 2011 6:00 am
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
This implementation works for most cases, but before enabling the autopilot you should get the rollangle around 0, too much rolling "confuses" the autopilot.