Archived

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

Functor

Is This Not Permitted???

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 this post


Link to post
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;

(multiply instead of divide!)
also, you should be using GL_TRIANGLE_FAN instead of GL_TRIANGLE_STRIP

hope that helps

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

Share this post


Link to post
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.//
miscellaneous links

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

Share this post


Link to post
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 this post


Link to post
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.//
miscellaneous links

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

Share this post


Link to post
Share on other sites