Nick Nougat

11-30-2002, 03:21 PM

Hi!

I need to be able to align objects along a vector. An example being a laser gun aiming at a target - so I need to be able to align it with the vector (enemy.origin - gun.origin).

I know, that in principle you take the "aim" vector as Z, then use some UP vector(Y) like the Y axis itself, build the cross product to get the orthonormal vector (-> X), then do a cross product with X and Z to get the Real Y...

But What do I do if the Z and Y vectors are almost parallel? Is there any formula to adjust the Up vector accordingly so that objects don't flip?

Thanks,

Nick

[Edited PS:]

BTW:

Right now I have to do the rotations with matrices, although I use quaternions for all other rotations.

Is there any way to calculate quaternions from an orthogonal vector pair or is the only way to get a quaternion a matrix->quaternion conversion?

[This message has been edited by Nick Nougat (edited 11-30-2002).]

I need to be able to align objects along a vector. An example being a laser gun aiming at a target - so I need to be able to align it with the vector (enemy.origin - gun.origin).

I know, that in principle you take the "aim" vector as Z, then use some UP vector(Y) like the Y axis itself, build the cross product to get the orthonormal vector (-> X), then do a cross product with X and Z to get the Real Y...

But What do I do if the Z and Y vectors are almost parallel? Is there any formula to adjust the Up vector accordingly so that objects don't flip?

Thanks,

Nick

[Edited PS:]

BTW:

Right now I have to do the rotations with matrices, although I use quaternions for all other rotations.

Is there any way to calculate quaternions from an orthogonal vector pair or is the only way to get a quaternion a matrix->quaternion conversion?

[This message has been edited by Nick Nougat (edited 11-30-2002).]