• Advertisement


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

Camera Rotation around a 3D point

This topic is 5716 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

Why is it so hard? When my camera is at position X 0, Y 0 and Z 0 in the world, everything is perfectly fine, but when it''s in any other place it circles around the 0,0,0 point of the world.. This is what I am doing: LoadIdentity(matTemp); LoadIdentity(matView) MatrixRotateY(matTemp, camAngle); MatrixMultiply(matView, matView, matTemp); MatrixLookAtLH(matTemp, camEye, camAt, camUp); MatrixMultiply(matView, matView, matTemp); TransformMatrix(D3DTS_VIEW, matTemp); matView is the View Matrix, matTemp is a custom matrix to hold the values. camAngle is the angle. Please... 2 days have passed and I still can''t figure this out...

Share this post

Link to post
Share on other sites
you have to:

translate object to origin


translate back to original position


Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Since you are using DirectX, it is possible to use the D3DX helper library.

I believe it downloads seperate from DirectX 8 but comes with 7.

Check out the LookAtMatrix and LookAtMatrixLH functions. All you would have to specify is the point in space where your camera is located and then a look at point which could be built from your position and a directional vector. To rotate the camera, you would rotate the directional vector. To move the camera, you would move the position.

I''m not at my computer so I can''t dump some code here, but this is the way I solved the problem. I also had to write a short function to convert the D3DXMATRIX to a D3DMATRIX.


Share this post

Link to post
Share on other sites
Sorry to disturb, but, what are you doing...?

LoadIdentity(matTemp);//loading the identity matrix
MatrixRotateY(matTemp, camAngle);/*you load a identity rotated matrix, i usually start here*/
MatrixMultiply(matView, matView, matTemp);/*well ... you multiply it by the identity....*/
MatrixLookAtLH(matTemp, camEye, camAt, camUp); /* make a matrix that "look" to a point (rotaiting it to focus the point i belive 0,0,0 i think here''s your mistake)*/
MatrixMultiply(matView, matView, matTemp);/*you multiply it. I don''t know what you want to get*/

TransformMatrix(D3DTS_VIEW, matTemp);//you put it

i usually do ...

MatrixRotateY(&matRY, camAngle);//rotate
/*first rotate then translate multiplication it''s not conmutative... in matrix*/

(D3DTS_VIEW, matTemp);

if this is not your question.. sorry in advance.

Share this post

Link to post
Share on other sites
The camera is dynamic, I modify it everytime the user asks for.

The way I do it *now* was the only logical way I found of doing what I wanted:

// reset both matrices

// move camera to where the user is
MatrixTranslate(matTemp, MYXPOS, MYYPOS, MYZPOS);

// do whatever I have to do
MatrixRotateZ(matTemp, camAngle.x);
MatrixMultiply(matView, matView, matTemp);
etc. etc.

// back to original pos
MatrixTranslate(matTemp, 0, 0, 0);
MatrixMultiply(matView, matView, matTemp);

// we say matTemp will be a LookAtLH matrix
MatrixLookAtLH(matTemp, camVEye, camVAt, camVUp);
MatrixMultiply(matView, matView, matTemp);

// finally, transform
TransformMatrix(D3DTS_VIEW, matView);


Maybe I''m doing not necessary stuff, but I''m somewhat newbie to matrix math

Share this post

Link to post
Share on other sites

  • Advertisement