Think of an artist who tries to paint a view. What should he do? At first he should decide his sitting position (adjusting the camera) and secondly he should try to paint that 3D view onto a 2D paper (projection). Last thing he should decide is which part of the paper the view will be drawn (viewport). What an OpenGL programmer should do is a very similar to this process:
In computer graphics we represent assets as array of points. Every point is represented with 4 parameters in homogeneous coordinates, in mathematics it's represented with matrices like:
Pay attention it is not the representation on the screen. It is the representation of the asset in the real world coordinates. Screen is a 2D plane so that we need to project the asset on it. In order to do that we need to multiply it with a Transformation Matrix called Projection Matrix. We have basically two kind of projections in computer graphics:
- Perspective Projection
- Orthographic Projection
Ortographic projection can be used in computer aided applications. You can think of Autocad or Solidworks type of applications. Perspective projections can be used in especially in games. Basically in perspective projections you can view assets relatively. As an example if you're in a plane and looking below you'll see road lines which are all the same size. But you're in a car you'll see the farthermost line as the shortest one. After you make decision between ortographic and perspective projections you need to multiply your asset (array of points) with this projection matrix. The result of this operation will give you the asset's 2D represented coordinates. Then remember that you should decide which part of the screen you want to draw this object. It is another transformation type called viewport. When you multiply the last result with your viewport matrix then you obtain the drawing of your asset on the screen.
And lastly what if you want to move the object on the screen(Translation) or want to show your asset bigger/smaller (Scaling), or want to rotate your asset? These are called viewing transformations as a whole. In OpenGL we have modelview matrix in order to do these operations. Model is our asset and view our camera. Think why both of them represented as one matrix? Because, there is no difference between rotating model about left side 45 degrees or rotating camera about right side 45 degrees. This example is valid with other situations as well. (Translation,Scaling)
I think it's been a good introduction about Computer Graphics and OpenGL.
Hiç yorum yok:
Yorum Gönder