In OpenGL or similar 3D graphic API (Application Programming Interface), we have to make transformations. The three main components of the transformation that used in 3D rendering are “Translation” (moving from one position to another), “Rotation” and “Scaling” (changing the size). Transformation means applying these three things to 3D models, environment or camera in 3D world.
In OpenGL, the transformations can be categorized into three forms. They are Modeling Transformation, Viewing Transformation and Projection Transformation. To implement these transformations in OpenGL with any programming language, we can use matrices or Quaternions. Normally, OpenGL graphic API only supports matrices. However, calculating in Quaternions is more efficient than using matrices in real implementations.
To understand the transformations in OpenGL, we can imagine and compare with taking a photo in real world.
Imagine what we will do when we are about to take a photo of an object in real world. The first thing we might do is the positioning of the object. We have to place the object that we want to take a photo of it in environment. We have to think about where to place that object (translation), in which orientation (rotate) and what is the size of that object (scale). Based on these faces, we have to decide how we want the photo of that object. In OpenGL, "this is Modeling Transformation”. We are considering about the object (3D model) to render it.
Some of the functions in OpenGL for transformation are glTranslate, glRotate and glScale.
After we have positioned and determined for the object that we want to take a photo, we have to think about our camera. Of course....! We still need to think about the camera. We also need to think about transformations for our camera. We have to place the camera at proper position (or probably the cameraman) and then determine the orientation of the camera. (Camera should be upside down or 90 degree rotated..?). In OpenGL, we called that case as “Viewing Transformation”. The most widely used function for implementing the viewing transformation in OpengL is gluLookAt( ). It has three sets of coordinate values as show below. By setting these three coordinate values for that function, we can define the correct the transformation to our camera.
gluLookAt ( x, y, z, x, y, z, x, y, z)
The first coordinate values (blue) are for the position of the camera or eye coordinates. The second (red) coordinate values are the position that the camera will be looking at (look at). The last three coordinate values are for the camera's “up vector”. It defines the alignment of the camera according to the one of the X, Y, Z axis. For example, gluLookAt (2,3,5, 0, 0, 0, 0, 1, 0) means that our camera is at position (2,3,5) in 3D world. The camera will be looking at the original (0,0,0) and the orientation of the camera is along Y axis (0,1,0). That means that the “up vector” of the camera is in same direction of positive Y axis.
Another transformation in OpenGL is “Projection Transformation”. Projection transformation has two sub categories, perspective projection and orthogonal projection.
Perspective projection is displaying (or rendering) as in the real world. The nearer objects to the viewers will be large and the far objects will be small according to the distance from viewer (or camera). Orthogonal projection is useful for engineering drawing. It has no perspective and all the object in rendered scene will be the same size regardless of the distance from viewer. Therefore, they can be used in blue-print drawing in engineering tasks.
One special thing we need to think in perspective projection is “frustum”. If you don't know about what is the frustum, see the figure to understand about it. Only objects inside that frustum can be seen by viewer in OpenGL rendering API. In other way, only objects (models) inside that frustum will be rendered by OpenGL. There are some components in frustum. Near and far planes are easy to understand. Fovy is an angle of viewing. I hope they can be understood by seeing the picture
If we compare the projection transformation with taking photo at outside, it is defining and setting of the lens of the camera. We can define how much distance the camera's lens will capture and the setting of focus of the lens.
The last transformation we also need to mention in OpenGL is “viewport transformation”. Imagine that after we have taken a photo with camera, we have to print out the photo to photo paper from film. We can define the size and shape ratio of the photo just before it can be transferred to the photo paper from film. This is also called “aspect ratio”. The real photo on the photo paper is the “viewport” of our image. We can also define the viewport in OpenGL rendering (see the figure). Therefore, viewport transformation is defining the aspect ratio and how we can see our rendered 3D scene on the screen.

