| further reading | more topics » |
| mjbWorld program | 3D theory |
3D physics |
3D maths |
3D programming | technology |
about site |
sitemap A-Z |
| index | language | dev tools | games | structure | platforms | OOAD | information |
| index | setup | 2d | 3d |
| index | dx9vb | dx9C# | OpenGL C++ |
| index | introduction | first | shapes | 3D | rotation | textures | camera |
| keyboard | moving |
|
This toturial was written for me by Imran Khan (imranahmedkhan82@hotmail.com,
iak1982@yahoo.com). |
||||||
|
Use of Camera: In this section we will learn 'How to use Camera in Opengl' . Camera usage is the most important feature of OpenGL. As it is impossible to move in a 3D-World physically. We therefore use Camera in order to move in 3D-world. First of all we will define a Vector Structure.
First we define 2 constructors, one with no arguments ( which is also called Default Constructor) and one with 3 arguments. As we are in 3D , we will use 3 coordinates (x,y,z). we assign the value of the arguments (new_x,new_y,new_z) to its local variable(x,y,z). Next we Overload ( + , - , * , / ) Operators.So
that we can easily add,subtract,multiply,divide Vectors Now declare 3 variable of " tVector " structure.
First variable use for Setting position of the Camera.
We can easily understand this by the following figure.
Now I think, it will be more clear that why we use Vector structure. Now we will define a method which will set the position,view and up vector of the Camera.
It takes 9 arguments : (x,y,z) for each ( position,view,up ). We use this method so that we can set the initial postion of the Camera.First we set initliaze the mPos then mView and then mUp.We will call this method in the InitGL method. So that our Camera postion will be set at the bigenning of the program. Now the InitGL method will be look like :
As we set the position of the Camera. We just assign values to some variables (vector ). Now we will call a predefined function 'gluLookAt' and passed the variables, which we have already set, to this method. We will call the this method in 'DrawGLScene' method. Before each shape we draw, we will first call 'gluLookAt '. Before drawing Pyramid....
Before Drawing Cube...
"gluLookAt " , places the camera at the position of the first 3 parameters, places the center of the scene at the position of the next 3 parameters, and the last 3 parameters describe the vector that is "up".We done nothing , we just passed the variable , which we already set. You can play with the initial vlaues of Position,View and Up Vectors, to see wat changes it will produce. |
|
metadata block
|
|
| see also: |
|
| Correspondence about this page | |
|
Book Shop - Further reading. Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them. |
|
|
Commercial Software Shop Where I can, I have put links to Amazon for commercial software, not directly related to this site, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them. |
|
|
Can this page be improved? Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page. |
|
|
progam I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here: |
for kdgame programming: http://sourceforge.net/projects/kdgame/ |
This site may have errors. Don't use for critical systems.
Copyright (c) 1998-2008 Martin John Baker - All rights reserved - privacy policy.