View Full Version : Object Rotations
03-21-2001, 12:19 PM
Hey everyone. I'm trying to program a small space sim with enemy ships that fly around and try to shoot you. I have routines to rotate the enemies that use x, y and z angles but I do not know how to get the correct angles to rotate the object by to face the position the user is at. I have classes to do the usual changes from matrices to quaternions and vectors and the like but I have been unable to get euler angles from all of it that actually work when rotated. The angles the functions give me always cause the object to face weird directions. Does anyone know how to get good correct angles in degrees to allow for object rotation to face the current position the user is at? Thanks for the help.
03-23-2001, 07:51 AM
You probably don't want to use Euler angles to set rotation because of gimbal lock. Your classes on Matrices and Quaternions might be a better route. In brief if you want to align a vector (an enemy space ship) with the camera (another vector) you need to find the rotation arc and axis between the two vectors. From that you can get a quaternion and you can use that to produce a rotation matrix. A good FAQ I found is http://skal.planet-d.net/demo/matrixfaq.htm.
03-23-2001, 08:01 AM
Steve, your link seems to be broken. I assume you're referring to the "Matrix & Quaternion FAQ" - the latest version of this is at http://www.cs.ualberta.ca/~andreas/math/matrfaq_latest.html
03-23-2001, 12:21 PM
Perhaps you misunderstood the question. In order to rotate the object, I have to use euler angles. That is the only way to change the vertices of the object that is being rendered on the screen so that it can face different directions. I am using the quaternion and matrix classes to obtain angles but they do not work. I am wondering if there is an alternate way because I absolutely have to have euler angles in the end to rotate the object. There is no way around that. Thanks for the help.
03-23-2001, 12:55 PM
No, you don't need Euler angles to rotate something. In fact, you can feel free to load any matrix you want through glLoadMatrix; it could even be another projection matrix or complete garbage.
You don't use Quaternions to obtain angles. You take your rotations, turn them into quaternions, use quaternion multiplication on them in the correct order, and turn the resulting quaternion into the matrix you give to glMultMatrix. Very simple.
The angles you get from your functions are probably correct; it's just that using them by calling multiple glRotatef's is not going to give you the results you were looking for. Use Quaternions as I said and it should work.
03-24-2001, 10:20 PM
Unfortunately for me, yes I do need Euler angles to rotate the object. You are forgetting that the object is not the user and has nothing to do with OpenGL's matrices and the like. The object is a seperate entity loaded from a file and rendered as a mass of triangles that is seen by the user as it flys around on the screen. I use quaternions to get a vector angle to use for one call of glRotatef to change the camera but this has nothing to do with what I am posting about. Euler angles are used as paramters for the function to rotate the x y and z locations of the object I am actually trying to render. The object has a collection of faces, each with 3 vertices and an x, y and z for each vertice. Based on the Euler angles given to the RotateObject(float x, float y, float z) function, new locations of the vertices are computed so when the object is re-rendered it looks like it is facing another direction. Using matrices and quaternions I can get numbers to use to move the object but none of the euler angles I use cause the enemy object to face the right direction. I wish there was some way to rotate a seperate object without 3 euler angles but since the object is composed of triangles, there is no way around using angles.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.