I tried to make the third-person mode work on quaternions. Here's what I got:
[code=delphi]
ctThirdPerson:
if Assigned(FTarget) then
begin
FTarget.Move(AFactor);
Q := QuaternionFromEuler(Rotation);
Q1 := Quaternion(0.0, 0.0, 2.0, 5.0); // desired distance from the target
Q2 := QuaternionMultiply(QuaternionConjugate(Q),
QuaternionMultiply(Q1, Q));
Offset := Vec3(Q2.X, Q2.Y, Q2.Z);
NewPos := Vec3Add(Offset, FTarget.Position);
Position := NewPos;
end;
[/code]
But this code doesn't work, because the camera moves, while the target object remains stationery, even though there's a line that "commands" him to move.
Any suggestions?
EDIT
I haven't tried your code, User137 yet. First, I wanna see if it's possible to do on quaternions. The code I'm using is taken from another source, where it works.
EDIT2
Here's another code I found (in C#):
Code:
Matrix transform = Matrix.Identity;
transform.Forward = ChaseDirection;
transform.Up = Up;
transform.Right = Vector3.Cross(Up, ChaseDirection);
// Calculate desired camera properties in world space
desiredPosition = ChasePosition +
Vector3.TransformNormal(DesiredPositionOffset, transform);
lookAt = ChasePosition +
Vector3.TransformNormal(LookAtOffset, transform);
I could use it if I knew which array fields correspond to forward, up, and right vectors. I saw a nice diagram somewhere, but can't find it now. Can someone tell me where these vectors are?
EDIT3
haha, I found the picture: http://www.songho.ca/opengl/files/gl_anglestoaxes01.png
Bookmarks