getting the direction

Started by
10 comments, last by Bruno 19 years, 11 months ago
Hi I have an object wich is at position P , and has it''s rotations (x,y,z). With this information, is it possible to calculate where the object is facing ? The object is a light source, and i want to project a texture to the place he his facing., but i''m having troubles in calculating it. thanks for any help, Bruno
Advertisement
Where an object is "facing" is completely arbitrary. You have to first choose which face of an object is the "front." Then the direction the object is "facing" is simply the normal to the surface of the "front."
This can be done (among other ways) with matrix multiplication. Keep in mind that the order in which you apply the yaw, pitch and roll will affect the final orientation.

In your case, you would start by creating a matrix representing your x rotation. Then you would multiply this by a matrix representing your y rotation, and finally be a z rotation matrix. The appropriate matrices and how to multiply them can be found in any good 3d graphics book - try ''3D Math Primer,'' for example.

Your final matrix represents the final orientation of your object, with the three rows or columns representing the side, up and forward vectors, respectively. So your ''facing'' vector would be the third row or column of the matrix.

If you just use elevation/azimuth (or whatever it''s called) instead, there''s probably a quicker way to do it. I''m not sure if there''s a quicker way to handle three rotations (aside from using quaternions).
Strife, i cannot user normals in this case.

jyk, thanks for the ideia,
I already have the matrix of the object, it''s from that matrix that i''m able to extract the angles.
So, you say i have the facing vector of my mesh in the third row or colum of the matrix ?
thanks., i''l check it out, and see if that does the job.,

Bruno
->I have an object wich is at position P , and has it''s rotations (x,y,z).

by rotations, you mean roll pitch yaw(heading)?
if so, make sure the sum of coords are = to 1.
roll2 = roll / sqrt(roll^2+pitch^2+yaw^2)
pitch2 = pitch / idem
yaw 2 = idem
if you have the angles just make:
roll2= arccos(angleroll);
pitch2=arccos(anglepitch);
yaw2=idem

then you have the equation of a line:
R=P+a.(roll2,pitch2,yaw2);

->Strife, i cannot user normals in this case.
It impossible... your object MUST have a normal, since directions and angles are always RELATIVE to a base... you record it using a normal. It usual to keep track of object by this way ->(x,y,z,r,p,y) 3 coord of translation
3 coord of rotation
"I already have the matrix of the object, it''s from that matrix that i''m able to extract the angles.
So, you say i have the facing vector of my mesh in the third row or colum of the matrix ? "

Yeah, if you have the matrix, you should already have the orientation vectors. Let us know if it works for you.
Actually it did not work

I also tried to multiply the vector (0,-1,0) by the rotation angles of the model, but no luck either.
"Actually it did not work "

Hmmm. I''m not sure what to tell you. An orientation matrix is generally an orthogonal basis with three axes (x, y, z), either in the columns or the rows. If it''s a 4X4 matrix, you''ll just be dealing with the upper left 3X3 portion. How is it not working?
Just to make sure, i''m not forgetting anything.

It''s a 4x4 matrix, d3d style.,
First a transpose it to OGL style, and i get the orientation matrix.
Then, to get the destination point, i just add the orientation to the original position, like this :

Ropes_Cubes.matrix.Transpose(tp);
dir[0] = tp.matrix.mArray[0];
dir[1] = tp.matrix.mArray[1];
dir[2] = tp.matrix.mArray[2];

Then i have,
Light_Origin;

and i calculate Light_Destiny :

Light_Destiny[0] = Light_Origin[0] - dir[0];
Light_Destiny[2] = Light_Origin[2] - dir[2];
Light_Destiny[1] = Light_Origin[1] - dir[1];

That''s about it.,
Just a note, i''m using the first position of the matrix ( 0,1,2 ) , because it gives better results ( still wrong ) than ( 4,5,6 ). With the last ones, the light projection goes totally wacko.
You spot something wrong here ?

I posted two videos ( divx )

This one, is using positions (0,1,2) of the matrix:
www.fysoftware.com/temp/shadow.avi

This one, is using positions (4,5,6) of the matrix:
www.fysoftware.com/temp/shadow2.avi

thanks,
Bruno

4, 5, 6 will give you nonsense results. Remember that although we''re dealing with the upper left 3X3 portion of the matrix, it''s still a 4X4 matrix. So the third row or column is actually 8, 9, 10.

Try that and see if it works any better.

Actually 4, 5, 6 is wrong even for a 3X3 matrix - it should be 6, 7, 8. Anyway, try 8, 9, 10...

This topic is closed to new replies.

Advertisement