From 414115690e3f4b286540f7467c9f34fcbefde473 Mon Sep 17 00:00:00 2001 From: Nite Luo Date: Fri, 16 Jan 2015 00:04:26 -0800 Subject: [PATCH 1/2] Create rotation test case for billboard --- .../Classes/BillBoardTest/BillBoardTest.cpp | 66 +++++++++++++++++++ .../Classes/BillBoardTest/BillBoardTest.h | 12 +++- .../Classes/Camera3DTest/Camera3DTest.cpp | 9 +-- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp index a7462ba2c7..bd6d50f9f2 100644 --- a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp +++ b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp @@ -41,6 +41,7 @@ static int sceneIdx = -1; static std::function createFunctions[] = { + CL(BillBoardRotationTest), CL(BillBoardTest) }; @@ -72,6 +73,71 @@ static Layer* restartSpriteTestAction() return layer; } +//------------------------------------------------------------------ +// +// Billboard Rotation Test +// +//------------------------------------------------------------------ +BillBoardRotationTest::BillBoardRotationTest() +{ + auto root = Sprite3D::create(); + root->setNormalizedPosition(Vec2(.5,.25)); + addChild(root); + + auto model = Sprite3D::create("Sprite3DTest/orc.c3b"); + model->setScale(5); + model->setRotation3D(Vec3(0,180,0)); + root->addChild(model); + + auto bill = BillBoard::create(); + bill->setPosition(0, 120); + root->addChild(bill); + + auto sp = Sprite::create("Images/SpookyPeas.png"); + sp->setScale(2); + bill->addChild(sp); + + auto lbl = Label::create(); + lbl->setPosition(0, 30); + lbl->setString("+100"); + bill->addChild(lbl); + + auto jump = JumpBy::create(1, Vec2(0, 0), 30, 1); + auto scale = ScaleBy::create(2, 2, 2, 0.1); + auto seq = Sequence::create(jump,scale, NULL); + + auto rot = RotateBy::create(2, Vec3(-90, 0, 0)); + auto act = Spawn::create(seq, rot,NULL); + + auto scale2 = scale->reverse(); + auto rot2 = rot->reverse(); + auto act2 = Spawn::create(scale2, rot2, NULL); + + auto seq2 = Sequence::create(act, act2, NULL); + auto repeat = RepeatForever::create(seq2); + model->runAction(repeat); +} + +BillBoardRotationTest::~BillBoardRotationTest() +{ + +} + +std::string BillBoardRotationTest::title() const +{ + return "Rotation Test"; +} + +std::string BillBoardRotationTest::subtitle() const +{ + return "All the sprites should still facing camera"; +} + +//------------------------------------------------------------------ +// +// Billboard Rendering Test +// +//------------------------------------------------------------------ BillBoardTest::BillBoardTest() : _camera(nullptr) { diff --git a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.h b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.h index a2203b850d..3bbf65ae28 100644 --- a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.h +++ b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.h @@ -34,7 +34,17 @@ namespace cocos2d { class Camera; } - +class BillBoardRotationTest : public BaseTest +{ +public: + CREATE_FUNC(BillBoardRotationTest); + BillBoardRotationTest(); + virtual ~BillBoardRotationTest(void); + virtual std::string title() const override; + virtual std::string subtitle() const override; + +protected: +}; class BillBoardTest : public BaseTest { diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 7541a3565e..6c5e9dc172 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -130,6 +130,7 @@ CameraRotationTest::CameraRotationTest() auto sp3d = Sprite3D::create(); sp3d->setPosition(s.width/2, s.height/2); + sp3d->setRotation3D(Vec3(90,90,0)); addChild(sp3d); auto lship = Label::create(); @@ -140,10 +141,10 @@ CameraRotationTest::CameraRotationTest() //Billboards //Yellow is at the back bill1 = BillBoard::create("Images/Icon.png"); - bill1->setPosition3D(Vec3(s.width/2 + 50, s.height/2 + 10, -10)); + bill1->setPosition3D(Vec3(50, 10, -10)); bill1->setColor(Color3B::YELLOW); bill1->setScale(0.6f); - addChild(bill1); + sp3d->addChild(bill1); l1 = Label::create(); l1->setPosition(Vec2(0,-10)); @@ -157,9 +158,9 @@ CameraRotationTest::CameraRotationTest() bill1->addChild(p1); bill2 = BillBoard::create("Images/Icon.png"); - bill2->setPosition3D(Vec3(s.width/2 - 50, s.height/2 - 10, 10)); + bill2->setPosition3D(Vec3(-50, -10, 10)); bill2->setScale(0.6f); - addChild(bill2); + sp3d->addChild(bill2); l2 = Label::create(); l2->setString("Billboard2"); From 796720e4fd4881765a0bb2563fddad7949b4ee86 Mon Sep 17 00:00:00 2001 From: Nite Luo Date: Fri, 16 Jan 2015 00:14:24 -0800 Subject: [PATCH 2/2] Rotate root node --- tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp index bd6d50f9f2..d33b7a6fc8 100644 --- a/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp +++ b/tests/cpp-tests/Classes/BillBoardTest/BillBoardTest.cpp @@ -102,6 +102,10 @@ BillBoardRotationTest::BillBoardRotationTest() lbl->setString("+100"); bill->addChild(lbl); + auto r = RotateBy::create(10, Vec3(0,360,0)); + auto rp = RepeatForever::create(r); + root->runAction(rp); + auto jump = JumpBy::create(1, Vec2(0, 0), 30, 1); auto scale = ScaleBy::create(2, 2, 2, 0.1); auto seq = Sequence::create(jump,scale, NULL);