Jump to content
  • Advertisement
Sign in to follow this  
deltaKshatriya

Rotate to face function

This topic is 2853 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

Advertisement

If you consider the rotation around each of those angles seperately, you'll see that a rotation around the y axis for example effectively moves the vertices in the xz plane. The line along which the sides of the cube should align can be used as the hypotenuse in basic trigonometry, while either distance in the x or z direction between the origin and the point you want to face can be used as opposite or adjacent side (which one depends on the coordinate system you're using) to compute the sin or cos of the angle.

The above is probably a better advice :)

Share this post


Link to post
Share on other sites
Quote:
Original post by kryotech
So I have a cube that I want to rotate to face a point in 3D space. I am limited to using x, y, z angles. Does anyone understand how this can be done?
Are you *sure* you're limited to using x, y, and z angles? (I ask because people often think they have to use Euler angles when in fact they do not.)

Share this post


Link to post
Share on other sites
Te software I'm using has commands that rotate the object around the x, y , and z axis. It doesn't have any other commands. I guess I need a generic rotate to face function as well, not one just for a cube.

Share this post


Link to post
Share on other sites
Quote:
Original post by kryotech
Te software I'm using has commands that rotate the object around the x, y , and z axis. It doesn't have any other commands. I guess I need a generic rotate to face function as well, not one just for a cube.
What software is it?

Share this post


Link to post
Share on other sites
If you're really only able to use Euler angles for this, you can compute a pair of spherical angles from the vector from the box position to the target position using a Cartesian-to-spherical-coordinate conversion. (You only need two angles for this, so you can ignore the third.)

How to perform the conversion will depend on what conventions you're using (e.g. which axis is up), but will generally reduce to a couple of calls to (e.g.) atan2().

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!