#### Archived

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

# Camera Rotation around a 3D point

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

## 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 on other sites
you have to:

translate object to origin

rotate

translate back to original position

-me

##### Share on other sites
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.

-James

Thanks a lot

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

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
D3DXMatrixTranslation(&matT,0,0,g_fDistanceZ);
D3DXMatrixMultiply(&matView,&matRY,&matT);
/*first rotate then translate multiplication it''s not conmutative... in matrix*/

(D3DTS_VIEW, matTemp);

##### 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.
multiply.

// 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

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 10
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633331
• Total Posts
3011395
• ### Who's Online (See full list)

There are no registered users currently online

×