Jump to content
  • Advertisement
Sign in to follow this  
Kewley

OpenGL Co-ordinate System

This topic is 3738 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

Hi, I'm having a bit of trouble with the co-ordinate system in OpenGL. I thought I had a good enough understanding to draw some basic shapes, but my code isn't working right and I don't know why. It's a pong clone, the paddles display fine, but the ball doesn't (doesn't appear). I've just copied the important bits Thanks in advance.
...float P1Height = 1.0; 
float P2Height = 1.0; 
	
float BCenter = 0.0f;
float P1Center = 0.0f;
float P2Center = 0.0f;
	
float BRadius = 1.0f;

float PaddleSpeed = 0.1f;
float BSpeed = 0.2f;...

...glBegin(GL_QUADS); //draw ball/paddles

	//Player One - left side
	glVertex3f( -6.5f, P1Center + P1Height, -10.0f);		// Top Left
	glVertex3f( -6.2f, P1Center + P1Height, -10.0f);		// Top Right
	glVertex3f( -6.2f, P1Center - P1Height, -10.0f);		// Bottom Right
	glVertex3f( -6.5f, P1Center - P1Height, -10.0f);		// Bottom Left

	//Player Two - right side
	glVertex3f( 6.5f, P2Center - P2Height, -10.0f);		// Top Left
	glVertex3f( 6.2f, P2Center - P2Height, -10.0f);		// Top Right
	glVertex3f( 6.2f, P2Center + P2Height, -10.0f);		// Bottom Right
	glVertex3f( 6.5f, P2Center + P2Height, -10.0f);		// Bottom Left

	//Ball - center
	glVertex3f( BCenter - BRadius, BCenter - BRadius, -10.0f);		// Top Left
	glVertex3f( BCenter + BRadius, BCenter + BRadius, -10.0f);		// Top Right
	glVertex3f( BCenter - BRadius, BCenter - BRadius, -10.0f);		// Bottom Right
	glVertex3f( BCenter + BRadius, BCenter + BRadius, -10.0f);		// Bottom Left
	
glEnd(); //End quadrilateral coordinates...
[Edited by - Kewley on March 30, 2008 5:12:32 PM]

Share this post


Link to post
Share on other sites
Advertisement
Check the order of your vertices when drawing the ball. In your code, you're going from the bottom left corner to the top right. Either go clockwise or counter-clockwise around the polygon :)

EDIT: You also appear to be placing vertices in the same place when drawing the ball :s

Share this post


Link to post
Share on other sites
Sorry I've taken a while to reply. I'm having a few problems with my laptop at the moment, and on top of that Visual Studio keep throwing errors at me left, right and center every time I start up an IDE. I'm going to try and fix it all next weekend and then hopefully get back on this. Sorry.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!