Jump to content


- - - - -

Rotation and Vectors. HELP PLZ!


11 replies to this topic

#1 rockwall

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 20 November 2005 - 12:10 AM

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)

#2 erkokite

    New Member

  • Members
  • PipPip
  • 12 posts

Posted 20 November 2005 - 12:21 AM

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.

#3 rockwall

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 20 November 2005 - 01:04 AM

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.

#4 erkokite

    New Member

  • Members
  • PipPip
  • 12 posts

Posted 20 November 2005 - 01:21 AM

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.

#5 rockwall

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 20 November 2005 - 02:11 AM

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.

#6 juhnu

    Valued Member

  • Members
  • PipPipPip
  • 292 posts

Posted 27 November 2005 - 11:37 AM

rockwall said:

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?

#7 .oisyn

    DevMaster Staff

  • Moderators
  • 1822 posts

Posted 27 November 2005 - 09:09 PM

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
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#8 Nils Pipenbrinck

    Senior Member

  • Members
  • PipPipPipPip
  • 597 posts

Posted 27 November 2005 - 09:39 PM

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.

#9 .oisyn

    DevMaster Staff

  • Moderators
  • 1822 posts

Posted 27 November 2005 - 09:48 PM

Quote

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.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#10 rockwall

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 29 November 2005 - 04:28 AM

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!

#11 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 29 November 2005 - 05:15 AM

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:

http://www.mathworks...ulerangles.html (math)
http://www.euclidean.../matrixToEuler/ (Java code)
reedbeta.com - developer blog, OpenGL demos, and other projects

#12 rockwall

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 29 November 2005 - 06:03 AM

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 :).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users