Click to See Complete Forum and Search --> : How do i


tech2040
October 15th, 2004, 02:33 PM
I am currently creating a program in OpenGL that is able to display freight packages of varying dimensions within a given area.
However i am having trouble placing the glBegin(GL_QUADS); in the correct locations. so far all of the boxes are being drawn "on top" of each other

this is the code i am currently using:
float x_Pos[] = {0,70, 0, 0,70, 0, 0, 0, 0, 0, 0, 0, 0, 0};
float y_Pos[] = {0, 0, 0, 0, 0, 0,45,45,45,45,75,75,75,75};
float z_Pos[] = {0, 0,24,48,48,72, 0,24,48,72,0,24,48, 72};

float x_Axisl[] = {70,14,70,70,14,70,70,70,70,70,70,70,70,70};
float y_Axisl[] = {45,40,45,45,40,45,30,30,30,29,29,29,29,29};
float z_Axisl[] = {24,48,24,24,48,24,24,24,24,24,24,24,24,24};
for (int i = 0; i <=13; i++)
{
x_Axis = x_Axisl[i]/100;y_Axis = y_Axisl[i]/100;z_Axis = z_Axisl[i]/100;
x_Pos[i]/=100;y_Pos[i]/=100;z_Pos[i]/=100;
m_xScaling = x_Axisl[i]*2; m_yScaling = y_Axisl[i]*2; m_zScaling = z_Axisl[i]*2;
glTranslatef(0.0f,-y_Pos[i],0.0f);
DefineCube();

}


void COpenGLObject::DefineCube()
{

glBegin(GL_QUADS);
// Front Face
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-x_Axis, -y_Axis, z_Axis);
glTexCoord2f(1.0f, 0.0f); glVertex3f( x_Axis, -y_Axis, z_Axis);
glTexCoord2f(1.0f, 1.0f); glVertex3f( x_Axis, y_Axis, z_Axis);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-x_Axis, y_Axis, z_Axis);
// Back Face
glNormal3f( 0.0f, 0.0f,-1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-x_Axis, -y_Axis, -z_Axis);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-x_Axis, y_Axis, -z_Axis);
glTexCoord2f(0.0f, 1.0f); glVertex3f( x_Axis, y_Axis, -z_Axis);
glTexCoord2f(0.0f, 0.0f); glVertex3f( x_Axis, -y_Axis, -z_Axis);
// Top Face
glNormal3f( 0.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-x_Axis, y_Axis, -z_Axis);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-x_Axis, y_Axis, z_Axis);
glTexCoord2f(1.0f, 0.0f); glVertex3f( x_Axis, y_Axis, z_Axis);
glTexCoord2f(1.0f, 1.0f); glVertex3f( x_Axis, y_Axis, -z_Axis);
// Bottom Face
glNormal3f( 0.0f,-1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-x_Axis, -y_Axis, -z_Axis);
glTexCoord2f(0.0f, 1.0f); glVertex3f( x_Axis, -y_Axis, -z_Axis);
glTexCoord2f(0.0f, 0.0f); glVertex3f( x_Axis, -y_Axis, z_Axis);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-x_Axis, -y_Axis, z_Axis);
// Right face
glNormal3f( 1.0f, 0.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( x_Axis, -y_Axis, -z_Axis);
glTexCoord2f(1.0f, 1.0f); glVertex3f( x_Axis, y_Axis, -z_Axis);
glTexCoord2f(0.0f, 1.0f); glVertex3f( x_Axis, y_Axis, z_Axis);
glTexCoord2f(0.0f, 0.0f); glVertex3f( x_Axis, -y_Axis, z_Axis);
// Left Face
glNormal3f(-1.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-x_Axis, -y_Axis, -z_Axis);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-x_Axis, -y_Axis, z_Axis);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-x_Axis, y_Axis, z_Axis);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-x_Axis, y_Axis, -z_Axis);
glEnd();



}


PLEASE TELL ME WHAT I AM DOING WRONG

Philip Nicoletti
October 15th, 2004, 03:19 PM
Maybe you just need to rotate the scene. I'm not sure if it looks
like what you want, but with the following code boxes are not
drawn on top of each other. (Note, I commented out your
translate, I am using glOrtho() you are probably using one
of the perspective transformations:


float xrot = 240.0f;
float yrot = 120.0f;;
float zrot = 40.0f;

float m_xScaling = 1.0f;
float m_yScaling = 1.0f;
float m_zScaling = 1.0f;

glClearColor(0.0f,0.0f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-2,2,-2,2,-2,2);

glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glRotatef(zrot,0.0,0.0,1.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor3f(1.0f,0.0f,0.0f);

float x_Pos[] = {0,70, 0, 0,70, 0, 0, 0, 0, 0, 0, 0, 0, 0};
float y_Pos[] = {0, 0, 0, 0, 0, 0,45,45,45,45,75,75,75,75};
float z_Pos[] = {0, 0,24,48,48,72, 0,24,48,72,0,24,48, 72};

float x_Axisl[] = {70,14,70,70,14,70,70,70,70,70,70,70,70,70};
float y_Axisl[] = {45,40,45,45,40,45,30,30,30,29,29,29,29,29};
float z_Axisl[] = {24,48,24,24,48,24,24,24,24,24,24,24,24,24};
for (int i = 0; i <=13; i++)
{
x_Axis = x_Axisl[i]/100;y_Axis = y_Axisl[i]/100;z_Axis = z_Axisl[i]/100;
x_Pos[i]/=100;y_Pos[i]/=100;z_Pos[i]/=100;
m_xScaling = x_Axisl[i]*2; m_yScaling = y_Axisl[i]*2; m_zScaling = z_Axisl[i]*2;
// glTranslatef(0.0f,-y_Pos[i],0.0f);
DefineCube();

}

Runt888
October 15th, 2004, 06:45 PM
Generally with 3D graphics you define a shape as being drawn a certain way, then perform transforms to it. For example, write a cube class that draws a 1x1x1 cube, centered on the origin. Then before you draw the cube, setup a transform to put it in the correct location (using glTranslate, glRotate, and glScale). Make sure you apply the transforms in the correct order - this is especially important when if you're translating and rotating.

Kelly

tech2040
October 17th, 2004, 10:21 PM
Thanks

Andreas Masur
October 18th, 2004, 02:21 PM
[ Moved thread ]