Archived

This topic is now archived and is closed to further replies.

camera rotation

Recommended Posts

trying to get my camera to be able to accept rotations... this is what i currently have:
D3DXMATRIXA16 matRotation;
D3DXMatrixRotationYawPitchRoll( &matRotation, rotation.x, rotation.y, rotation.z);

eye.x = matRotation._31;
eye.y = matRotation._32;
eye.z = matRotation._33;

D3DXMatrixLookAtLH( &matView, &position, &eye, &up );
Direct3D:D3DDevice->SetTransform( D3DTS_VIEW, &matView );

doesnt do anyhting when i change rotation values maybe this is totaly wrong?

Share on other sites
Hmm... What exactly are you trying to do? If you want to freely rotate your camera, then don''t use D3DXMatrixLookAtLH. That function takes the eye point (Where the camera is) and a look-at point (What the camera is looking at) and computes the View matrix based on those points.

Your code is setting the camera''s current position in world space based on a rotation matrix.

Now, if you would like to compute the base View matrix by using look at lh, Do that then freely rotate the camera by multiplying it by a rotation matrix afterwards, like this:

D3DXMATRIX View, Build;
D3DXMatrixLookAtLH(&View , &At, &Eye, &Up);
D3DXMatrixRotationYawPitchRoll(&Build, rx, ry, rz);
View *= Build;

If this is not what you are looking for either, then reply with a clearer description of what you''re trying to do.

Share on other sites
rotation to simulate "tilt" would involve changeing the up vector.

Share on other sites
yeah i want free cam,

is this what u meant with ur description:
	D3DXMATRIXA16 matCamera;	D3DXMATRIXA16 matRotation;    D3DXMatrixLookAtLH( &matView, &position, &eye, &up );	D3DXMatrixRotationYawPitchRoll(&matRotation, rotation.x, rotation.y, rotation.z);	D3DXMatrixMultiply( &matCamera, &matView, &matRotation );    Direct3D:D3DDevice->SetTransform( D3DTS_VIEW, &matCamera );

because that dont work either :-/

Share on other sites
Why don't you try quaternions?

D3DXQUATERNION QUAT;D3DXMATRIX     MatrixAT;D3DXMATRIX     ViewMatrix;//--//--D3DXQuaternionRotationYawPitchRoll(&QUAT, CamRotY, CamRotX, CamRotZ);D3DXMatrixAffineTransformation(&MatrixAT, 1.25f, NULL, &QUAT, &CameraPosition);D3DXMatrixInverse(&ViewMatrix, NULL, &MatrixAT);//--//--Device->SetTransform(D3DTS_VIEW, &ViewMatrix);

EDIT: If you're wanting a free cam, then you might want to consider quaternions. If not it will be gimble lock city.

BTW - It looks like you're using DirectX9. It's the same for DirectX9 just change the D3DXMATRIX to D3DXMATRIXA16.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on July 2, 2003 8:20:22 AM]

Share on other sites
i dont use quaternions, because i dont know how, are they easy to use? any good tuts?

Share on other sites
quote:
Original post by UltimaX
EDIT: If you're wanting a free cam, then you might want to consider quaternions. If not it will be gimble lock city.

why is everybody trying to make people believe that quaternions are the only working solution? theres more than just euler angles and quaternions and the only real good reason for quaternions are interpolating rotations or maybe having 7 instead of 9 floats to store an orientation.

no, euler angles wont work correctly but neither will quaternions if he still tries to just update 3 angles and build the correct quat from them. the problem isnt vectors or quats but not loosing the order in which you rotate.

also, multiplying a matrix built with lookat and one with yawpitch.. shouldnt work. one is an inverted matrix (for view) and the other is "normal" (for transformation).
why dont you just forget about lookat, insert the position in the matrix from yaw... and invert it (if the general version coming with dx isnt optimized to handle this special and easy case just check what lookat does to inverse it and do the same yourself).

still, storing three angles and doing stuff like anglex+=3 when turning left wont get you far.

[edited by - Trienco on July 3, 2003 4:42:59 AM]

Share on other sites
well, lets assume im using good ''ol rotations,

everything i''ve tried hasnt worked, any suggestions why?

Share on other sites
directx is making it quite easy with its seperate view matrix. just keep a camera matrix, apply transformations to it like to any other object and invert it before setting it as view matrix.

edit: if i remember that right they are in global space so you might want to make sure you rotate around the right axis (the cameras axes, not the world axes). i wouldnt be surprised if just switching the matrices around will have the same effect.

[edited by - Trienco on July 3, 2003 4:46:01 AM]

Share on other sites
can i just apply a rotation matrix to the view matrix?

Share on other sites
no, because the view matrix is inverted to move everything else the opposite way. thats why you keep and transform a seperate matrix and inverse it when you need to set the view matrix.

Share on other sites
Hi

Try something like this.

Every frame create three matrixes that will become one matrix representing the view matrix.

Create one rotation matrix for X and Y axis. Thats 2 of 3.
D3DXMatrixRotationX (&viewTransformTemp, valueX);
viewRotationX *= viewTransformTemp;

D3DXMatrixRotationY (&viewTransformTemp, valueY);
viewRotationY *= viewTransformTemp;

Then create the camera translation(transform):

D3DXMatrixTranslation (&viewTransformTemp, valueX, valueY, valueZ);
viewTransform *= viewTransformTemp;

(Notice: the last frames data must be held to achieve an nice camera animation).

Now multiply the three matrixes together to get your view matrix(well not actually yet but getting closer).

viewMatrix = viewRotationX*viewRotationY*viewTransform;

Now every frame zero the D3DXMatrixLookAtLH() fucntion required componentes like Eye position, view target, view normal etc.. what ever you need to create the finel view matrix.

viewEyePosition = D3DXVECTOR3 ( 0.0f, 0.0f, 0.0f);
viewTarget = D3DXVECTOR3 ( 0.0f, 0.0f, 10.0f);
viewNormal = D3DXVECTOR3 ( 0.0f, 10.0f, 0.0f);

Something like above. Now multiply every component with the viewMatrix MATRIX(we just created it).
D3DXVec3TransformCoord (&viewEyePosition, &viewEyePosition, &viewMatrix);
D3DXVec3TransformCoord (&viewTarget, &viewTarget, &viewMatrix);
D3DXVec3TransformNormal (&viewNormal, &viewNormal, &viewMatrix);

Now your eye position, view target and view normal has been set to curent "view space". Then just multiply the components into a matrix and pass it to DirectX.

D3DXMatrixLookAtLH (&viewMatrix, &viewEyePosition, &viewTarget, &viewNormal);
DX9Interface->gmD3DDEVICE9->SetTransform(D3DTS_VIEW, &viewMatrix);

Voila.. But wait this doesn''t rotate the camera. Well yes it doesn''t, but hey now you can assign value to X, Y rotation, camera translation etc.. All you have to do is to pass to the rotation matrix operations and the translation operation values and the camera will start to come. Use functions like sin() and cos() to create and circle that will move your camera. As the last tip put every operation in their own function. So that you can alter the rotation and traslation matrixes as much as you want untill you are ready to create the final view matrix for DirectX.

• Forum Statistics

• Total Topics
628375
• Total Posts
2982319

• 10
• 9
• 14
• 24
• 11