4
\$\begingroup\$

I have quite large 2D game scene. The scene is much larger than the screen of the LCD. Therefore, I have to move the camera (view) in desired directions, to display particular parts of the scene.

What is the correct way of moving viewport over the scene, in Orthogonal (2D) projection, please?

There are two solutions coming to my mind:

  1. Using GluLookAt(), which is designed to move camera moslty in Perspective Projection, but it could work well for 2D as well. However, not all of the GluLookAt() parameters would be utilized in Ortho configuration.
  2. Using opposite View Translate transformation. This would mean, if I need to move my 2D camera 10 units to the right(positive x axis), I would apply opposite Translate transformation to every scene vertex (negative x axis). This way, I would create illusion, the camera moves to the right.

These are the solutions coming from my mind. However, because, i am self taught, is there any correct and recommended way of moving camera over the 2D scene, please?

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

There are several correct ways -- both of the methods you described are fine. I would suggest the first method, using gluLookAt or otherwise directly manipulating the view transformation matrix to transform it sideways. All parameters to gluLookAt are still going to be used.

GL combines the world and view matrices into one, so depending on the level to which you abstract that yourself it may not matter if you manipulate the "view" matrix or the "object" matrix (since they're the same). If you do maintain a separation of these concepts in your own code, I would say that it's more readable to manipulate the view matrix (via gluLookAt or more direct transformation) than the object matrix, even the math would end up being equivalent.

\$\endgroup\$
3
  • \$\begingroup\$ +1, Hi Josh. Thank you for your good answer. You mention, that even in Orthographic configuration I would take advantage of all gluLookAt() parameters. Would you explain more, please, how I would use EyePosition or UpVector? As I understand Orthographic transformation, there is no eye distance from the camera center. I am not sure if UpVector would be any benefitial in Ortho views, as well. Thanks. \$\endgroup\$ May 13, 2011 at 16:25
  • \$\begingroup\$ gluLookAt just computes a matrix (using this math). It does nothing else, and it has no knowledge of the rest of the GL state, so the eye position and up vector -- which are used to define basis vectors to compute cross products and ultimately arrive at the final basis vectors for the view space are just as relevant and necessary regardless of whether or not you will eventually use a perspective or orthographic projection. \$\endgroup\$
    – user1430
    May 13, 2011 at 16:27
  • \$\begingroup\$ I see, and thanks for your additional comment. It was valuable, as I did not know things you mentioned in there. Your answer is clear candidate for the Accepted Answer, but I would like to wait few moments to see if others bring some valuable information. \$\endgroup\$ May 13, 2011 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .