Create rotation test case for billboard

This commit is contained in:
Nite Luo 2015-01-16 00:04:26 -08:00
parent bec21d8e7f
commit 414115690e
3 changed files with 82 additions and 5 deletions

View File

@ -41,6 +41,7 @@ static int sceneIdx = -1;
static std::function<Layer*()> createFunctions[] = static std::function<Layer*()> createFunctions[] =
{ {
CL(BillBoardRotationTest),
CL(BillBoardTest) CL(BillBoardTest)
}; };
@ -72,6 +73,71 @@ static Layer* restartSpriteTestAction()
return layer; 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() BillBoardTest::BillBoardTest()
: _camera(nullptr) : _camera(nullptr)
{ {

View File

@ -34,7 +34,17 @@ namespace cocos2d {
class Camera; 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 class BillBoardTest : public BaseTest
{ {

View File

@ -130,6 +130,7 @@ CameraRotationTest::CameraRotationTest()
auto sp3d = Sprite3D::create(); auto sp3d = Sprite3D::create();
sp3d->setPosition(s.width/2, s.height/2); sp3d->setPosition(s.width/2, s.height/2);
sp3d->setRotation3D(Vec3(90,90,0));
addChild(sp3d); addChild(sp3d);
auto lship = Label::create(); auto lship = Label::create();
@ -140,10 +141,10 @@ CameraRotationTest::CameraRotationTest()
//Billboards //Billboards
//Yellow is at the back //Yellow is at the back
bill1 = BillBoard::create("Images/Icon.png"); 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->setColor(Color3B::YELLOW);
bill1->setScale(0.6f); bill1->setScale(0.6f);
addChild(bill1); sp3d->addChild(bill1);
l1 = Label::create(); l1 = Label::create();
l1->setPosition(Vec2(0,-10)); l1->setPosition(Vec2(0,-10));
@ -157,9 +158,9 @@ CameraRotationTest::CameraRotationTest()
bill1->addChild(p1); bill1->addChild(p1);
bill2 = BillBoard::create("Images/Icon.png"); 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); bill2->setScale(0.6f);
addChild(bill2); sp3d->addChild(bill2);
l2 = Label::create(); l2 = Label::create();
l2->setString("Billboard2"); l2->setString("Billboard2");