Original Post
Hello, Im writing an application that renders serveral 3d-rectangles in a space. All the rectangels have the attributes: width, height, length, x, y and z. The problem I have is that some rectangles seems to be drawn partially inside others, this occurs eventhough I've confirmed that the coordinates and dimensions for the rectangles are correct (that is, not overlapping each other) The code for painting each rectangle looks like this: Of course the rectangles are specified in millimeters (they are ~1000-3000 on each dimension) I thought it was a good idea to simply divide all coordinates and dimensions with 1000. Also, the "_zoom" variable is -15.0f. It would be much appreciated if somebody could point out where the flaw is, because in all sense I believe this should work. Regards, John
void GLPacket::render() const
{
double w = (double)getWidth()/1000;
double l = (double)getLength()/1000;
double h = (double)getHeight()/1000;
glPushMatrix();
glTranslatef( (float)getX()/1000, (float)getY()/1000, (float)(getZ()/1000)+_zoom );
glColor3f( (float)_colour.r/255, (float)_colour.g/255, (float)_colour.b/255 );
glBegin(GL_QUADS);
//Top
glNormal3d( 0.0f, 0.0f, 1.0f);
glVertex3d( w, h, 0.0f ); // Top Right (Top)
glVertex3d( 0.0f, h, 0.0f ); // Top Left (Top)
glVertex3d( 0.0f, h, l ); // Bottom Left (Top)
glVertex3d( w, h, l ); // Bottom Right (Top)
//Bottom
glVertex3d( w, 0.0f, 0.0f ); // Top Right (Bottom)
glVertex3d( 0.0f, 0.0f, 0.0f ); // Top Left (Bottom)
glVertex3d( 0.0f, 0.0f, l ); // Bottom Left (Bottom)
glVertex3d( w, 0.0f, l ); // Bottom Right (Bottom)
//Front
glVertex3d( w, h, l ); // Top Right (Front)
glVertex3d( 0.0f, h, l ); // Top Left (Front)
glVertex3d( 0.0f, 0.0f, l ); // Bottom Left (Front)
glVertex3d( w, 0.0f, l ); // Bottom Right (Front)
//Back
glVertex3d( w, h, 0.0f ); // Top Right (Back)
glVertex3d( 0.0f, h, 0.0f ); // Top Left (Back)
glVertex3d( 0.0f, 0.0f, 0.0f ); // Bottom Left (Back)
glVertex3d( w, 0.0f, 0.0f ); // Bottom Right (Back)
//Left
glVertex3d( 0.0f, h, 0.0f ); // Top Right (Left)
glVertex3d( 0.0f, h, l ); // Top Left (Left)
glVertex3d( 0.0f, 0.0f, l ); // Bottom Left (Left)
glVertex3d( 0.0f, 0.0f, 0.0f ); // Bottom Right (Left)
//Right
glVertex3d( w, h, 0.0f ); // Top Right Of The Quad (Right)
glVertex3d( w, h, l ); // Top Left Of The Quad (Right)
glVertex3d( w, 0.0f, l ); // Bottom Left Of The Quad (Right)
glVertex3d( w, 0.0f, 0.0f ); // Bottom Right Of The Quad (Right)
glEnd();
glPopMatrix();