#### Archived

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

# newbie question: camera rotation about origin

## Recommended Posts

riz    122
Hi all, I am having a bit of trouble figuring out a third person camera, and I'd appreciate it if someone could post a code sample on how to rotate the camera about the origin. By this, I am confused by the matrix multiplications... so far i have this:
D3DXMATRIX matTranslate, matRotate, matTranslateBack, camera;

D3DXMatrixTranslation(&matTranslate, -camera_loc_x, -camera_loc_y, -camera_loc_z);
D3DXMatrixRotationY(&matRotate, camera_yrot);
D3DXMatrixTranslation(&matTranslateBack, camera_loc_x, camera_loc_y, camera_loc_z);

D3DXMatrixMultiply(&camera, &matTranslate, &matRotate);
//D3DXMatrixMultiply(&camera, &camera, &matTranslateBack);

g_pd3dDevice->SetTransform( D3DTS_VIEW, &camera);

but this gives rotates the camera about ITS y-axis, but not about the origin's. BTW i know you are supposed to translate, rotate, and translate back, but if I uncomment the second line, then all goes haywire. Anyway, it's late and my brain is not working as it should, so if anyone has some pseudocode/code sample on simply implementing a 3d person camera about the origin, i would so greatly appreciate it! riz [edited by - riz on May 2, 2002 3:59:52 AM] [edited by - riz on May 2, 2002 4:00:17 AM]