From f41f00fcb255986cf17fadb9f59d682126508907 Mon Sep 17 00:00:00 2001 From: huangshiwu Date: Wed, 7 Jan 2015 11:44:16 +0800 Subject: [PATCH] make rotated rect draw correctly --- cocos/2d/CCDrawNode.cpp | 7 +++++-- cocos/2d/CCDrawNode.h | 2 +- .../Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 9073bfdc81..e9d04b546d 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -663,9 +663,12 @@ void DrawNode::drawDot(const Vec2 &pos, float radius, const Color4F &color) _dirty = true; } -void DrawNode::drawRect(const Vec2 &lb, const Vec2 <, const Vec2 &rt, const Vec2& rb, const Color4F &color) +void DrawNode::drawRect(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, const Vec2& p4, const Color4F &color) { - drawRect(lb, rt, color); + drawLine(Vec2(p1.x, p1.y), Vec2(p2.x, p2.y), color); + drawLine(Vec2(p2.x, p2.y), Vec2(p3.x, p3.y), color); + drawLine(Vec2(p3.x, p3.y), Vec2(p4.x, p4.y), color); + drawLine(Vec2(p4.x, p4.y), Vec2(p1.x, p1.y), color); } void DrawNode::drawSegment(const Vec2 &from, const Vec2 &to, float radius, const Color4F &color) diff --git a/cocos/2d/CCDrawNode.h b/cocos/2d/CCDrawNode.h index aafc1131e7..c9257973e3 100644 --- a/cocos/2d/CCDrawNode.h +++ b/cocos/2d/CCDrawNode.h @@ -80,7 +80,7 @@ public: /** draw a dot at a position, with a given radius and color */ void drawDot(const Vec2 &pos, float radius, const Color4F &color); - void drawRect(const Vec2 &lb, const Vec2 <, const Vec2 &rt, const Vec2& rb, const Color4F &color); + void drawRect(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, const Vec2& p4, const Color4F &color); void drawSolidRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color); diff --git a/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index b213915745..ac4b574157 100644 --- a/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/tests/cpp-tests/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -278,6 +278,8 @@ DrawNodeTest::DrawNodeTest() // draw a rectangle draw->drawRect(Vec2(23,23), Vec2(7,7), Color4F(1,1,0,1)); + draw->drawRect(Vec2(15,30), Vec2(30,15), Vec2(15,0), Vec2(0,15), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1)); + // draw a circle draw->drawCircle(VisibleRect::center() + Vec2(140,0), 100, CC_DEGREES_TO_RADIANS(90), 50, true, 1.0f, 2.0f, Color4F(1.0, 0.0, 0.0, 0.5));