# Aircraft rotation questions.

This topic is 3879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a ship. It has its forward, right and up vectors. The roll angle will define its rotation about forward, yaw around up etc. Using a rotation matrix (axis-angle) to update the vectors, what do I need to do to simulate real life plane flight?

##### Share on other sites
Ok, I think I've got it. All I need to know is how to transform your coordinate system in such a way that it is perfectly aligned with your orthogonal up/right/forward vectors and how much of a performance hit there will be by doing this every step. Thanks.

(I really don't want to have to transform my mesh manually.)

##### Share on other sites
Quote:
 Original post by glopenwhat do I need to do to simulate real life plane flight?

Are you asking "how do I update the position and orientation of my aircraft given input roll rates", or are you asking, "how do I determine roll rates given control surface changes"? (Or both)?

##### Share on other sites
Thanks!

Well, the first question, I think. Or maybe both. I know how to roll around an axis because that's what glRotatef() does. With a rotation matrix I can determine my current Up, Forward and Right vectors. I figure the trick is to store your previous orientation so that when you want to, say, pitch around Right vector, glPushMatrix() makes it render the mesh in a system aligned to the global system first then rotate it around the Right vector. Does this make sense? If it does, how exactly can I transform my current system to align with the ship's Up, Right etc. vectors so that when it is drawn, it will show the ship as it was in the previous frame? Will be a great help.

I guess if this is getting too complicated I'll have to switch to quarternions but I don't know much about them. And of course I'm currently trying to update the orientation with angle increments instead of global values.

[Edited by - glopen on June 10, 2008 3:22:59 PM]

##### Share on other sites
Quote:
 I guess if this is getting too complicated I'll have to switch to quarternions but I don't know much about them.
The behavior of matrices and quaternions with respect to rotations is fundamentally equivalent*, so switching to quaternions won't help any here.

As for your question, I'm not quite clear on what you're trying to accomplish, but I get the feeling you're on the wrong track with glRotate*(). You can certainly use glRotate*() to set up OpenGL's modelview matrix for the purpose of rendering the object in question, but you won't be able to use glRotate*() to incrementally adjust the orientation of the object (not easily, at least).

*I'll clarify what I mean here by 'fundamentally equivalent'. If for these two representations you set aside all aspects that are related to programming rather than mathematics - storage requirements, numerical stability, the efficiency and/or elegance of various operations, etc. - the behavior of quaternions and matrices with respect to rotations is basically the same. I tend to make a point of this in my posts because there seems to be a widespread belief that these two representations differ fundamentally (the most oft-repeated untruth being that matrices are subject to gimbal lock while quaternions are not). As such, my advice to anyone trying to choose between rotation matrices and quaternions is to stick with matrices unless you know exactly why a quaternion would be a better choice in the given context.

##### Share on other sites
Quote:
 Original post by glopenI guess if this is getting too complicated I'll have to switch to quarternions but I don't know much about them. And of course I'm currently trying to update the orientation with angle increments instead of global values.

You will want to switch to Quaternions anyway to avoid "Gimbal Lock". Just google them, there are some great resources out there for converting to and from Quaternions and Axis/Angle, Matrices etc. IIRC Gamasutra has quite a few articles on the subject.

##### Share on other sites
Quote:
 You will want to switch to Quaternions anyway to avoid "Gimbal Lock".
You might want to read my post above (especially the part in small print).

##### Share on other sites
Thanks guys for the insight.

About using glRotate*(), if I do manage to set up the modelview matrix to align the system with my local axes, after it is done, shouldn't basic rotations do the trick? I mean:

[SOURCE]//After alignment and everythingglRotatef(pitch_incr,0,0,1);glRotatef(yaw_incr,0,1,0);glRotatef(roll_incr,1,0,0);[/SOURCE]

Because after all the transformations have been done, I just rotate the mesh around the X,Y,Z as they are basically the local axes of the aircraft.

I have just come across an example of a simple flight sim with quarternions and it seemed to do the above before drawing the plane.

BTW, isn't the above alignment procedure functionally similar to a satelite dish's azimuth/elevation adjustments? Thanks for all the info again.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015825
×