I have the rotation(A), elevation(B) and location(C) of a camera in a left handed 3d space. +x is right, +y is down and +z is inwards. Initially the camera is pointing in +z direction with up direction being -y. This camera is rotated by angle B along x axis, rotated by angle A along y axis and then translated by vector C.

How do I calculate the view matrix for such a camera?


1 Answer 1


You can compute your new right vector using the unit circle (assuming your angle A is measured in radians):

right.x = - cos(A)
right.y = 0
right.z = sin(A)

Here I've used a negative on the x component, because you said the camera is initially pointed in the +z direction. That would mean its "right" vector points in the world's "left" direction when angle A is zero.

We can use a similar trick for the forward and up vectors, using spherical coordinate formulas and a cross product:

forward.x = cos(B) * sin(A)
forward.y = sin(B)
forward.z = cos(B) * cos(A)

up = cross(forward, right)

Now a 3x3 matrix with (right, up, forward) as its columns will rotate an object by angles A and B.

Expand it to a 4x4 matrix and make the last column (C.x, C.y, C.z, 1) and now you have a complete local to world matrix, with both rotation and translation.

Invert this matrix to get a world to local matrix, to transform the worldspace positions of objects into the camera's view space.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .