best way to implement a camera effect

I have a pretty naive question about implementing a camera that is controlled by the keyboard and optionally mouse.

My goal is to have a camera look at a fixed character initially. Then, with up, down, left and right arrow keys, the camera will remain in the same z value, but move horizontally closer to the direction the camera is looking at or horizontally further. With the left and right, it would just move left and right horizontally.

However, when I use the mouse to change the angle of the camera (assuming upvector is the z axis always), the keyboard will generate consistent movements… namely closer to the direction I’m looking at if I hit up arrow and further (backwards) if I hit the down arrow.

Am I making sense? Also, I’m thinking I’ll probably have to use a variable velocity and a task to implement the speeding up and slowing down of the camera. I think I have a pretty good picture about this part, just not sure about the first part I mentioned. You guys have some tip or a quick tutorial for this kind of thing? I should probably get a game programming book huh? Oh, I was looking at the compass effect… could it be used to make the camera always move up and down the x axis even if I change camera angle?



Probably the easiest way to implement that sort of thing is to use self-relative motions, like this:

camera.setPos(camera, 0, 1, 0)
camera.setPos(camera, 1, 0, 0)

to move the camera one foot forward or right, respectively. Since you are specifying to move the camera relative to its current position and orientation, then when the camera tilts up or down, “forward” will start to aim up or down as well.

A CompassEffect is not really the thing you want to use here; that’s more useful when you have a deeply nested scene graph and you want some object to always weathervane in the same direction regardless of its parentage.