Cardinals33

03-29-2001, 09:03 PM

Hi. I am writing an engine that allows the user to fly through space with a six degrees of freedom engine. The engine works fine and I can easily change the camera angle based on user input but what I can't figure out how to do is to get an enemy fighter that the user rotate to fly towards the user when in attack mode and rotate to fly away when fleeing. I have a function to rotate the object which is a collection of triangles but because the rotations are performed in order the end result is not right. I've found I cannot compute the individual angles and then plug them into the rotation function as the object ends up facing a direction no where near what it should. What I am wondering is if there is a way to obtain an x, y and z angle that will actual rotate the object correctly? The rotation function i use looks like this:

WorldObject::RotateObject(int angleX, int angleY, int angleZ)

{

float temp_x, temp_y, temp_z;

int count;

for(count=0; count < model.NumVertices; count++)

{

temp_x = c[angleX] * model.Vertices_local[count].x - s[angleX] * model.Vertices_local[count].y;

temp_y = s[angleX] * model.Vertices_local[count].x + c[angleX] * model.Vertices_local[count].y;

model.Vertices_local[count].x = c[angleY] * temp_x - s[angleY] * model.Vertices_local[count].z;

temp_z = s[angleY] * temp_x + c[angleY] * model.Vertices_local[count].z;

model.Vertices_local[count].y = c[angleZ] * temp_y - s[angleZ] * temp_z;

model.Vertices_local[count].z = c[angleZ] * temp_z + s[angleZ] * temp_y;

model.Vertices_screen[count].x = (model.Vertices_local[count].x / model.scalefactor) + model.World_Pos.x; model.Vertices_screen[count].y = (model.Vertices_local[count].y/model.scalefactor) + model.World_Pos.y;

model.Vertices_screen[count].z = (model.Vertices_local[count].z/model.scalefactor) + model.World_Pos.z;

}

}

This works fine for one angle but when using multiple angles it gets screwed up. I know there are ways around this using quaternions and the like but how can that be applied to this since I need Euler angles to rotate the object? Thanks for the help.

-Dan

WorldObject::RotateObject(int angleX, int angleY, int angleZ)

{

float temp_x, temp_y, temp_z;

int count;

for(count=0; count < model.NumVertices; count++)

{

temp_x = c[angleX] * model.Vertices_local[count].x - s[angleX] * model.Vertices_local[count].y;

temp_y = s[angleX] * model.Vertices_local[count].x + c[angleX] * model.Vertices_local[count].y;

model.Vertices_local[count].x = c[angleY] * temp_x - s[angleY] * model.Vertices_local[count].z;

temp_z = s[angleY] * temp_x + c[angleY] * model.Vertices_local[count].z;

model.Vertices_local[count].y = c[angleZ] * temp_y - s[angleZ] * temp_z;

model.Vertices_local[count].z = c[angleZ] * temp_z + s[angleZ] * temp_y;

model.Vertices_screen[count].x = (model.Vertices_local[count].x / model.scalefactor) + model.World_Pos.x; model.Vertices_screen[count].y = (model.Vertices_local[count].y/model.scalefactor) + model.World_Pos.y;

model.Vertices_screen[count].z = (model.Vertices_local[count].z/model.scalefactor) + model.World_Pos.z;

}

}

This works fine for one angle but when using multiple angles it gets screwed up. I know there are ways around this using quaternions and the like but how can that be applied to this since I need Euler angles to rotate the object? Thanks for the help.

-Dan