mirror of https://github.com/axmolengine/axmol.git
Update Issue829Test (DrawPrimitiveTest) (#844)
* Update Issue829Test (DrawPrimitiveTest) * Update DrawPrimitivesTest.cpp * Update DrawPrimitivesTest.cpp
This commit is contained in:
parent
efe9e36816
commit
6038cfb531
|
@ -242,40 +242,89 @@ string Issue11942Test::subtitle() const
|
|||
|
||||
Issue829Test::Issue829Test()
|
||||
{
|
||||
ax::Vec2 vertices[] = {
|
||||
{0, 0},
|
||||
{50.000000000, 20.000000000},
|
||||
{100.000000000, 0.000000},
|
||||
{80.000000000, 50.000000},
|
||||
{100.0000000, 100.0000000},
|
||||
{50.0000000, 80.0000000},
|
||||
{0.000000, 100.000000},
|
||||
{20.000000, 50.000000},
|
||||
{0, 0}};
|
||||
Vec2 vertices0[] = {{50.0, 20.0}, {100.0, 0.0}, {80.0, 50.0}, {100.0, 100.0},
|
||||
{50.0, 80.0}, {0.0, 100.0}, {20.0, 50.0}, {0, 0}};
|
||||
|
||||
Vec2 vertices4[] = {{362, 148}, {326, 241}, {295, 219}, {258, 88}, {440, 129},
|
||||
{370, 196}, {372, 275}, {348, 257}, {364, 148}};
|
||||
|
||||
Vec2* ver[] = {vertices0, vertices4};
|
||||
|
||||
DrawNode* drawNode[sizeof(ver) + 1];
|
||||
for (int i = 0; i < sizeof(ver); i++)
|
||||
{
|
||||
drawNode[i] = DrawNode::create();
|
||||
addChild(drawNode[i]);
|
||||
}
|
||||
|
||||
drawNode[0]->drawPolygon(vertices0, sizeof(vertices0) / sizeof(vertices0[0]), Color4F(0.0f, 0.0f, 0.7f, 0.5f), 3,
|
||||
Color4F(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
drawNode[0]->setPosition({20, 200});
|
||||
drawDirection(vertices0, sizeof(vertices0) / sizeof(vertices0[0]), drawNode[0]->getPosition());
|
||||
|
||||
drawNode[4]->drawPolygon(vertices4, sizeof(vertices4) / sizeof(vertices4[0]), Color4F(0.0f, 0.0f, 0.7f, 0.5f), 3,
|
||||
Color4F(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
drawNode[4]->setPosition({-70, -20});
|
||||
drawDirection(vertices4, sizeof(vertices4) / sizeof(vertices4[0]), drawNode[4]->getPosition());
|
||||
|
||||
{
|
||||
auto drawNode1 = DrawNode::create();
|
||||
drawNode1->drawPoly(vertices, sizeof(vertices) / sizeof(vertices[0]), false, Color4F(1.0f, 1.0f, 1.0f, 1));
|
||||
drawNode1->setPosition(10, 100);
|
||||
addChild(drawNode1);
|
||||
const float o = 80;
|
||||
const float w = 20;
|
||||
const float h = 50;
|
||||
{ // star
|
||||
auto drawNode1 = DrawNode::create();
|
||||
addChild(drawNode1);
|
||||
drawNode1->setPosition(300, 100);
|
||||
Vec2 star[] = {
|
||||
Vec2(o, o),
|
||||
Vec2(o + w, o - h),
|
||||
Vec2(o + w * 2, o), // lower spike
|
||||
Vec2(o + w * 2 + h, o + w),
|
||||
Vec2(o + w * 2, o + w * 2), // right spike
|
||||
Vec2(o + w, o + w * 2 + h),
|
||||
Vec2(o, o + w * 2), // top spike
|
||||
Vec2(o - h, o + w), // left spike
|
||||
};
|
||||
|
||||
drawNode1->drawPolygon(star, sizeof(star) / sizeof(star[0]), Color4F(0.0f, 0.0f, 0.7f, 0.5f), 1,
|
||||
Color4F(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
|
||||
drawDirection(star, sizeof(star) / sizeof(star[0]), drawNode1->getPosition());
|
||||
}
|
||||
|
||||
{ // wrong order
|
||||
auto drawNode1 = DrawNode::create();
|
||||
addChild(drawNode1);
|
||||
drawNode1->setPosition(-80, 20);
|
||||
Vec2 wrongOrder[] = {Vec2(o + w, o - h), Vec2(o + w * 2, o), Vec2(o + w * 2 + h, o + w),
|
||||
Vec2(o + w * 2, o + w * 2)};
|
||||
|
||||
drawNode1->drawPolygon(wrongOrder, sizeof(wrongOrder) / sizeof(wrongOrder[0]),
|
||||
Color4F(0.0f, 0.0f, 0.7f, 0.5f), 1, Color4F(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
||||
drawDirection(wrongOrder, sizeof(wrongOrder) / sizeof(wrongOrder[0]), drawNode1->getPosition());
|
||||
}
|
||||
{ // correct order
|
||||
Vec2 correctOrder[] = {Vec2(o + w * 2, o), Vec2(o + w * 2 + h, o + w), Vec2(o + w * 2, o + w * 2),
|
||||
Vec2(o + w, o - h)};
|
||||
auto drawNode2 = DrawNode::create();
|
||||
addChild(drawNode2);
|
||||
drawNode2->setPosition({-10, 20});
|
||||
drawNode2->drawPolygon(correctOrder, sizeof(correctOrder) / sizeof(correctOrder[0]),
|
||||
Color4F(0.0f, 0.0f, 0.7f, 0.5f), 1, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
|
||||
|
||||
drawDirection(correctOrder, sizeof(correctOrder) / sizeof(correctOrder[0]), drawNode2->getPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Issue829Test::drawDirection(const Vec2* vec, const int size, Vec2 offset)
|
||||
{
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
auto drawNode1_1 = DrawNode::create();
|
||||
drawNode1_1->drawPoly(vertices, sizeof(vertices) / sizeof(vertices[0]), true, Color4F(1.0f, 1.0f, 1.0f, 1));
|
||||
drawNode1_1->setPosition(120, 100);
|
||||
addChild(drawNode1_1);
|
||||
}
|
||||
{
|
||||
auto drawNode2 = DrawNode::create();
|
||||
drawNode2->drawSolidPoly(vertices, sizeof(vertices) / sizeof(vertices[0]), Color4F(1.0f, 1.0f, 1.0f, 1));
|
||||
drawNode2->setPosition(230, 100);
|
||||
addChild(drawNode2);
|
||||
}
|
||||
{
|
||||
auto drawNode3 = DrawNode::create();
|
||||
drawNode3->drawPolygon(vertices, sizeof(vertices) / sizeof(vertices[0]), Color4F(1.0f, 1.0f, 1.0f, 1), 4, Color4F(0.0f, 0.0f, 1.0f, 0.5f));
|
||||
drawNode3->setPosition(350, 100);
|
||||
addChild(drawNode3);
|
||||
auto label = Label::createWithTTF(std::to_string(i).c_str(), "fonts/Marker Felt.ttf", 10);
|
||||
this->addChild(label);
|
||||
label->setPosition(vec[i] + offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,5 +335,5 @@ string Issue829Test::title() const
|
|||
|
||||
string Issue829Test::subtitle() const
|
||||
{
|
||||
return "DrawNode::draw*Poly* draw incorrect geometry";
|
||||
return "Red polygon has wrong order!";
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
CREATE_FUNC(Issue829Test);
|
||||
|
||||
Issue829Test();
|
||||
void drawDirection(const ax::Vec2* vec, const int size, ax::Vec2 offset);
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
|
Loading…
Reference in New Issue