Jump to content
  • Advertisement
Sign in to follow this  

Very confused with GL_projection / GL_modelview / camera / objetcts

This topic is 2556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color="#000000"]I have a very big brain confusion:
How affects the :
[color="#000000"] glTranslated
[color="#000000"] glRotatef
depending of the glMatrixMode[color="#000000"] set

glMatrixMode[color="#000000"](GL_MODELVIEW[color="#000000"]);[color="#000000"] [color="#000000"]// [color="#000000"]Select [color="#000000"]The [color="#000000"]Modelview [color="#000000"]Matrix
glMatrixMode[color="#000000"](GL_PROJECTION[color="#000000"]);[color="#000000"] [color="#000000"]// [color="#000000"]Select [color="#000000"]The [color="#000000"]Modelview[color="#000000"] Matrix

I'd want :
1.- Set the position of the camera focus and the ref .
What I have to use ?
[color="#000000"]gluPerspective[color="#000000"](), [color="#000000"] glFrustum , [color="#000000"] gluLookAt[color="#000000"]() ?????
[color="#000000"]2.- Drawing objects
2.1- Using their absolute coordinates
2.2.- Move them before paint.
Now, I can view my objects if they are at 0,0,0 . Using the examples and tutorials founded on the web.
But, I'm unable to draw nothing when I want to use a world whose limits are -1000,-1000,200 1000,1000,300 (x,y,z min x,y,z max ) and simple 2D square defined by -500,500,250 500,500, 250. By moment I' want to place the camara like an airplane (on XY plane ).

Somebody can give me a little lesson ?. Thanks

Share this post

Link to post
Share on other sites
First of all, I strongly advise you read Chapter 3 of the OpenGL Red Book. It has a very detailed explanation on GL transformations. Take specific note that there is no separate 'camera' transformation: it is accumulated in Model/View matrix. Even better, read the whole book :) It's outdated if you search for modern principles and techniques like shaders and tessellation, but the core OpenGL operation is very well documented there.

Simply put, glMatrixMode() selects the current matrix, the one that will be affected by further glTranslate/Rotate/LookAt/whatever calls. Technically, every call to any such function multiplies current matrix with a desired transformation. Therefore, you'd rarely want to call i.e. glTranslate/Rotate with GL_PROJECTION as current matrix (at least until you're being fancy with your projection transformation).

Simple way of things for your desired setup is:

// Select the projection matrix to set up camera 'focus'
glLoadIdentity(); // Clear out any existing transformation
// Set up camera 'focus'
gluPerspective(); // or glFrustum, or glOrtho, or glLoadMatrix, or glMultMatrix, whatever your setup for projection transformation is

// Done with the projection, everything else is model/view
glLoadIdentity(); // Clear out any existing transformation
// Set up camera position and angle. Note the negative coordinates. See Red Book why this is so.
gluLookAt(-camera.x,-camera.y,-camera.z, where.x, where.y, where.z, camera.upX, camera.upY, camera.upZ);

// Set up objects, for each object repeat this:
glPushMatrix(); // save the 'view' matrix
glTranslatef(object.x,object.y,object.z); // 'move' your object somewhere
// Draw the object however you want, and then:
glPopMatrix(); // restore the 'view' matrix

Take a note that when you set up camera 'focus' through gluPerspective, you should set far clipping plane distance. Setting it with a big number will decrease your Z-buffer precision. There are many techniques to draw objects in a vast world, but this is another topic. To make things simpler for yourself, at least for now while you're getting the hang of things, I'd advise you to rethink your world's dimensions, i.e. scale everything down unit-wise, e.g. 100 or 1000 times. It won't matter for viewing if it's 1, 100 or 1000 when relative dimensions are preserved (e.g. if you had one object 1000x1000 and another 500x500, it'd be exactly the same if you made the first one 10x10 and the second one 5x5, and scaled their coordinates accordingly).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!