#### Archived

This topic is now archived and is closed to further replies.

# Is This Not Permitted???

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

## Recommended Posts

I want to create a flat horizontal circle in the center of my room. I don''t want to go through and specify each vertex by hand. I was hoping this would work, but it does not. Am I doing anything wrong? How can I get this sort of algorithm to work? GLfloat xTemp; GLfloat yTemp; GLfloat count = 50.0; GLfloat currentAngle = 0.0; GLfloat theta = 10.0; GLfloat radius = 44.0; glBegin(GL_TRIANGLE_STRIP); glNormal3f(0.0, 0.0, 1.0); glVertex3f(0.0, 0.0, 73.0); while (currentAngle <= 360.0) { xTemp = cos(currentAngle)/radius; yTemp = sin(currentAngle)/radius; glVertex3f(xTemp, yTemp, 73.0); currentAngle += theta; } glEnd();

##### Share on other sites
You might want to use quadratics. It''s simple. Just find it in NeHe''s tutorials for "disk".

##### Share on other sites
I spotted two problems -
xTemp = cos(currentAngle)/radius;yTemp = sin(currentAngle)/radius;

should probably be
xTemp = cos(currentAngle) * radius;yTemp = sin(currentAngle) * radius;

also, you should be using GL_TRIANGLE_FAN instead of GL_TRIANGLE_STRIP

hope that helps

Enigma
------
...about how we can engage with...

##### Share on other sites
Also, sin and cos expect the angle in radians.

##### Share on other sites

  	const double DTR = 3.141593 / 180;	glTranslatef(0.0f, 0.0f, -5.0f);		glBegin(GL_TRIANGLE_FAN);	glVertex3f(0.0f, 0.0f, 0.0f);	for(int i = 0; i <= 360; i+= 5)		glVertex3f(cos(i*DTR), sin(i*DTR), 0);	glEnd();

Wrote it in 5 minutes. All it takes is a bit of thought.

Later,
ZE.

P.S. you can change the value in the for loop to determine the number of "wedges" you want, which then determines the blockyness of the circle, but also affects speed.

//email me.//zealouselixir software.//msdn.//n00biez.//

[if you have a link proposal, email me.]

##### Share on other sites
ZE: why not using glVertex2f ?
Answer: because it''s a five-minute code !

and BTW, just in case someone didn''t see it : "DTR" stands for "Degree To Radian".

##### Share on other sites
quote:
Original post by vincoof
ZE: why not using glVertex2f ?
Answer: because it''s a five-minute code !

and BTW, just in case someone didn''t see it : "DTR" stands for "Degree To Radian".

Why not write look-up tables? Why not tell him how to change the radius?

Because it''s 5 minute code, that''s exactly right. My responsibility is to tell you how to do it. It''s your job to figure out the best way for your circumstances.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//

[if you have a link proposal, email me.]

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 10
• 11
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632651
• Total Posts
3007657
• ### Who's Online (See full list)

There are no registered users currently online

×