29LightTests::LightTests()
35 : _directionalLight(nullptr)
36 , _pointLight(nullptr)
43 auto s = Director::getInstance()->getWinSize();
44 auto camera = Camera::createPerspective(60, (
float)s.width/s.height, 1.0f, 1000.0f);
45 camera->setCameraFlag(CameraFlag::USER1);
46 camera->setPosition3D(Vec3(0.0f, 100.0f, 100.0f));
47 camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
50 TTFConfig ttfConfig(
"fonts/arial.ttf", 15);
63 auto menu = Menu::create(menuItem0, menuItem1, menuItem2, menuItem3,
nullptr);
64 menu->setPosition(Vec2::ZERO);
65 menuItem0->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
67 menuItem1->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
69 menuItem2->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
71 menuItem3->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
108 auto s = Director::getInstance()->getWinSize();
121 std::string fileName =
"Sprite3DTest/orc.c3b";
122 auto sprite = Sprite3D::create(fileName);
123 sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
124 sprite->setPosition(Vec2(0.0f, 0.0f));
125 sprite->setScale(2.0);
126 auto sp = Sprite3D::create(
"Sprite3DTest/axe.c3b");
127 sprite->getAttachNode(
"Bip001 R Hand")->addChild(sp);
128 auto animation = Animation3D::create(fileName);
131 auto animate = Animate3D::create(animation);
132 sprite->runAction(RepeatForever::create(animate));
136 sprite->setCameraMask(2);
140 std::string fileName =
"Sprite3DTest/sphere.c3b";
141 auto sprite = Sprite3D::create(fileName);
142 sprite->setPosition(Vec2(30.0f, 0.0f));
144 sprite->setCameraMask(2);
148 std::string fileName =
"Sprite3DTest/sphere.c3b";
149 auto sprite = Sprite3D::create(fileName);
150 sprite->setScale(0.5f);
151 sprite->setPosition(Vec2(-50.0f, 0.0f));
153 sprite->setCameraMask(2);
157 std::string fileName =
"Sprite3DTest/sphere.c3b";
158 auto sprite = Sprite3D::create(fileName);
159 sprite->setScale(0.5f);
160 sprite->setPosition(Vec2(-30.0f, 10.0f));
162 sprite->setCameraMask(2);
168 auto s = Director::getInstance()->getWinSize();
169 _ambientLight = AmbientLight::create(Color3B(200, 200, 200));
175 _directionalLight = DirectionLight::create(Vec3(-1.0f, -1.0f, 0.0f), Color3B(200, 200, 200));
181 _pointLight = PointLight::create(Vec3(0.0f, 0.0f, 0.0f), Color3B(200, 200, 200), 10000.0f);
187 _spotLight = SpotLight::create(Vec3(-1.0f, -1.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f), Color3B(200, 200, 200), 0.0, 0.5, 10000.0f);
194 auto tintto1 = TintTo::create(4, 0, 0, 255);
195 auto tintto2 = TintTo::create(4, 0, 255, 0);
196 auto tintto3 = TintTo::create(4, 255, 0, 0);
197 auto tintto4 = TintTo::create(4, 255, 255, 255);
198 auto seq = Sequence::create(tintto1,tintto2, tintto3, tintto4,
nullptr);
203 auto tintto1 = TintTo::create(4, 255, 0, 0);
204 auto tintto2 = TintTo::create(4, 0, 255, 0);
205 auto tintto3 = TintTo::create(4, 0, 0, 255);
206 auto tintto4 = TintTo::create(4, 255, 255, 255);
207 auto seq = Sequence::create(tintto1,tintto2, tintto3, tintto4,
nullptr);
212 auto tintto1 = TintTo::create(4, 255, 0, 0);
213 auto tintto2 = TintTo::create(4, 0, 255, 0);
214 auto tintto3 = TintTo::create(4, 0, 0, 255);
215 auto tintto4 = TintTo::create(4, 255, 255, 255);
216 auto seq = Sequence::create(tintto2, tintto1, tintto3, tintto4,
nullptr);
217 _pointLight->runAction(RepeatForever::create(seq));
221 auto tintto1 = TintTo::create(4, 255, 0, 0);
222 auto tintto2 = TintTo::create(4, 0, 255, 0);
223 auto tintto3 = TintTo::create(4, 0, 0, 255);
224 auto tintto4 = TintTo::create(4, 255, 255, 255);
225 auto seq = Sequence::create(tintto3, tintto2, tintto1, tintto4,
nullptr);
226 _spotLight->runAction(RepeatForever::create(seq));
232 static float angleDelta = 0.0;
236 _directionalLight->setRotation3D(Vec3(-45.0, -CC_RADIANS_TO_DEGREES(angleDelta), 0.0f));
241 _pointLight->setPositionX(100.0f * cosf(angleDelta + 2.0 * delta));
243 _pointLight->setPositionZ(100.0f * sinf(angleDelta + 2.0 * delta));
248 _spotLight->setPositionX(100.0f * cosf(angleDelta + 4.0 * delta));
250 _spotLight->setPositionZ(100.0f * sinf(angleDelta + 4.0 * delta));
251 _spotLight->setDirection(-Vec3(cosf(angleDelta + 4.0 * delta), 1.0, sinf(angleDelta + 4.0 * delta)));
256 TestCase::update(delta);
263 case LightType::AMBIENT:
267 sprintf(str,
"Ambient Light %s", isON ==
true?
"ON":
"OFF");
273 case LightType::DIRECTIONAL:
277 sprintf(str,
"Directional Light %s", isON ==
true?
"ON":
"OFF");
283 case LightType::POINT:
287 sprintf(str,
"Point Light %s", isON ==
true?
"ON":
"OFF");
293 case LightType::SPOT:
297 sprintf(str,
"Spot Light %s", isON ==
true?
"ON":
"OFF");
#define ADD_TEST_CASE(__className__)
cocos2d::Label * _pointLightLabel
void SwitchLight(cocos2d::Ref *sender, cocos2d::LightType lightType)
cocos2d::Label * _directionalLightLabel
cocos2d::Label * _spotLightLabel
cocos2d::DirectionLight * _directionalLight
cocos2d::PointLight * _pointLight
cocos2d::Label * _ambientLightLabel
virtual void update(float delta) override
cocos2d::AmbientLight * _ambientLight
cocos2d::SpotLight * _spotLight
virtual std::string title() const override
static cocos2d::Vec2 top()
static cocos2d::Vec2 left()