Public Group

# [OpelGL] transformations

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

## Recommended Posts

Guys i am going in crazy. Part 1 say me if i am wrong: by default the camera points in the negative z direction, centered in the origin and has an up vector (0,1,0). If i dont touch the MODELVIEW matrix (basicaly i just reset it to the identity one) and i draw a sphere with glut*Sphere this sphere will be centered in the origin right? Now if i use pyramid projection (using gluPerspective) with the near plane distance to zero i should have a pyramid parallel to the z axe with the peak in the origin. Since just half sphere will be in the volume i will see half sphere (depending on the angle passed to gluPerspective but i will see something by sure). This is ok. pert 2 Now let's go to the other projection, the orthographic one. There is an example in the red book (chapter 5 example 5.1) about a lit sphere. The problem is not the light. My question is: there is no trasformation and it draws a whole sphere. My question is: if the camera is in (0,0,0) and points to z-negative axe and i draw a sphere always in (0,0,0) how can i see the whole sphere? The example doesnt move the camera and doesnt translate the sphere far away to be visible. There is something i am missing i am sure. So i tought that what i am not understanding is the glOrtho projection. I am reading the main difference between the 2 projections are the near and far planes wich have to positive for the pyramid and can be + or - for the "box". Now, i.e., what's the clue in having the near plane behind the camera? What's the effect? This is really a basic question but i have to understand since i am having some problem with the next chapters. If u can help me do it i am in pain. bye guys thanks

##### Share on other sites
ok let me post the example

#include <GL/gl.h>#include <GL/glu.h>#include <GL/glut.h>void init(void) {   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };   GLfloat mat_shininess[] = { 50.0 };   GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };   glClearColor (0.0, 0.0, 0.0, 0.0);   glShadeModel (GL_SMOOTH);   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);   glLightfv(GL_LIGHT0, GL_POSITION, light_position);   glEnable(GL_LIGHTING);   glEnable(GL_LIGHT0);   glEnable(GL_DEPTH_TEST);}void display(void){   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   glutSolidSphere (1.0, 20, 16);   glFlush ();}void reshape (int w, int h){   glViewport (0, 0, (GLsizei) w, (GLsizei) h);   glMatrixMode (GL_PROJECTION);   glLoadIdentity();   if (w <= h)      glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,         1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);   else      glOrtho (-1.5*(GLfloat)w/(GLfloat)h,         1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();}int main(int argc, char** argv){   glutInit(&argc, argv);   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);   glutInitWindowSize (500, 500);    glutInitWindowPosition (100, 100);   glutCreateWindow (argv[0]);   init ();   glutDisplayFunc(display);    glutReshapeFunc(reshape);   glutMainLoop();   return 0;}

Asu can see the only transf. is the call to glLoadIdentity().
if the camera is in (0,0,0) and points to z-negative axe and i draw a sphere always in (0,0,0) how can i see the whole sphere?

kiss

##### Share on other sites
Thinking in terms of a camera helps to understand transformation. But the truth is, in OpenGL, there is no camera. There is an origin and global axes, you draw you objects in this coordinate system, and the view volume "slices" a part of the entire coordinate system and projects onto the viewport.

The kind of confusion you have on the orthographic projection showing the whole sphere is a result of thinking in terms of a camera. In orthographic projection, it doesn't make any sense to talk about a camera at all, or a viewpoint, or anything along those lines.

In perspective projection this is OK, as there is a single point of projection everything is projected towards. Just as in real life, with a camera, or your eyes, there is a point of projection (the focal point in the camera or in your eyes).

In orthographic projection, there is no such focal point. To answer your question directly; the whole sphere is visible because it is entirely within the view volume defined by glOrtho. So you may argue something along the lines; "what about the half-sphere behind the camera located at the origin?". There is an origin, and half the sphere is indeed "behind" that origin. But that origin is in no way a focal point that can be described in terms of a camera, so you cannot draw any conclusions from such an unexpected result based on that theory.

To get a half-sphere, set the one of the clip planes to zero, which will cut the sphere in half.

##### Share on other sites
You have to translate the camera or the sphere, otherwise the camera will be located at the center of the sphere, no mater where you "look" you'll only "see" the inside of the sphere (not even that if backface culling is on).

try glTranslatef(0,0,-10) after glClear in display().

##### Share on other sites
guys thanks a lot, i feel better :D

I am not the problem, it's the book. Some topics should be really explained better.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633297
• Total Posts
3011247
• ### Who's Online (See full list)

There are no registered users currently online

×