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.