Rotate to face function

Started by
7 comments, last by Zakwayda 13 years, 6 months ago
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?

No one expects the Spanish Inquisition!

Advertisement
Try this :D

http://lmgtfy.com/?q=rotating+a+3d+cube

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 :)
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
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.)
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.

No one expects the Spanish Inquisition!

Quote:Original post by Xeogen
Try this :D

http://lmgtfy.com/?q=rotating+a+3d+cube


Ok, that was pretty funny. I applaud you on the originality :)

No one expects the Spanish Inquisition!

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?
DarkBASIC Pro (I know, I need to get away from it).

No one expects the Spanish Inquisition!

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

This topic is closed to new replies.

Advertisement