Re: Fixed object using quaternion



"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


.



Relevant Pages

  • RE: Light Direction relative to World Matrix
    ... It's usual practice to move the camera and derive the view matrix transform ... I can then rotate the world matrix to rotate my camera. ... I use a Tilt field to change the Z-component of my LookAt vector, ... This means that when I rotate the camera, the shadows on the ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Camera preview orientation on HTC-Universal
    ... It sounds to me like you're seeing a camera ... does not use DirectShow or the DirectShow camera driver. ... This is necessary because as you rotate the shell on the device you also physically rotate the device. ... How can I tell the output renderer to NOT rotate / flip the content? ...
    (microsoft.public.pocketpc.developer)
  • Re: rotation
    ... create a vector representing the camera, ... then with that angle create a rotation matrix, set it on the device, draw. ... The angle that is a radian conversion says the value is ... I am trying to rotate this object so that it faces the camera for then ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Light Direction relative to World Matrix
    ... > from the camera position, ... I can then rotate the world matrix to rotate my camera. ... I use a Tilt field to change the Z-component of my LookAt vector, ... >>Microsoft MVP ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Camera preview orientation on HTC-Universal
    ... Rendering the preview pin as you did below should always result in the image ... It sounds to me like you're seeing a camera ... does not use DirectShow or the DirectShow camera driver. ... >> the correct orientation (don't rotate when rendering it). ...
    (microsoft.public.pocketpc.developer)