←Back

OpenGL Camera

Under Construction...

Related Topics: OpenGL Transform, OpenGL Projection Matrix, Quaternion
Download: OrbitCamera.zip, trackball.zip

Overview

OpenGL Eye Space
OpenGL camera is always at origin and facing to -Z in eye space

OpenGL doesn't explicitly define neither camera object nor a specific matrix for camera transformation. Instead, OpenGL transforms the entire scene inversely to a space where a fixed camera is at the origin (0,0,0) and always looking along -Z axis. This space is called eye space.

Because of this, OpenGL uses a single GL_MODELVIEW matrix for both object transformation to world space and camera (view) transformation to eye space.

You may break it down into 2 logical sub matrices;
OpenGL ModelView matrix combined

That is, once all objects are transformed in a scene with Mmodel first, then transform the entire scene reversely with Mview. In this page, we will discuss only Mview for camera transformation in OpenGL.

LookAt

gluLookAt() is used to construct a viewing matrix where a camera is located at the eye position and looking at (or rotating to) the target point. The eye position and target are defined in world space. This section describes how to implement the viewing matrix equivalent to gluLookAt().

Camera lookAt animation
OpenGL camera's lookAt() transformation

Camera's looAt transformation consists of 2 transformations; translating the whole scene inversely from the eye position to the origin, and rotating the scene with reverse orientation, so the camera is positioned at the origin and facing to the -Z axis.

Suppose a camera is located at (2, 0, 3) and looking at (0,0,0) in world space. That is the camera's eye position is (2, 0, 3) and it rotates about 33.7 degree along Y-axis to look at the target. In order to construct the viewing matrix for this case, we need to translate the world to (-2, 0, -3) and rotate it -33.7 degree along Y-axis. As a result, the virtual camera becomes facing to -Z axis at the origin.

Camera pitch animation Camera yaw animation

Rotation

Shifting

Forwarding

Example: OpenGL Orbit Camera

OpenGL OrbitCamera

Download: OrbitCamera.zip

Example: Trackball

OpenGL Trackball

Download: trackball.zip

←Back
Hide Comments
comments powered by Disqus