Jump to content
  • Advertisement
Sign in to follow this  
Xashikolauk

Specifying Direction Vectors

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's what I'm trying to do: Given a user-specified 2-tuple of radian measures(which we will call A), I want to be able to locate a normalized 3d vector which is rotated from the starting position (1,0,0) to the left by A[0] radians, and then ascended upwards by A[1] radians. Basically, the user inputs something such as "(85 degrees, 42 degrees)"; I then want to find the normalized vector which points 85 degrees counter-clockwise from the positive x-axis, and is then acclinated 42 degrees upward from the x-z plane. This would allow them to specify any direction in a format that is easily human understandable. The first step is easy enough, just multiply the vector (1,0,0) by the standard y-axis rotational matrix for A[0]. I'm having trouble doing the acclination though. My best-guess is that I need to rotate it around a perpendicular line; however, I don't know how to find that line nor how to construct a rotational matrix for it. If anyone could point me in the right direction, or describe a simpler method, it would be a big help.

Share this post


Link to post
Share on other sites
Advertisement
Well, the line you want to rotate around is 0,0,1 at the start, so after rotating 1,0,0 by 85 degrees, you should also rotate this axis by the same amount.

Your matrix will do this for you. Calculate the rotation matrix you need for the rotation of your direction around 0,0,1. Multiply it by the rotation you need around 0,1,0. This gives a final matrix, which is what you want. Be careful, as if you multiply them the wrong way round, it will rotate up first, and then around, instead.

Share this post


Link to post
Share on other sites
In addition to Squirm's solution, you might also consider spherical coordinates (which is pretty much equivalent). Off the top of my head:

x = cos(A[0])*cos(A[1]);
z = sin(A[0])*cos(A[1]);
y = sin(A[1]);

You might have to flip the sign of z to get the direction of rotation that you want.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!