OK..! This article is the discussion of the basic ideas of transformation in OpenGL. I hope this article is useful for the beginners and junior students in digital media field. I also believe that the ideas and basic concepts in this article is also useful for any other graphic APIs.
In OpenGL, the transformations can be categorized into three forms. They are Modeling Transformation, Viewing Transformation and Projection Transformation. To implement these transformations in OpenGL with any programming language, we can use matrices or Quaternions. Normally, OpenGL graphic API only supports matrices. However, calculating in Quaternions is more efficient than using matrices in real implementations.
To understand the transformations in OpenGL, we can imagine and compare with taking a photo in real world.
Imagine what we will do when we are about to take a photo of an object in real world. The first thing we might do is the positioning of the object. We have to place the object that we want to take a photo of it in environment. We have to think about where to place that object (translation), in which orientation (rotate) and what is the size of that object (scale). Based on these faces, we have to decide how we want the photo of that object. In OpenGL, "this is Modeling Transformation”. We are considering about the object (3D model) to render it.
Some of the functions in OpenGL for transformation are glTranslate, glRotate and glScale.
After we have positioned and determined for the object that we want to take a photo, we have to think about our camera. Of course....! We still need to think about the camera. We also need to think about transformations for our camera. We have to place the camera at proper position (or probably the cameraman) and then determine the orientation of the camera. (Camera should be upside down or 90 degree rotated..?). In OpenGL, we called that case as “Viewing Transformation”. The most widely used function for implementing the viewing transformation in OpengL is gluLookAt( ). It has three sets of coordinate values as show below. By setting these three coordinate values for that function, we can define the correct the transformation to our camera.
gluLookAt ( x, y, z, x, y, z, x, y, z)
The first coordinate values (blue) are for the position of the camera or eye coordinates. The second (red) coordinate values are the position that the camera will be looking at (look at). The last three coordinate values are for the camera's “up vector”. It defines the alignment of the camera according to the one of the X, Y, Z axis. For example, gluLookAt (2,3,5, 0, 0, 0, 0, 1, 0) means that our camera is at position (2,3,5) in 3D world. The camera will be looking at the original (0,0,0) and the orientation of the camera is along Y axis (0,1,0). That means that the “up vector” of the camera is in same direction of positive Y axis.
Another transformation in OpenGL is “Projection Transformation”. Projection transformation has two sub categories, perspective projection and orthogonal projection.
Perspective projection is displaying (or rendering) as in the real world. The nearer objects to the viewers will be large and the far objects will be small according to the distance from viewer (or camera). Orthogonal projection is useful for engineering drawing. It has no perspective and all the object in rendered scene will be the same size regardless of the distance from viewer. Therefore, they can be used in blue-print drawing in engineering tasks.
One special thing we need to think in perspective projection is “frustum”. If you don't know about what is the frustum, see the figure to understand about it. Only objects inside that frustum can be seen by viewer in OpenGL rendering API. In other way, only objects (models) inside that frustum will be rendered by OpenGL. There are some components in frustum. Near and far planes are easy to understand. Fovy is an angle of viewing. I hope they can be understood by seeing the picture
If we compare the projection transformation with taking photo at outside, it is defining and setting of the lens of the camera. We can define how much distance the camera's lens will capture and the setting of focus of the lens.The last transformation we also need to mention in OpenGL is “viewport transformation”. Imagine that after we have taken a photo with camera, we have to print out the photo to photo paper from film. We can define the size and shape ratio of the photo just before it can be transferred to the photo paper from film. This is also called “aspect ratio”. The real photo on the photo paper is the “viewport” of our image. We can also define the viewport in OpenGL rendering (see the figure). Therefore, viewport transformation is defining the aspect ratio and how we can see our rendered 3D scene on the screen.
OK..! This article is the discussion of the basic ideas of transformation in OpenGL. I hope this article is useful for the beginners and junior students in digital media field. I also believe that the ideas and basic concepts in this article is also useful for any other graphic APIs.
No comments:
Post a Comment