[Algorithms] Direction+Up vector to Axis/angle
Brought to you by:
vexxed72
|
From: Max G. <gi...@li...> - 2000-11-19 13:07:57
|
Hello!
Question: how to convert direction and up vectors to axis/angle
rotation?
-------------------------------------------------------------------------
Similar subject has been discussed recently in 'vector+angle' thread but
without any real answer.
In my solution I tried to duplicate Mesa3D sources but I must have done
something wrong... Can you explain me what should I do? Or maybe someone
could take a look at my code (I use Point3d class for both vertices and
vectors).
My camera is based on OpenGL scheme and is specified by: position,
axis/angle rotation, fov, near/far clipping planes.
public void lookAt(Point3d eye, Point3d target, Point3d up)
{
setPosition(eye); // updates camera position
// this is based on Mesa3D's glu.c lookAt(...) method
Point3d z = eye.sub(target).normalize();
Point3d y = up;
Point3d x = y.cross(z);
y = z.cross(x).normalize();
x.normalize();
// converting to Axis/Angle
Matrix3d m = new Matrix3d(x.x, x.y, x.z, y.x, y.y, y.z, z.x, z.y,
z.z);
rotation = new AxisAngled(m).normalize();
}
and from class AxisAngled:
public void set(Matrix3d matrix)
{
// x, y and z must be computed prior to computing angle
// (because of axisLength() which needs them)
x = matrix.e8 - matrix.e6;
y = matrix.e3 - matrix.e7;
z = matrix.e4 - matrix.e2;
a = Math.atan2(axisLength() / 2.0, (matrix.e1 + matrix.e5 + matrix.e9
- 1.0) / 2.0);
}
Any suggestions / fixes?
Can this be done simpler (without intermediate matrix stage)? Do you
have *any* working code that converts vectors to axis/angle?
Help!
Bye,
Max
--
-----------------------------------------------
Max Gilead gi...@li...
XMage library http://xmage.sourceforge.net
-----------------------------------------------
-- Sex on TV is bad. You might fall off...
|