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)

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.

rockwall
—
2005-11-20T01:04:11Z —
#3

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.

erkokite
—
2005-11-20T01:21:08Z —
#4

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.

rockwall
—
2005-11-20T02:11:30Z —
#5

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.

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?

oisyn
—
2005-11-27T21:09:01Z —
#7

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

Nils_Pipenbrinck
—
2005-11-27T21:39:26Z —
#8

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.

oisyn
—
2005-11-27T21:48:45Z —
#9

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.

rockwall
—
2005-11-29T04:28:45Z —
#10

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!

Reedbeta
—
2005-11-29T05:15:02Z —
#11

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:

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 .