0
101 Nov 20, 2005 at 00:10

i am making a game engine, and i need to create a function that gives me rotation about the x, y, and z axis if i give it and up vector and a forward vector. in other words, i need something that tells me the orientation of an object if i give the function a vector for the direction it should be facing and a vector for which way is up. any help is useful, but the more complete the better
thanx!
note: rotation is done by rotating about the y axis, then x, then z, if it makes a difference.(probably does)

#### 11 Replies

0
101 Nov 20, 2005 at 00:21

this might work:

1. make sure all of your vectors are normalized

2. theta_y = acos(view.x_axis);
theta_x = acos(view.y_axis);
theta_z = acos(up.x_axis);

This will probably work, but I just pulled it out of the top of my head, so you will probably need to tweak it. Good luck.

0
101 Nov 20, 2005 at 01:04

thanx for the quick response, but this doesn’t work. i think it’s a little more complicated somehow.
just another thought, gluLookAt also used a view (forward) and up vector.

0
101 Nov 20, 2005 at 01:21

If you are using OpenGL with the standard C math library, remember that the standard C math library uses radians and OGL uses degrees. Might fix things. Just a guess.

0
101 Nov 20, 2005 at 02:11

sry, that’s not the problem. a few flaws, taking acos of one length isn’t enough information to find one angle. also, based on the order of rotations, (in this case y axis, then x, then z) orientation of the angles to the vector change, so again, there’s more to it.

0
101 Nov 27, 2005 at 11:37

@rockwall

i am making a game engine, and i need to create a function that gives me rotation about the x, y, and z axis if i give it and up vector and a forward vector. in other words, i need something that tells me the orientation of an object if i give the function a vector for the direction it should be facing and a vector for which way is up. any help is useful, but the more complete the better
thanx!
note: rotation is done by rotating about the y axis, then x, then z, if it makes a difference.(probably does)

Could you tell us what you are trying to do? Maybe your problem would be solvable in a more robust way, which doesn’t involve finding angles?

0
101 Nov 27, 2005 at 21:09

You can only return such a result if you define in what order the x, y and z rotations take place (yes, this is important!). So, what is that order? Most FPS-like games use a Y -> X -> Z order, as you want the Y to control the yaw, the X the pitch and the Z roll which usually is 0 to maintain a natural “up” orientation

0
101 Nov 27, 2005 at 21:39

You just need to build a lookat matrix (like gluLookAt does it). A little bit of google will show you how to do it.

Then you need to decompose the matrix into euler angles. And again, google will guide you to the code on the first page.

I just wonder why you need euler angles at all. You already have the matrix.

0
101 Nov 27, 2005 at 21:48

You just need to build a lookat matrix (like gluLookAt does it). A little bit of google will show you how to do it.

Why? What the lookat function does is calculate the up and forward vectors, according to some world-up, and put the axes in a matrix. Since you already have the up and forward vectors, calculating the right-vector is a simple cross-product on the known axes. Then you can put it in your matrix, but that doesn’t help you finding the euler angles. And you don’t even need the right-vector to find the euler angles.

0
101 Nov 29, 2005 at 04:28

to answer your question, i need the function to return angles so they can be used more easily and universally. if it returns a matrix, it presents a quirck for the user to need to deal with. i cannot, for the life of me, find a function online that turns an opengl matrix (or any matrix) into 3 euler angle with the rotation order yxz. if anyone can help, awsome.
thanx!

0
167 Nov 29, 2005 at 05:15

If your intention is to allow the user to control rotation, then I’m afraid that Euler angles are probably not going to be that useful to them either. Maybe a graphical interface where you could spin things by clicking and dragging on “handles”, that uses matrices or quats internally, would be better (although admittedly much more work).

This in mind, here are some pages that discuss how to decompose a 3x3 rotation matrix (this will be the upper-left part of your 4x4 transformation matrix) into Euler angles:

0
101 Nov 29, 2005 at 06:03

sorry, i didn’t explain that very well. what i meant was that for the game engine, i need to have a universal way to translate everything for internal reasons, and as yxz euler angles are the best in my case, i need the function to give me data i can pass to other functions. it makes everything easier in the end. Anyways, it’s working now, so thanks for the help :).