Look vector to Rotation Matrix

Started by
12 comments, last by Kwizatz 14 years, 5 months ago
I have tried swapping the order of the cross product but that just flips the direction like you said.

Here are two pictures that show problem. In both cases the quadrangle's normal is (0,1,0).

The first one uses:

xAxis = Vector3.Cross(Vector3.UnitZ, zAxis) when length < 0.01f:

zAxis

The one uses:

xAxis = Vector3.Cross(Vector3.UnitX, zAxis) when length < 0.01f:

xAxis

In both cases the camera is looking down the -ve Z axis.
Advertisement
Seems expected, what do you mean 'the texture will face (0,0,1)'? if you created the quad with only x and y values, it is expected to be so, unless you specified the vertices backwards, then it would face (0,0,-1).

Now, I don't know why you have a conditional on xAxis, if you're implementing a look at function, there is only one possible x,y,z axis.
Quote:
Now, I don't know why you have a conditional on xAxis, if you're implementing a look at function, there is only one possible x,y,z axis.


In case the up vector is parallel to the look vector.

Quote:
Seems expected, what do you mean 'the texture will face (0,0,1)'?


If you imagine that the quad is longer in height than width, the two orientations sharing the same up would be different for the two unit axes:

xAxis = Vector3.Cross(Vector3.UnitZ, zAxis) when length < 0.01f_______|      ||      | |      | (Viewed from above, camera facing (0,-1,0)|      ||      ||______|xAxis = Vector3.Cross(Vector3.UnitX, zAxis) when length < 0.01f_____________|            ||            | (Viewed from above, camera facing (0,-1,0)|____________| 


In other words the unit axis chosen affects the orientation, even though the surface normal remains constant/correct.

Does that make sense?
Quote:Original post by Spa8nky
In case the up vector is parallel to the look vector.


Yes, that's something you have to live with.

Quote:Original post by Spa8nky
If you imagine that the quad is longer in height than width, the two orientations sharing the same up would be different for the two unit axes:

xAxis = Vector3.Cross(Vector3.UnitZ, zAxis) when length < 0.01f_______|      ||      | |      | (Viewed from above, camera facing (0,-1,0)|      ||      ||______|xAxis = Vector3.Cross(Vector3.UnitX, zAxis) when length < 0.01f_____________|            ||            | (Viewed from above, camera facing (0,-1,0)|____________| 


In other words the unit axis chosen affects the orientation, even though the surface normal remains constant/correct.

Does that make sense?


Well, yes, that happens because you're selecting a new up vector, think of it as a vector from the top of your head pointing upwards into Z, if you rotate your head such that your up vector points to the right into X, what you see won't change, but you will see it flipped 90 degrees to one side, that is why you shouldn't pick a new up vector wily nilly, if you expect your camera to be facing straight up or down constantly (for example for a FPS), then either cap the angle of rotation or find a better solution, quaternions work for me.

Also: remember to normalize your cross products.

This topic is closed to new replies.

Advertisement