Is This Not Permitted???

Started by
6 comments, last by Functor 22 years, 1 month ago
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();
Shakedown...
Advertisement
You might want to use quadratics. It''s simple. Just find it in NeHe''s tutorials for "disk".
Check out my website. Also, I am working on my first 3D game. I made PONG in OpenGL and I hope to have it on my site soon! Bye Bye!if(mypost == stupid){ cout << "Ignore me!";}
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...
Also, sin and cos expect the angle in radians.
---visit #directxdev on afternet <- not just for directx, despite the name
Quadrics...not quadratics.

Later,
ZE.

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

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

[twitter]warrenm[/twitter]


  	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.]

[twitter]warrenm[/twitter]

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".
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.]

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement