-
Notifications
You must be signed in to change notification settings - Fork 7.1k
fix concave polygon bug in DrawNode #19641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,28 @@ NS_CC_BEGIN | |
|
||
static const int DEFAULT_LINE_WIDTH = 2; | ||
|
||
class Triangulate | ||
{ | ||
public: | ||
|
||
// triangulate a contour/polygon, places results in STL vector | ||
// as series of triangles. | ||
static V2F_C4B_T2F_Triangle * Process(const Vec2 *verts,V2F_C4B_T2F_Triangle * triangles,int n,const Color4F &fillColor); | ||
|
||
// compute area of a contour/polygon | ||
static float Area(const Vec2 *verts,int n); | ||
|
||
// decide if point Px/Py is inside triangle defined by | ||
// (Ax,Ay) (Bx,By) (Cx,Cy) | ||
static bool InsideTriangle(float Ax, float Ay, | ||
float Bx, float By, | ||
float Cx, float Cy, | ||
float Px, float Py); | ||
|
||
private: | ||
static bool Snip(const Vec2 *verts,int u,int v,int w,int n,int *V); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With cocos2d-x coding style, please use lower case for the first character of the function name, and please use verb for first word, for example
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. I have changed the style in the new commit . |
||
}; | ||
|
||
class PointArray; | ||
/** | ||
* @addtogroup _2d | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,6 +265,10 @@ DrawNodeTest::DrawNodeTest() | |
Vec2 points[] = { Vec2(s.height/4,0), Vec2(s.width,s.height/5), Vec2(s.width/3*2,s.height) }; | ||
draw->drawPolygon(points, sizeof(points)/sizeof(points[0]), Color4F(1,0,0,0.5), 4, Color4F(0,0,1,0.5)); | ||
|
||
// Draw concave polygons | ||
Vec2 concavePoints[] = { Vec2(0,130), Vec2(140,130), Vec2(140,160),Vec2(120,145),Vec2(30,145),Vec2(0,160) }; | ||
draw->drawPolygon(concavePoints, sizeof(concavePoints)/sizeof(concavePoints[0]), Color4F(1,0,0,0.5), 4, Color4F(0,0,1,0.5)); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to add a separate test case, or it is hard to catch the error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok,I added a test class : Issue19641Test in the new commit .And I moved that code into Issue19641Test. |
||
// star poly (triggers buggs) | ||
{ | ||
const float o=80; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to add the url of the codes comes from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The url is http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml.
I wrote the url in the first comment up there. Do you mean that I need write the url into the source code's comment ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, i think it is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've added in the new commit.