simulate camera rotation

Hi,

I wrote a primitive 3D renderer (from scratch, no opengl etc), I can apply 4x4 matrix transformations to my models. My camera is statically located looking down the z-axis.

Is it possible to figure out what rotation matrix should be applied to the models to simulate rotating the camera around the x-axis, or any other axis for that matter?

I’m not sure how you make the camera move, since all I have right now is transforming individual objects.

Thanks,
Mark

First you need to learn to put single transformation into matrix. If you look over the web, you should find many examples of matrices representing singla transformation.

Rotation matrix (around Z axis) would look more less like this:
cos(a) -sin(a) 0 0
sin(a) cos(a) 0 0
0 0 1 0
0 0 0 1

Since we rotate around Z, then Z axis doesn’t change but X and Y axes are “exchanging” their values sinusoidally. If a=0 then sin(a) = 0 and cos(a) = 1 which means we get an identity matrix.

Making matrix containing multiple transformation is done by multiplying single-transformation matrices.

The movement you’re interested in should do the folowing transformations:

  1. rotate object around one axis (Y)
  2. rotate object around another axis (X)
  3. translate object away from camera (Z axis)

Since at beginning object and camera are at the same location, rotating only changes angle of view. Finally you move such rotated object away.

Hi k_szczech,

I have all of that built into my Matrix3d class, so I’m set there.

What I’m wondering though is how you get the ‘camera’ to move about the world axes? Right now my engine (written from scratch) doesn’t really have a concept of camera, it’s just at (0,0,0) looking down the z-axis.

For right now I do all my matrix transformations on my objects, then move them to about (0,0,-200) so that they are in view of the camera.

Now I want to start moving the camera though, and don’t really know how to begin doing that.

The other option is to simulate camera movement by transforming all objects using the ‘world’ as the root as a large assembly. I don’t quite know how to do that given that I’d need to figure out dynamically which angles to rotate by to simulate the ‘camera’ moving.

Thanks

Hi Mark,

Maybe you can use the gluLookAt function.

gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ )

Then you can rotate about the X-axis by setting eyeY=sin(a) and eyeZ=cos(a)

N.

Hi NiCo,

I definitely would, it’s just that I wrote this rendering engine from scratch (no opengl or anything). I’m not quite sure mathematically how to approach this. I mean I’m rotating my models about the world axes, but then how do you do a ‘camera’ transformation? I don’t know if these rendering engines just figure out a world transform to apply to all models to make it ‘appear’ as if you’re really moving ‘the camera’, or if there really is some special class/implemenation of a camera you’re supposed to come up with?

Thanks

The link I provided you with explains how the 4x4 matrix is built:

M is then constructed as follows:
( s[0] s[1] s[2] 0 )
| u[0] u[1] u[2] 0 |
M = | |
|-f[0] -f[1] -f[2] 0 |
| 0 0 0 1 |
( )
and gluLookAt is equivalent to glMultMatrixf(M);
glTranslated (-eyex, -eyey, -eyez);

Check the glspec chapter 2.11.2 to see how the translate/rotate/scale calls are mapped to 4x4 transformation matrices.

N.

The trick is to figure out the transform that you would use to move your camera object into the world, but instead of transforming the camera, you transform the rest of the world using the inverse of this transform.

I was just about to put a similar post up, so I hope no one minds me asking a quick question here to prevent a similar thread.

I know you can do the camera movements/rotations with gluLookAt, OR you could simply apply all the opposite transformations to everything else. But I was wondering which is more efficient for moving the camera with mouse and keyboard input?

There really is no difference in efficiency, the gluLookAt function also sets up a modelview matrix that is used to transform all other objects you’re drawing. The only difference is in the way you think about the problem.