PDA

View Full Version : Drawing concave polygons HELP!

fandecine
10-14-2002, 11:11 AM
I have to draw convex and concave polygons. By clicking the mouse, the user adds a point and the polygon updates itself.
How can I do it?
I appreciate your help.
LD

PS: Polygon in 2D

[This message has been edited by fandecine (edited 10-14-2002).]

ToolChest
10-14-2002, 11:48 AM
I would just try to break the poly into tris if that fits into your app.

fandecine
10-14-2002, 11:54 AM
Sorry but I don't know what you mean. How do you do it?

ToolChest
10-14-2002, 12:35 PM
lets say your poly has 5 verts:

v1----v2
| /
| v3
| \
v5----v4

build a method to convert the poly into triangles:

v1----v2
| \ /
| v3
| / \
v5----v4

see what I mean? its still the same shape, only the individual polys are convex no matter the over all shape.

hope this helps...

GRRR... stupid browser!!! my pic is messed up... http://www.opengl.org/discussion_boards/ubb/frown.gif

try this:

v1-v2
\ |
v5|
/ |
v4-v3

v1-v2
\/|
v5|
/\|
v4-v3

[This message has been edited by john_at_kbs_is (edited 10-14-2002).]

ahhhh!!! sorry, for the ghetto pics, I hope that they look good enough to help out... http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by john_at_kbs_is (edited 10-14-2002).]

jwatte
10-14-2002, 12:51 PM
Do a google for "ear clipping" or more general "polygon tesselation".

chief
10-14-2002, 10:48 PM
try this: www.codeproject.com/useritems/polygon_tesselation.asp (http://www.codeproject.com/useritems/polygon_tesselation.asp)

GeLeTo
10-14-2002, 10:55 PM
Or render the polygon into the stencil buffer first as a triangle fan (don't wory about the tessalation) with a StencilMask of 1 and GL_INVERT StencilOp then draw the bounding rectangle of the polygon using GL_EQUAL,1 StencilFunc. This will not be teribly efficient with lots of independent shapes because you have to clear the stencil each time, but it's perfect for complex shapes (text for instance, this approach will take care of the holes and you can draw the whole text at once). Also if you're clever with the StencilMask you can draw up to 8(or whatever the number of stencil bits avaiable) shapes before clearing the stencil.