PDA

View Full Version : Deformation



Mat
04-29-2002, 08:37 AM
Hi,

I have a problem when I draw a simple G_Squads that is a rectangle.. I know the values are correct because I took exactly as it was in another program working...

But my rectangle are not correctly displayed they look like a parallelogram.. in fact my rectangle is deformed but I checked every visualisation option:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, width/height, 0.001f, 1000000.0f);
glMatrixMode(GL_MODELVIEW);

and I calculated my Z position correctly for seeing all my object..

Do you know from where thi deformation could come ??

Thanks a lot
Mat

nexusone
04-29-2002, 10:45 AM
A square as you rotate it in 3D space with a perspective view will look like a parallelogram. Just like in the real world as you rotate a square, the end closer to you will look larger then the end farther away. Without this you would not have the effect of depth to an object.
Now if you did not want the effect of depth then you could use ortho mode.

Also on your gluPerspective(45.0f, width/height, 0.001f, 1000000.0f);, what is with the large number to super small number. The first one of 0.001 would get the same effect by using 0.0f, if you wanted to go back farther then start using negative numbers. If you drawn your square with a depth of 100000, no wonder it looks like a parallelogram, try starting with something under 100.

example program draws a square at a 45 degree angle, you get the parallelogram effect, which is correct for a 3D view of a rotated object:



#include <GL/glut.h>
#include <stdlib.h>

void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}

}

void init(void)
{
int ix,iy,iz;
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glMatrixMode (GL_MODELVIEW);
}


void reshape (int w, int h)
{
// Window size has changed stuff goes here.
glClearColor (0.0, 0.0, 0.0, 0.0);
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(60.0f, w/h, 0.0f, 10.0f);
glMatrixMode (GL_MODELVIEW);
}

void display(void)
{
//GL drawing stuff here.
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glColor3f(1.0, 1.0, 1.0);
glTranslatef(0.0, 0.0, -5.0);
glRotatef(45, 0.0, 1.0, 0.0);
glBegin(GL_QUADS);
glVertex2f(1,1);
glVertex2f(1,-1);
glVertex2f(-1,-1);
glVertex2f(-1,1);
glVertex2f(1,1);
glEnd();
glPopMatrix();

glutSwapBuffers();
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
glutSetWindowTitle("Glut window");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}




[This message has been edited by nexusone (edited 04-29-2002).]