Jump to content

  • Log In with Google      Sign In   
  • Create Account


drawing a 2D torus (basically a circle with a hole in it).


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Enerjak   Members   -  Reputation: 229

Like
0Likes
Like

Posted 17 March 2013 - 12:15 AM

I've been trying to render a torus (in 2D) in OpenGL and Well, I think I'm on the right track but I thought I'd ask you how to go about getting it to work. here's the code:

 

// attempting to create a torus (in 2D)
void createRing(double radius,
				double radius2,		
				int numSegments, 
				double x, 
				double y)
{
	double mAngle = 0.0;
	double mAngle2 = 0.0;
	glBegin(GL_POLYGON);
	for(int i = 0; i < numSegments; i++)
	{
		mAngle = i * (2 * 3.14/numSegments);
		mAngle2 = i * (2 * 3.14/numSegments);
		glVertex2d(x + radius * cosf(mAngle), y + radius * sinf(mAngle));
		glVertex2d(x + (radius + radius2 * cosf(mAngle2)) * cosf(mAngle2),
				y + (radius + radius2 * sinf(mAngle2)) * sinf(mAngle2));
	}
		
	glEnd();
}

now here's the polygon this produces:

 

http://puu.sh/2j6uh

 

please let me know if there's anything I need to do to fix this.



Sponsor:

#2 Dragonsoulj   Crossbones+   -  Reputation: 2009

Like
1Likes
Like

Posted 17 March 2013 - 05:55 AM

Looks like you are on the right track for the ring. Does increasing your number of segments give you a smoother looking ring?



#3 C0lumbo   Crossbones+   -  Reputation: 2133

Like
3Likes
Like

Posted 17 March 2013 - 06:49 AM

The shape you're trying to draw is not a convex polygon, so using GL_POLYGON is wrong. I think GL_TRIANGLE_STRIP is a better fit. In switching to a triangle strip you should change the 'for' condition to <=.

 

Also, your second glVertex2d call looks very wrong to me. It should be exactly the same as the first, but using radius2 instead of radius (or (radius + radius2) depending on what you want radius2 to mean).



#4 Enerjak   Members   -  Reputation: 229

Like
1Likes
Like

Posted 17 March 2013 - 09:40 AM

thanks, I can always count on the fine people on this forum! 






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS