Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problems with drawing several objects

Started by jjohn Jul 5, 2006 at 12:47 PM 1 replies 600+ views
Original Post
jjohn
jjohn
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:

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();			



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
Palidine
Palidine
looks like integer division assuming that getY() and such return integers. this statement:

(float)getY()/1000

will truncate the result of the division of getY()/1000 (i.e. no decimal places) and THEN cast that result to a float. what you want for float div is:

((float)getY()) / 1000.0f;

note: the extra parens.

you have the same problem on every line where you are doing division.

-me
jjohn
jjohn
Holy crap! what a rookie mistake!
Must be my complete inexperience with graphics-programming.

Anyway, you are now the hero of the day.

Thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.