Advertisement

3D Rotation question....

Started by May 17, 2002 07:41 PM
1 comment, last by Zab 22 years, 9 months ago
Hi, I was wondering if somebody could give me a hand here... I''m drawing a few triangles ( I guess you could call them a model ) using a basic GL_TRIANGLES setup, with the "front" of the model pointing along the x axis. Now, what I want to do is rotate the (modelview?) matrix so that when the model is drawn on the screen, the "front" is pointing along a certain vector ( a normalized velocity in this case ), without any roll. I''ve got something going, but I''m getting strange results. At the moment it looks like this (OpenGL): double pitch = -atan(m_velocity.y / sqrt(m_velocity.z * m_velocity.z+ m_velocity.x*m_velocity.x)); double yaw = atan2( m_velocity.x, m_velocity.z); glRotatef( pitch / PI * 180 , 0,0,1 ); // around the Z axis glRotatef( yaw / PI * 180, 0,1,0 ); // around the Y axis I kind of took the above code from somewhere, and don''t really understand it so it may not make too much sense. Any help would be much appreciated!
This would be a better question for either the graphics or opengl boards. If you label the sides of a right triangle a, o and h for adjacent, opposite and hypotheneous then the angle between a and h is atan(o/a). That will return an angle between -pi/2 and pi/2. If instead you use atan2(a,o) then you get an angle between 0 and 2pi. One complete revolution is 2*pi radians, i.e. 360 degrees. So to convert between radians r and degrees d is d=r/pi*180. glRotate does an axis angle rotation, i.e. you rotate by an angle around the specified axis. (0,0,1) is a unit vector pointing down the z-axis. (0,1,0) is a unit vector pointing down the y axis. Your y axis is up. The pitch is the angle with the xz plane, i.e. picture a boat hitting waves head on and pitching back and forth. The roll is how much you lean side to side, i.e. picture a boat being hit from the side by a wave and rolling over. The yaw is a bit harder, but picture sailboat with a strong side wind. The yaw is the differance between the direction the boat is pointing and the direction it is actually moving.
Keys to success: Ability, ambition and opportunity.
Advertisement
I don''t consider this to be a graphics question. I find it suitable for this forum.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement