DrawPoly and Concave

BlitzMax Forums/BlitzMax Beginners Area/DrawPoly and Concave

CASO(Posted 2006) [#1]
Is there a way to draw a concave shape?

Here is the code I am using:
Graphics 400,400,0,0

Global point#[20]

For p=0 To 9
	WaitMouse()
	SetColor(255,255,255)
	Plot MouseX(),MouseY()
	point[p*2]=MouseX()
	point[p*2+1]=MouseY()
	Flip
Next

DrawPoly(point)
Flip

While Not KeyHit(KEY_ESCAPE)
Wend



Perturbatio(Posted 2006) [#2]
Um... correct me if I'm wrong, but the code you posted already does allow concave polys.


CASO(Posted 2006) [#3]
Did you try it?
Whenever I run it and tryu and make a "C" shape with the points I end up with an "O" shape or a backward "D" shape.
FYI: I want it filled


Perturbatio(Posted 2006) [#4]
Did you try it?


yes, that's why I said what I said.


Dreamora(Posted 2006) [#5]
If you want to make a C, make a C.

If you only do the part of C and assume that this then gives a C and no D, its just your wrong understanding of what you actually do.

You have to do ALL the needed points to form a C, not only the outer side of the "C Curve", but as well the inner curve!


CASO(Posted 2006) [#6]
I do make the make the inner curve. I FIGURED IT OUT. It does draw a concave polygon as long as you don't start at on of the endpoints of the "C". I don't know why.


Azathoth(Posted 2006) [#7]
It seems to ignore some of the points and instead of a smooth edge its jagged.


Brendane(Posted 2006) [#8]
The open gl driver uses the GL_POLYGON drawing mode to render the polygon. (ie. BM does not triangulate the polygon for you).

From the opengl redbook :-

"GL_POLYGON
Draws a polygon using the points v0, ... , vn-1 as vertices. n must be at least 3, or nothing is drawn. In addition, the polygon specified must not intersect itself and must be convex. If the vertices don't satisfy these conditions, the results are unpredictable. "

The d3d7 version draws the polygon as a triangle fan - which obviously doesn't supoprt concave shapes.

As you can see DrawPolygon only supports convex shapes. You will either have to find or write your own triangulator if you want concave polys.

Documentation update? (holds breath...)


tonyg(Posted 2006) [#9]
.. but you can draw a concave shape with the code Cal posted. It just depends on which points are posted first. Can't explain it but it *is* possible.


Brendane(Posted 2006) [#10]
It's purely an accident of chance for such a simple C shape and is easily explainable if you imagine a triangle fan. I challenge you to make a letter H though.

Neither the gl nor the d3d version work the same way and neither are made to support concave polys - it should be documented.


tonyg(Posted 2006) [#11]
... wasn't disagreeing as I don't know any better. Just pointing out that you *can* make a concave shape and that I couldn't explain it.
p.s. You *can* make an 'H'ish shape.