How to create arcs in OpenGL
Hi,
I would like to find out how could I draw an arc using OpenGL.
I have the position of the arc, the radius, the start angle as well as the sweep range. How could I draw with all this information.
Thanks!
As a sequence of (short) line segments.
Decide how many segments you want to break your arc into.
Use trig (cos,sin) to compute the coordinate of each segment end.
Draw the segments.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
Decide how many segments you want to break your arc into.
Use trig (cos,sin) to compute the coordinate of each segment end.
Draw the segments.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
You can use "evaluators" in OpenGL to draw smooth curves.
Look up glMap1f() and glEvalCoord1() and other related functions.
The most flexible way to handle curves would be NURBs
(Non-Uniform Rational B-Splines).
Look into the GLU library. It has support for drawing
curves and surfaces.
Look up gluNewNurbsRenderer() and other related functions.
Kami no Itte ga ore ni zettai naru!
Look up glMap1f() and glEvalCoord1() and other related functions.
The most flexible way to handle curves would be NURBs
(Non-Uniform Rational B-Splines).
Look into the GLU library. It has support for drawing
curves and surfaces.
Look up gluNewNurbsRenderer() and other related functions.
Kami no Itte ga ore ni zettai naru!
Thanks for the advice. I am really new to OpenGL, is it possible for you to show me in codes on how to use the trig(cos,sin) to do it. I know how to start the coding but I am not sure on how to draw the arc out using the mathematical algorithm
glBegin(GL_LINE_STRIP)
for(...)
{
how to do the trig code here??
}
GLEnd()
glBegin(GL_LINE_STRIP)
for(...)
{
how to do the trig code here??
}
GLEnd()
Kel19,
Take a look at the gluPartialDisk() function for drawing arcs. I think it will do most of the work you are looking for. Dig into the source code for it if you want to learn more about the math.
Here is a link to the reference in case you don''t have the blue book:
http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_RM/sgi_html/ch06.html#id5556583
Remember: Search is your friend!
robo
Take a look at the gluPartialDisk() function for drawing arcs. I think it will do most of the work you are looking for. Dig into the source code for it if you want to learn more about the math.
Here is a link to the reference in case you don''t have the blue book:
http://www.parallab.uib.no/SGI_bookshelves/SGI_Developer/books/OpenGL_RM/sgi_html/ch06.html#id5556583
Remember: Search is your friend!
robo
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement