# calculating the direction an object is facing

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

## Recommended Posts

Hi, Apologies if this is a really dumb question, but after calculating the normal to an object, say a cube, and then I want that cube to move, how to I find out what direction the cube is actually facing? I just can't figure it out over the last hour or so, I'm only getting to grips with 3D maths. thanks for any help Cossie

##### Share on other sites
The proper question is: In which six directions is the cube facing?!

*kidding ;)*

Could you please be more precise?

##### Share on other sites
Quote:
 Original post by cossieafter calculating the normal to an object, say a cube, and then I want that cube to move, how to I find out what direction the cube is actually facing?

I don't follow. Normals aren't defined for meshes, only for planes (and hence polygons) and vertices. Could you provide a deeper explanation of the problem, maybe with an example?

##### Share on other sites
Okay,

What I'm trying to do is work out which direction an object is facing, Right / Left / Towards the viewer / Away from the viewer.

I've drawn a cube (using 6 GL_QUADS), and calculated a normal (cross product of 2 vectors and then normalized) on the quad that what I want to be the "face" (like a person's face) of the cube.

So, then say, the cube is rotated or moved some random value, is there a way I can work out in what direction the cube's "face" is looking in? (which I guess would be what direction it's normal is pointing in?)

##### Share on other sites
Sure there is. You apply the rotational component of the transformation to the normal. The result is the new 'facing' vector.

At least that covers the 'orientation' case. If you actually have a viewer in your scene, then things get a little more complicated:
For instance, suppose the cube is three feet in front of me, facing me directly. Now translate it some distance laterally. It is still has the same orientation, but it is no longer 'facing me'. If this is your situation, then we'll need to know more. In particular, how are you representing the positions of the bodies and the transformation being applied to them.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632936
• Total Posts
3009312
• ### Who's Online (See full list)

There are no registered users currently online

×