Archived

This topic is now archived and is closed to further replies.

Nibbles

Getting a direction vector from a point and 3 angles

Recommended Posts

Nibbles    569
Hi, I can do this on paper during an algebra exam, but do you think I can do it during my own time for my own hobby (in programming that is)? Yeah right. How do I get the direction vector from a 3D point and 3 angles (pitch, yawl, and roll)? It''s so i can translate a point in 3D space using: x'' = x + tx; y'' = y + ty; z'' = z + tz; Thanks, Scott btw: I might have used some wrong terms or something, so please let me know

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
The three angles together are called Euler angles, and they are one oway of describing a rotation in space. They are not the easiest to work with though, so you may find it easier to convert them to quaternion or matrix form. You can find source for this in varioius places, including probably on this site.

Euler angles, a quaternion or a matrix describe a rotation. To get a direction from this you need to start from an initial direction, perhaps the default ''forward'' direction of your car/spaceship/player. Apply the quaternion or matrix to your initial direction to get the desired final direction.

Share this post


Link to post
Share on other sites
Aldacron    4544
I just logged on to ask a similar question

To help get you started - translation on the x/z plane:

x (-=)(+=) sin(yRotAngle) * MoveSpeed;
z (-=)(+=) cos(yRotAngle) * MoveSpeed;

The problem I''ve run into is adding the Y component. I''ve worked out this much:

y (+=)(-=) tan(xRotAngle) * MoveSpeed;

In First Person mode, this is all I need and it works fine. However, I want to implement a fly-through mode for my level editor. The problem starts when I rotate the x-axis too much. Then, instead of going forward I wind up going backward. I did a check of the value of the xRotAngle, and if xRotAngle >= 180 && xRotAngle < 360, I negated the resulting tan. Didn''t work. Anyone have any ideas for me?


Share this post


Link to post
Share on other sites