Jump to content
  • Advertisement
Sign in to follow this  
jjohn

Problems with drawing several objects

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Holy crap! what a rookie mistake!
Must be my complete inexperience with graphics-programming.

Anyway, you are now the hero of the day.

Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!