OpenGL 2D Camera

Started by
0 comments, last by haegarr 14 years, 4 months ago
I am trying to implement a camera system that ties into the scenegraph. Every object on the scenenode is passed a matrix from its parent node and multiplies its own matrix to that. Then the contents are rendered. The problem I have is setting up an 2D camera using the scene node's transformation to build the view matrix. From the scene node I have a transformation that translates, rotates, and scales. My world space before the view matrix is setup with (0, 0) at the top left corner. I need the camera to rotate about the center and zoom about the center. Every combination of transforms I think should work does not work yet. How do I set the view matrix from the scenegraph transform?
Advertisement
In general the way is as follows (column vectors are used as ususal for OpenGL):

(1) Wrap the scaling with a temporary translation to ensure the correct center of scaling
C * S * C-1
where C denotes the center of scaling and S the scaling matrix.

(2) Wrap the rotation with a temporary translation to ensure the correct center of rotation
C * R * C-1
where C denotes the center of rotation (the same of those for the scaling in your case) and R the scaling matrix.

(3) Choose the convenient order "scaling first, then rotating the scaled object, then translate the rotated object"
T * C * R * C-1 * C * S * C-1
==
T * C * R * S * C-1

(4) Multiply with the parental transformation matrix
P * T * C * R * S * C-1

(5) The view transformation is the inverse of the camera transformation
( P * T * C * R * S * C-1 )-1

This topic is closed to new replies.

Advertisement