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.
Get roll of a node (airplane)
Get roll of a node (airplane)
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
Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
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
Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
-
- Posts: 1215
- Joined: Tue Jan 09, 2007 7:03 pm
- Location: Leuven, Belgium
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
Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
-
- Posts: 1215
- Joined: Tue Jan 09, 2007 7:03 pm
- Location: Leuven, Belgium
Get roll of a node (airplane)
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:
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;
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).
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.
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;
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
Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames