2015-02-19 16:18:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CocosStudio3DTest.h"
|
|
|
|
#include "cocostudio/CocoStudio.h"
|
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2015-02-19 16:18:54 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
IDC_NEXT = 100,
|
|
|
|
IDC_BACK,
|
|
|
|
IDC_RESTART
|
|
|
|
};
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
CocosStudio3DTests::CocosStudio3DTests()
|
2015-02-19 16:18:54 +08:00
|
|
|
{
|
2015-08-07 11:36:04 +08:00
|
|
|
FileUtils::getInstance()->addSearchPath("ccs-res/CocosStudio3DTest");
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(CSNode3DTest);
|
|
|
|
ADD_TEST_CASE(CSSprite3DTest);
|
|
|
|
ADD_TEST_CASE(CSUserCameraTest);
|
|
|
|
ADD_TEST_CASE(CSParticle3DTest);
|
2015-07-09 10:19:07 +08:00
|
|
|
ADD_TEST_CASE(CSSceneSkyBoxTest);
|
2015-02-19 16:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// CocosStudio3DTestDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
CocosStudio3DTestDemo::CocosStudio3DTestDemo(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CocosStudio3DTestDemo::~CocosStudio3DTestDemo(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CocosStudio3DTestDemo::title() const
|
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
2015-03-31 11:22:34 +08:00
|
|
|
void CocosStudio3DTestDemo::onExit()
|
|
|
|
{
|
2015-03-31 19:55:56 +08:00
|
|
|
cocostudio::destroyCocosStudio();
|
2015-04-03 14:31:03 +08:00
|
|
|
TestCase::onExit();
|
2015-02-19 16:18:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// CSNode3DTestTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
CSNode3DTest::CSNode3DTest()
|
|
|
|
{
|
2015-07-09 10:19:07 +08:00
|
|
|
auto node = CSLoader::createNode("Node3D.csb");
|
2015-02-19 16:18:54 +08:00
|
|
|
|
2015-06-24 14:58:14 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
auto label = Label::create();
|
|
|
|
label->setString(std::string("Function demo, no content to show"));
|
|
|
|
label->setPosition(size.width / 2, size.height / 2);
|
|
|
|
label->setTextColor(Color4B::ORANGE);
|
|
|
|
node->addChild(label);
|
|
|
|
|
2015-02-19 16:18:54 +08:00
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSNode3DTest::title() const
|
|
|
|
{
|
2015-02-23 00:34:30 +08:00
|
|
|
return "Node3DReader Test";
|
2015-02-19 16:18:54 +08:00
|
|
|
}
|
|
|
|
|
2015-02-23 00:34:30 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// CSSprite3DTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
CSSprite3DTest::CSSprite3DTest()
|
|
|
|
{
|
2015-07-09 10:19:07 +08:00
|
|
|
auto node = CSLoader::createNode("Sprite3D.csb");
|
2015-02-23 00:34:30 +08:00
|
|
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
auto sprite3D = node->getChildByTag(8);
|
|
|
|
|
|
|
|
sprite3D->setPosition(size.width / 2, size.height / 2 - 50);
|
|
|
|
sprite3D->setColor(Color3B::WHITE);
|
|
|
|
sprite3D->setOpacity(255);
|
|
|
|
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSSprite3DTest::title() const
|
|
|
|
{
|
|
|
|
return "Sprite3DReader Test";
|
|
|
|
}
|
|
|
|
|
2015-02-25 14:19:08 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// CSUserCameraTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
CSUserCameraTest::CSUserCameraTest()
|
|
|
|
{
|
2015-07-09 10:19:07 +08:00
|
|
|
auto node = CSLoader::createNode("UserCamera.csb");
|
2015-02-25 14:19:08 +08:00
|
|
|
|
2015-07-09 10:19:07 +08:00
|
|
|
auto sprite3D = Sprite3D::create("dragon/dragon.c3b");
|
2015-02-25 14:19:08 +08:00
|
|
|
sprite3D->setPosition3D(Vec3(100, 95, 80));
|
|
|
|
sprite3D->setCameraMask((unsigned int)CameraFlag::USER1);
|
|
|
|
|
|
|
|
addChild(node);
|
|
|
|
addChild(sprite3D);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSUserCameraTest::title() const
|
|
|
|
{
|
|
|
|
return "UserCameraReader Test";
|
|
|
|
}
|
|
|
|
|
2015-02-26 09:19:14 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// CSParticle3DTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
CSParticle3DTest::CSParticle3DTest()
|
|
|
|
{
|
2015-07-09 10:19:07 +08:00
|
|
|
auto node = CSLoader::createNode("Particle3D.csb");
|
2015-02-26 09:19:14 +08:00
|
|
|
|
|
|
|
addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSParticle3DTest::title() const
|
|
|
|
{
|
|
|
|
return "Particle3DReader Test";
|
|
|
|
}
|
2015-07-09 10:19:07 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// CSSceneSkyBoxTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
CSSceneSkyBoxTest::CSSceneSkyBoxTest()
|
|
|
|
{
|
|
|
|
auto node = CSLoader::createNode("SkyBox.csb");
|
|
|
|
|
|
|
|
addChild(node);
|
|
|
|
|
|
|
|
_camera = static_cast<Camera*>(node->getChildByName("UserCamera_0"));
|
|
|
|
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(CSSceneSkyBoxTest::onTouchesMoved, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSSceneSkyBoxTest::title() const
|
|
|
|
{
|
|
|
|
return "CocosStudio SkyBox Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSceneSkyBoxTest::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event)
|
|
|
|
{
|
|
|
|
if (touches.size())
|
|
|
|
{
|
|
|
|
auto touch = touches[0];
|
|
|
|
auto delta = touch->getDelta();
|
|
|
|
|
|
|
|
static float _angle = 0.f;
|
|
|
|
_angle -= CC_DEGREES_TO_RADIANS(delta.x);
|
|
|
|
_camera->setPosition3D(Vec3(50.0f * sinf(_angle), 0.0f, 50.0f * cosf(_angle)));
|
|
|
|
_camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
|
|
|
|
}
|
|
|
|
}
|