#### Archived

This topic is now archived and is closed to further replies.

# Need help with a rotation function!!

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

## Recommended Posts

I am working on a project for my graphics class using GLUT, but this is a general question that is non-language-specific. I am putting all my objects into classes, so that I can use inheritance to propagate object creation. My problem is that I want to make an easy way to rotate the objects. Using three variables (pitch, roll, and yaw) seems the easiest way, but I don''t know of an easy way to make it work. Doing the rotations seperately in sequence has unwanted results, because of the coordinate change with each rotation. Can this be done with a single matrix multiplication of some kind? I read on one of Nasa''s pages that this was computed for the shuttle using a single Eigen axis rotation, but I haven''t the slightest clue as to how to make that work. I just want something that is halfway intuitive to use to rotate the objects and that I can reset easily. Any help would be greatly appeciated!! >^,,^<

##### Share on other sites
You should either store a matrix or a quaternion if you want quick results. Take a look at this page, under the categories Q30, Q31, Q34, and Q35. There''s also lots of quaternion stuff there.

[Resist Windows XP''s Invasive Production Activation Technology!]

##### Share on other sites
The quaterion looks like the way to go, but I am just too slow tonight to figure out how to convert:

m_pitch = 5.0
m_roll = 40.0
m_yaw = -10.0

into something like:

glPushMatrix();
glMultMatrix(some_rotation_matrix_or_quaterion);
Draw_Object();
glPopMatrix();

##### Share on other sites
Well, one way is like this:
  glPushMatrix();glRotate(m_pitch,1.0f,0.0f,0.0f);glRotate(m_yaw,0.0f,1.0f,0.0f);glRotate(m_roll,0.0f,0.0f,1.0f);Draw_Object();glPopMatrix();

Although I still think you should go with another form of storage.

[Resist Windows XP''s Invasive Production Activation Technology!]

##### Share on other sites
The storage is used to keep record of all the rotations. Using the code you provided will result in some side effects that I am trying to avoid. For example, if m_Roll is 90, then the Y-axis has effectively become the X-axis, and the new Y-axis is the old negative X-axis. Any rotations after this (like the m_Pitch and m_Yaw) will be wrong, or at least not what I want. I want all the rotations to be independant of order or each other. Thank you for your help though!

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631782
• Total Posts
3002324
×