Re: Fixed object using quaternion
- From: "Dave Eberly" <dNOSPAMeberly@xxxxxxxxxxxxxxx>
- Date: Wed, 23 Aug 2006 14:08:48 GMT
"Serpe" <lorenzo@xxxxxxxxxx> wrote in message
news:1156327330.579311.281260@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a camera and a serie of object that have to remain fixed in the
camera view. When i rotate or move the camera the objects have to
rotate and move to mantain the distance and the angle from the camera
and they have to face the camera.
I am using quaternion to rotate objects and the camera too.
How can i achieve this effect?
Here is the description using vectors/matrices. Converting
the results to quaternions is a simple step. I use the
following convention: If M is a 3-by-3 matrix and T is a
3-by-1 vector, then the transformation of a 3-by-1
vector X produces a 3-by-1 vector Y = M*X + T (matrix
times vector uses matrix-on-left, vector-on-right). If
you apply another 3-by-3 matrix N, the composition is
N*M. If your system uses matrix-on-right, vector-on-left
(as a row vector), then you will need to adjust the
construction below.
Let E be the current world location for the camera. Let
D be the camera view direction, let U be the camera up
direction, and let R = Cross(D,U) be the camera right
direction. The matrix P = [D U R], whose three columns
are the specified vectors, is a rotation matrix.
Translation. If you translate E to E', then the incremental
change E'-E is added to all the object's world-space points.
Assuming you have a model-space object and a
model-to-world transformation, say, translation T and
rotation M, then the new model-to-world transformation
has translation T' = T+E'-E and the same rotation M' = M.
Rotation. Let Q be a rotation matrix that you will apply
to the camera vectors. The rotated vectors are D' = Q*D,
U' = Q*U, and R' = Q*R. In matrix terms, the total rotation
is Q*P, where P was defined previously in this post. The
rotation Q is applied to world points so that the rotation
is about the camera location E. Any point X in world space
is transformed to a new point X' = E + Q*(X-E).
I have assumed the model-to-world transformation involves
translation T and rotation M and *no* scaling. If you have
scaling, adjust accordingly. Let M = [A B C], where A, B,
and C are the three columns of M. Since M is a rotation
matrix, A, B, and C are unit length, mutually perpendicular,
and C = Cross(A,B). The world point X is rotated about E
to X'. The world point X+A is rotated about E to
X' + A' = E + Q*(X+A - E), so A' = Q*A. Similar arguments
show that X+B is rotated to X'+B', where B' = Q*B, and
X+C is rotated to X'+C', where C' = Q*C. Finally, X is a
world point and is obtained from a model-space point by
X = M*Z+T. Then
X' = E + Q*(X - E)
= E + Q*(M*Z+T - E)
= (Q*M)*Z + (Q*(T-E)+E)
This implies that the new model-to-world transformation has
a rotation M' = Q*M and a translation T' = Q*(T-E)+E.
In your system that uses quaternions, you have M and Q
represented as quaternions. The product of these
quaternions represents M'.
--
Dave Eberly
http://www.geometrictools.com
.
- References:
- Fixed object using quaternion
- From: Serpe
- Fixed object using quaternion
- Prev by Date: Re: OpenGL Tutorial
- Next by Date: move camera around object
- Previous by thread: Fixed object using quaternion
- Next by thread: move camera around object
- Index(es):
Relevant Pages
|