예제 #1
0
bool LoadingLayer::init()
{
    if(!LayerColor::init())
        return false;
    
    //Set the background color
    LoadingLayer::setColor(Color3B::WHITE);
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    Vec2 centerPoint = Utils::Utils::getCentralPoint(visibleSize, origin);
    
    //Load a planet sprite to show while the game loads
    Sprite3D* sprPlanet = Sprite3D::create("3d/meshes/MarsPlanet.obj", "3d/textures/MarsMap.jpg");
    sprPlanet->setPosition(centerPoint);
    Utils::Utils::setScale3D(10, sprPlanet);
    sprPlanet->runAction(RepeatForever::create(RotateBy::create(3,Vec3(0,360,0))));
    
    //Load the sprite with "LOADING..." string while the game loads
    Text* loadingText = Text::create("LOADING...", DEFAULT_FONT, 34);
    loadingText->setPosition(Vec2(sprPlanet->getPositionX(), SCREEN_FRAME_OFFSET));
    
    //Add elements as layer children
    addChild(sprPlanet);
    addChild(loadingText);
    
    return true;
}
예제 #2
0
Sprite3D *MySprite3DFactory::create(cocos2d::MySpriteType type)
{
    
    Sprite3D *sp = Sprite3D::create(m_ModelFilesOfType[type]);
    if(sp)
    {
        sp->setAnchorPoint(Vec2(0, 1));
        sp->runAction(getAction(type));
    }
    return sp;
}
예제 #3
0
void WTest3D::showSprite3D()
{
	//the assets are from the OpenVR demo
	//get the visible size.
	Size size = Director::getInstance()->getVisibleSize();
	float zeye = Director::getInstance()->getZEye();
	Vec3 eye(size.width / 2, size.height / 2.0f, zeye),
		center(size.width / 2, size.height / 2, 0.0f),
		up(0.0f, 1.0f, 0.0f);
	_camera = Camera::createPerspective(60, size.width / size.height, 100, 3000);// zeye + size.height / 2.0f);
	_camera->setCameraFlag(CameraFlag::USER1);
	//_camera->setPosition3D(Vec3(0, 25, 15));
	_camera->setPosition3D(eye + Vec3(0, 60, 10));
	//_camera->lookAt(center, up);
	//_camera->setRotation3D(Vec3(-35, 0, 0));
	//auto LightMapScene = Sprite3D::create("Sprite3DTest/boss1.obj");
	//LightMapScene->setTexture("Sprite3DTest/boss.png");
	//auto LightMapScene = Sprite3D::create("Sprite3DTest/aaaa.c3b");
	addChild(_camera);
	setCameraMask(2);

	std::string fileName = "Sprite3DTest/orc.c3b";
	//std::string fileName = "Sprite3DTest/cccc.c3b";
	for (int i = 0; i < 14; ++i)
	{
		auto LightMapScene = Sprite3D::create(fileName);
		LightMapScene->setScale(8);
		addChild(LightMapScene, 100 + i, 100 + i);

		LightMapScene->setRotation3D(Vec3(0, 180, 0));
		auto sc = LightMapScene->getScale();
		auto sz = LightMapScene->getContentSize();
		auto curY = _terrain->getHeight(Vec2(250 + i*(sc*sz.width - 150), 10));
		LightMapScene->setPosition3D(Vec3(250 + i*(sc*sz.width - 150), curY, 10));
	}

	for (int i = 0; i < 14; ++i)
	{
		auto LightMapScene = Sprite3D::create(fileName);
		LightMapScene->setScale(8);
		addChild(LightMapScene, 200 + i, 200 + i);

		LightMapScene->setRotation3D(Vec3(0, 0, 0));
		auto sc = LightMapScene->getScale();
		auto sz = LightMapScene->getContentSize();
		auto curY = _terrain->getHeight(Vec2(250 + i*(sc*sz.width - 150), -1500));
		LightMapScene->setPosition3D(Vec3(250 + i*(sc*sz.width - 150), curY, -1500));
	}

	for (int i = 0; i < 14; ++i)
	{
		auto LightMapScene = Sprite3D::create(fileName);
		LightMapScene->setScale(8);
		addChild(LightMapScene, 300 + i, 300 + i);

		LightMapScene->setRotation3D(Vec3(0, 90, 0));
		auto sc = LightMapScene->getScale();
		auto sz = LightMapScene->getContentSize();
		auto curY = _terrain->getHeight(Vec2(20, -400 - i * 80));
		LightMapScene->setPosition3D(Vec3(20, curY, -400 - i * 80));
	}

	for (int i = 0; i < 14; ++i)
	{
		auto LightMapScene = Sprite3D::create(fileName);
		LightMapScene->setScale(8);
		addChild(LightMapScene, 400 + i, 400 + i);

		LightMapScene->setRotation3D(Vec3(0, 270, 0));
		auto sc = LightMapScene->getScale();
		auto sz = LightMapScene->getContentSize();
		auto curY = _terrain->getHeight(Vec2(1200, -400 - i * 80));
		LightMapScene->setPosition3D(Vec3(1200, curY, -400 - i * 80));
	}

	//for (int i = 0; i < 10; ++i)
	//{
	//	auto LightMapScene = Sprite3D::create(fileName);
	//	LightMapScene->setScale(8);
	//	addChild(LightMapScene, i, i);

	//	LightMapScene->setRotation3D(Vec3(90, 180, 0));
	//	auto sc = LightMapScene->getScale();
	//	auto sz = LightMapScene->getContentSize();
	//	CCLOG("getContentSize().width = %f, getContentSize().height = %f",
	//		getContentSize().width, getContentSize().height);
	//	LightMapScene->setPosition3D(Vec3(200 + i*(sc*sz.width - 150), 100, -300));
	//}

	Sprite3D* temp = (Sprite3D*)getChildByTag(100 + 13);
	CCLOG("getPositionX() = %f, getPositionY() = %f, getPositionZ = %f",
		temp->getPositionX(), temp->getPositionY(), temp->getPositionZ());
	CCLOG("getScaleX() = %f, getScaleX() = %f, getScaleZ = %f",
		temp->getScaleX(), temp->getScaleY(), temp->getScaleZ());
	CCLOG("getContentSize().width = %f, getContentSize().height = %f",
		temp->getContentSize().width, temp->getContentSize().height);
	CCLOG("getAnchorPoint().x = %f, getAnchorPoint().y = %f",
		temp->getAnchorPoint().x, temp->getAnchorPoint().y);

	//actions
	temp->runAction(Sequence::create(
		DelayTime::create(2),
		CCMoveBy::create(0.5, Vec3(0, 100, 0)),
		CCMoveTo::create(1, Vec3(500, _terrain->getHeight(500, -500), -500)),
		nullptr));
	temp->runAction(Sequence::create(
		DelayTime::create(2.5),
		CCRotateBy::create(1, Vec3(90, 0, 0)),
		nullptr));

	// actions
	_camera->runAction(Sequence::create(
		DelayTime::create(5),
		MoveBy::create(3, Vec3(0, 0, -1300)),
		CallFunc::create([=](){
		for (int i = 0; i < 14; ++i)
		{
			Sprite3D* temp = (Sprite3D*)getChildByTag(200 + i);
			temp->runAction(Sequence::create(
				RotateTo::create(0.5, Vec3(90, 0, 0)),
				nullptr));
		}
	}),
		nullptr));
}