Sign in to follow this  
cossie

calculating the direction an object is facing

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 this post


Link to post
Share on other sites
Quote:
Original post by cossie
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 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?

Admiral

Share this post


Link to post
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 this post


Link to post
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.

Admiral

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this