PDA

View Full Version : Camera control in DirectX 9 - Need help



NecroDOME
17-02-2005, 03:10 PM
Hi there,

Im trying to rotate my camera (yaw, pitch and roll). I found this code snippet in the internet somewhere:


// Genenerate a quaternion, using only the yaw from the player
D3DXQuaternionRotationYawPitchRoll( &quat, cameraRotationYaw, 0.0f, 0.0f );

// Now build the matrix
D3DXMatrixAffineTransformation( &matOrientation, 1.25f, NULL, &quat, &cameraPosition );

// We must take the inverse to get the appropriate transformation
D3DXMatrixInverse( &matView, NULL, &matOrientation );


I translated it to

D3DXQuaternionRotationYawPitchRoll(Quat, Rotation.x, Rotation.y, Rotation.z);
D3DXMatrixAffineTransformation(matPos, 1.0, nil, Quat, Position);
D3DXMatrixInverse( matView, nil, matPos );



When I translate it te delphi I got an compiler error:
Incompatible types 'TD3DXQuarternion' and 'PD3DXQuarternion'

can anyone tell me how I translate TD3DXQuarternion to PD3DXQuarternion


(error is given on the Quat, witch is a TD3DXQuarternion in D3DXQuaternionRotationYawPitchRoll, and D3DXMatrixAffineTransformation needs a PD3DXQuarternion)

Could anyone help me with this ? Plzkthx

NecroDOME
24-02-2005, 09:01 AM
The solution the this problem is


D3DXQuaternionRotationYawPitchRoll(Quat, Rotation.x, Rotation.y, Rotation.z);
D3DXMatrixRotationQuaternion( matRot, Quat );
D3DXMatrixTranslation(matPos, Position.X, Position.Y, Position.Z);

D3DXMatrixMultiply(matView, matRot, matPos);

D3DXMatrixInverse( matView, nil, matView );

Device.SetTransform(D3DTS_VIEW, matView);

Sly
24-02-2005, 08:51 PM
I must have missed your original post, for it would have been a really easy answer. In the call to D3DXMatrixAffineTransformation, use the address-of operator by changing Quat to @Quat. This changes a TD3DXQuaternion to a PD3DXQuaternion.

NecroDOME
24-02-2005, 09:07 PM
thnx