3D Camera Math

Pages: 123
If you bend your neck 90°, your party hat will point to the wall rather than
the ceiling, while your ears will point to the floor and ceiling respectively.


This should clear things up -> http://tinypic.com/r/21jyf52/5
You can tell I'm not cheating by looking at the keys I press :)

Panning [1] and tilting [2] also work as expected, though there is a slight inconvenience. Because tilting up
and down now also affects the y' axis, you get the effect of rotating around the forward axis if you move your mouse in a circular way. This is how it's supposed to be working; it's not a bug. It can be annoying, because if, for example, you pan left and then right by the same amount, you may notice an unwanted slight rotation. The
easy fix for that last one is to simply ignore panning / tilting in one axis (horizontal or vertical) if the respective change in the mouse position is much smaller than the one in the other axis.

[1] http://en.wikipedia.org/wiki/Panning_(camera)
[2] http://en.wikipedia.org/wiki/Tilt_(camera)
Last edited on
Thanks very much for your help, when I get back to my dev environment I will try it out!

As for the inconvenience you mention, if it is what I think it is, then my current setup doesn't have that problem. If it's not what I think it is, I'll be back to discuss fixing it in a more elegant way ;)
I finally decided to go grab SFML 2.0 (it was about time, I guess) and see
what your code does, and I just wanted to comment on a couple of things.

my current setup doesn't have that problem

This is true, but it is at the expense of imposing constraints on the camera movement. Try tilting down and moving up until you can only see the red faces of your cubes. Then, try panning left and right. You'll notice
that the camera instead rotates around its forward (z') axis. This is an indication that your camera's up (y')
axis is always equal to the global y axis, much like in a FPS setup (and my first post). My point here is that
the inconvenience I mention is not really a 'problem'. It's just a(n) (unavoidable) side-effect of entirely unconstrained camera movement. You can't have the latter without the former.

Another thing I noticed is that after moving to the position and orientation I mentioned above, I was unable to continue tilting down in order to see the yellow faces. I had to rotate 180 degrees around the forward axis
(by exploiting the panning 'bug') and then tilt up. I figured it had to do with the if statements, so I commented them out and tried again. This time, I was able to continue tilting, but when I could only see the yellow faces the panning controls were inverted (which is also a side-effect of y' == y, and, I guess, the reason you put the if statements there).

I'm not saying your setup is a bad setup for panning and tilting; actually, this is exactly the expected behaviour in a FPS game. It's just that it doesn't mesh well with the rest of your expectations from the camera movement, and this is probably the reason you got stuck. Think about it: Panning, as you implemented it, requires that
y' == y. However, the rotation around the forward axis you wanted to introduce has to change y' in order to work properly (and, of course, the incompatibility is there even if you don't explicitly maintain such a vector).


PS: Congrats though for managing to pull this off with sin and cos. I'm not sure I have the patience to do this...
Last edited on
Thanks, you're right. Somehow I had this cognitive dissonance between what I thought my camera controls were doing and what they were actually doing.
Topic archived. No new replies allowed.
Pages: 123