PDA

View Full Version : Get Matrix rotations...



NecroDOME
28-11-2006, 04:09 PM
Hi,


case CameraType of
cameraFree:
begin
D3DXQuaternionRotationYawPitchRoll(Quat, Rotation.x + CameraShake.Rotation.x,
Rotation.y + CameraShake.Rotation.y,
Rotation.z + CameraShake.Rotation.z);
D3DXMatrixRotationQuaternion( matRot, Quat );
D3DXMatrixTranslation(matPos, Position.X, Position.Y, Position.Z);

D3DXMatrixMultiply(matView, matRot, matPos);

D3DXMatrixInverse( matView, nil, matView );

Screen.Device.SetTransform(D3DTS_VIEW, matView);
end;
cameraTarget:
begin
D3DXMatrixLookAtLH(matView, Position, TargetPoint, WolrdUp);

Screen.Device.SetTransform( D3DTS_VIEW, matView );

// Somewhere here: Rotation := GetRot(matView );
end;
end;


This piece of code I use to setup my camera in 3D view. However when I have a cameraTarget, I want to be able to retrieve teh rotation. How can I get the rotation from matView???

I realy need it. I use it to rotate the particles :P

Greets Michiel

cronodragon
28-11-2006, 04:54 PM
I had a similar question at GameDev.net, this is the answer:

http://www.gamedev.net/community/forums/viewreply.asp?ID=2818743

NecroDOME
28-11-2006, 08:20 PM
It retrieves the position. I need the rotation. I tried the code, but it didn't work in they way I want it...

btw: is there a way to just make teh camera rotate to a specified point? that rotation I can use to transform teh camera. In that case teh problem is solved.

cronodragon
28-11-2006, 08:29 PM
Think it this way: with D3DXMatrixLookAtLH() you define the camera position (pEye vector) and the objective (pAt vector). Set the objective 1 unit from the eye, and rotate the objective using the eye as pivot.

NecroDOME
28-11-2006, 10:59 PM
I take a look at that tomorrow... thanks for the advice:)

JSoftware
29-11-2006, 03:18 PM
I don't know how(and I don't think you can) you can convert the matrix directly to axisangle rotations

I would just convert the matrix into a quaternion and from that turn it into a rotation vector

NecroDOME
29-11-2006, 03:43 PM
I solved the problem:
Rotation.x := -ArcTan2(TargetPoint.z - Position.z, TargetPoint.x - Position.x)+(Pi*0.5);

x := (TargetPoint.x - Position.x) * (TargetPoint.x - Position.x);
z := (TargetPoint.z - Position.z) * (TargetPoint.z - Position.z);

Rotation.y := ArcTan2(Sqrt(x+z), TargetPoint.y - Position.y)-(Pi*0.5);
Rotation.z := 0;