Jump to content
  • Advertisement

Archived

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

supagu

camera rotation

This topic is 5640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
rotation to simulate "tilt" would involve changeing the up vector.

Share this post


Link to post
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 this post


Link to post
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 this post


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

Share this post


Link to post
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 this post


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

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

Share this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!