View Full Version : camera rotation matrix calculation

01-28-2001, 10:35 PM
i`m trying to calculate the matrix for camera rotation
rotation around the 0-X axes:
{ 1, 0, 0
0, cosX, -sinX,
0, sinX, cosX}
rotation around the 0-Y axes:
{cosY, 0, sinY,
0, 1, 0,
-sinY 0, cosY}
rotation around the 0-Z axes:
{cosZ, -sinZ, 0
sinZ, cosZ, 0
0, 0, 0}
after multiplication of the matricies we`ll yield the matrix, which rotates the camera around the global X,Y,Z axes:
matrix[0]=cosY*cosZ; matrix[4]=-cosY*sinZ; matrix[8]=sinY; matrix[12]=0;
matrix[1]=sinX*sinY*cosZ+cosX*sinZ; matrix[5]=-sinX*sinY*sinZ+cosX*cosZ; matrix[9]=-sinX*cosY; matrix[13]=0;
matrix[2]=-cosX*sinY*cosZ+sinX*sinZ; matrix[6]=cosX*sinY*sinZ+sinX*cosZ; matrix[10]=cosX*cosY; matrix[14]=0;
matrix[3]=0; matrix[7]=0;matrix[11]=0; matrix[15]=1;

To manipulate the camera - we have 2 angles: x, y cordinates of the mouse - turn around the Y and X axes.
This two angles - LOCAL to camera.(if global Y-not zero than global X not zero and global Z not zero).
Local camera 0Z axes always lies in global X0Z coordinates

How to project this 2 local mouse angles on to 3 global angles?

01-28-2001, 11:39 PM
You must not use a 3rd angle. use Polar-coordinates.

carthesic coords (hope i spelled it right...in german it is "Kartesische")

are (x,y,z)

polar coords are

(phi, lambda, radius)

where phi and lambda are 2 angles.

use mouse.x and mouse.y as angles. set radius to p.ex. 1 or 2.....

place the cam in (0,0,0) (or whatever) and calculate the lookat (and transform it by the camera-pos) with:


if cam is not 0,0,0 do:


..... this should work fine.