Archived

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

Drawing a 2D Circle

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

How would you create a 2D circle (I guess it would be a 3d cilinder with no Z hieght)? How many verticies do you need for it to looks smooth? How do you calculate the coords for the verticies rather than hardcoding? Or, is this generally done with a rectangular panel and a texture with transparency (sort of like a sprite) Direct3D code snippet appreciated. [edited by - -Moxie- on August 26, 2002 1:08:32 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Scheermesje
a perfect circle.


Not realy perfect, because (if you want a bit of performance), you will see the geomitry. A prefect sircle is imposible to do in realtime.

Share this post


Link to post
Share on other sites
A perfect circle is impossible anyways because there would be infinite points

But I guess the same goes for any type of geometry. I don''t know the term for it, but even a line segment is a finite set composed of infinite points. Wierd.

Share this post


Link to post
Share on other sites
Something like this maybe



  
glBegin(GL_LINES);
for(int i = 0; i < accuracy_desired; i+=num_steps)
{
x = cos(i);
y = sin(i);
glVertex2f(x, y);
}
glEnd();


[edited by - xg0blin on August 26, 2002 2:40:48 PM]

Share this post


Link to post
Share on other sites
Or you could use a triangle fan.

    
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0.0,0.0);
for(int i = 0; i < (360 degrees in radians); i+=accuracy) {
x = cos(i);
y = sin(i);
glVertex2f(x, y);
}
glEnd();

A triangle fan will draw a series of triangles, always using the first vertex as listed as the first vertex in each triangle. Like this:
v0,v1,v2
v0,v2,v3
v0,v3,v4
etc....

---
Make it work.
Make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites
Thanks.

Follow up questions:

If you were building a top down board game using Direct3D, let''s take checkers for example, is this the approach you would take?

Or can you make the pieces rectangular and apply a texture that looks like a piece and has the outside part of the circle as transparent?

Which of these approaches is easier to do mouse hit testing on?

Does performance come in to play with such a simple example?

Share this post


Link to post
Share on other sites
So the trade off is hit test accuracy? With a textured rect, you''re limited to hit testing on the rect. And with a circle mesh, you can hit test all the triangles? How difficult would it be to apply a texture, say one that looked like a checker piece with edge detail, to the circle mesh?

Thanks for the help on this.

Share this post


Link to post
Share on other sites
It might be easier to model your pieces. Direct3D has built in support for the .x format, so it is pretty easy to load them.

---
Make it work.
Make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book

Share this post


Link to post
Share on other sites