PuzzleSDK
LightTest类 参考

#include <LightTest.h>

+ 类 LightTest 继承关系图:
+ LightTest 的协作图:

Public 成员函数

 CREATE_FUNC (LightTest)
 
 LightTest ()
 
virtual ~LightTest ()
 
virtual std::string title () const override
 
virtual void update (float delta) override
 
void SwitchLight (cocos2d::Ref *sender, cocos2d::LightType lightType)
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual std::string subtitle () const
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 
virtual void onEnter () override
 

Private 成员函数

void addSprite ()
 
void addLights ()
 

Private 属性

cocos2d::AmbientLight * _ambientLight
 
cocos2d::DirectionLight * _directionalLight
 
cocos2d::PointLight * _pointLight
 
cocos2d::SpotLight * _spotLight
 
cocos2d::Label * _ambientLightLabel
 
cocos2d::Label * _directionalLightLabel
 
cocos2d::Label * _pointLightLabel
 
cocos2d::Label * _spotLightLabel
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

详细描述

在文件 LightTest.h33 行定义.

构造及析构函数说明

◆ LightTest()

LightTest::LightTest ( )

在文件 LightTest.cpp34 行定义.

35 : _directionalLight(nullptr)
36 , _pointLight(nullptr)
37 , _spotLight(nullptr)
38{
39 addSprite();
40 addLights();
41 scheduleUpdate();
42
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));
48 addChild(camera);
49
50 TTFConfig ttfConfig("fonts/arial.ttf", 15);
51 _ambientLightLabel = Label::createWithTTF(ttfConfig,"Ambient Light ON");
52 _ambientLightLabel->retain();
53 auto menuItem0 = MenuItemLabel::create(_ambientLightLabel, CC_CALLBACK_1(LightTest::SwitchLight,this,LightType::AMBIENT));
54 _directionalLightLabel = Label::createWithTTF(ttfConfig,"Directional Light OFF");
55 _directionalLightLabel->retain();
56 auto menuItem1 = MenuItemLabel::create(_directionalLightLabel, CC_CALLBACK_1(LightTest::SwitchLight,this,LightType::DIRECTIONAL));
57 _pointLightLabel = Label::createWithTTF(ttfConfig,"Point Light OFF");
58 _pointLightLabel->retain();
59 auto menuItem2 = MenuItemLabel::create(_pointLightLabel, CC_CALLBACK_1(LightTest::SwitchLight,this,LightType::POINT));
60 _spotLightLabel = Label::createWithTTF(ttfConfig,"Spot Light OFF");
61 _spotLightLabel->retain();
62 auto menuItem3 = MenuItemLabel::create(_spotLightLabel, CC_CALLBACK_1(LightTest::SwitchLight,this,LightType::SPOT));
63 auto menu = Menu::create(menuItem0, menuItem1, menuItem2, menuItem3, nullptr);
64 menu->setPosition(Vec2::ZERO);
65 menuItem0->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
66 menuItem0->setPosition( Vec2(VisibleRect::left().x, VisibleRect::top().y-50) );
67 menuItem1->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
68 menuItem1->setPosition( Vec2(VisibleRect::left().x, VisibleRect::top().y-100) );
69 menuItem2->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
70 menuItem2->setPosition( Vec2(VisibleRect::left().x, VisibleRect::top().y -150));
71 menuItem3->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
72 menuItem3->setPosition( Vec2(VisibleRect::left().x, VisibleRect::top().y -200));
73 addChild(menu);
74}
cocos2d::Label * _pointLightLabel
Definition: LightTest.h:60
void SwitchLight(cocos2d::Ref *sender, cocos2d::LightType lightType)
Definition: LightTest.cpp:259
cocos2d::Label * _directionalLightLabel
Definition: LightTest.h:59
cocos2d::Label * _spotLightLabel
Definition: LightTest.h:61
cocos2d::DirectionLight * _directionalLight
Definition: LightTest.h:54
cocos2d::PointLight * _pointLight
Definition: LightTest.h:55
cocos2d::Label * _ambientLightLabel
Definition: LightTest.h:58
void addSprite()
Definition: LightTest.cpp:106
void addLights()
Definition: LightTest.cpp:166
cocos2d::SpotLight * _spotLight
Definition: LightTest.h:56
static cocos2d::Vec2 top()
Definition: VisibleRect.cpp:57
static cocos2d::Vec2 left()
Definition: VisibleRect.cpp:45

引用了 _ambientLightLabel, _directionalLightLabel, _pointLightLabel, _spotLightLabel, addLights(), addSprite(), VisibleRect::left(), SwitchLight() , 以及 VisibleRect::top().

+ 函数调用图:

◆ ~LightTest()

LightTest::~LightTest ( )
virtual

在文件 LightTest.cpp77 行定义.

78{
80 _spotLightLabel->release();
81
83 _pointLightLabel->release();
84
86 _directionalLightLabel->release();
87
88 if (_spotLight)
89 _spotLight->release();
90
91 if (_pointLight)
92 _pointLight->release();
93
95 _directionalLight->release();
96
97 if (_ambientLight)
98 _ambientLight->release();
99}
cocos2d::AmbientLight * _ambientLight
Definition: LightTest.h:53

引用了 _ambientLight, _directionalLight, _directionalLightLabel, _pointLight, _pointLightLabel, _spotLight , 以及 _spotLightLabel.

成员函数说明

◆ addLights()

void LightTest::addLights ( )
private

在文件 LightTest.cpp166 行定义.

167{
168 auto s = Director::getInstance()->getWinSize();
169 _ambientLight = AmbientLight::create(Color3B(200, 200, 200));
170 _ambientLight->retain();
171 _ambientLight->setEnabled(true);
172 addChild(_ambientLight);
173 _ambientLight->setCameraMask(2);
174
175 _directionalLight = DirectionLight::create(Vec3(-1.0f, -1.0f, 0.0f), Color3B(200, 200, 200));
176 _directionalLight->retain();
177 _directionalLight->setEnabled(false);
178 addChild(_directionalLight);
179 _directionalLight->setCameraMask(2);
180
181 _pointLight = PointLight::create(Vec3(0.0f, 0.0f, 0.0f), Color3B(200, 200, 200), 10000.0f);
182 _pointLight->retain();
183 _pointLight->setEnabled(false);
184 addChild(_pointLight);
185 _pointLight->setCameraMask(2);
186
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);
188 _spotLight->retain();
189 _spotLight->setEnabled(false);
190 addChild(_spotLight);
191 _spotLight->setCameraMask(2);
192
193 {
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);
199 _ambientLight->runAction(RepeatForever::create(seq));
200 }
201
202 {
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);
208 _directionalLight->runAction(RepeatForever::create(seq));
209 }
210
211 {
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));
218 }
219
220 {
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));
227 }
228}

引用了 _ambientLight, _directionalLight, _pointLight , 以及 _spotLight.

被这些函数引用 LightTest().

+ 这是这个函数的调用关系图:

◆ addSprite()

void LightTest::addSprite ( )
private

在文件 LightTest.cpp106 行定义.

107{
108 auto s = Director::getInstance()->getWinSize();
109
110 //{
111 // std::string fileName = "Sprite3DTest/plane.c3b";
112 // auto sprite = Sprite3D::create(fileName);
113 // sprite->setRotation3D(Vec3(-90.0, 0.0, 0.0));
114 // sprite->setScale(5.0f);
115 // sprite->setPosition(Vec2(0.0, -50.0));
116 // addChild(sprite);
117 // sprite->setCameraMask(2);
118 //}
119
120 {
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);
129 if (animation)
130 {
131 auto animate = Animate3D::create(animation);
132 sprite->runAction(RepeatForever::create(animate));
133 }
134
135 addChild(sprite);
136 sprite->setCameraMask(2);
137 }
138
139 {
140 std::string fileName = "Sprite3DTest/sphere.c3b";
141 auto sprite = Sprite3D::create(fileName);
142 sprite->setPosition(Vec2(30.0f, 0.0f));
143 addChild(sprite);
144 sprite->setCameraMask(2);
145 }
146
147 {
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));
152 addChild(sprite);
153 sprite->setCameraMask(2);
154 }
155
156 {
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));
161 addChild(sprite);
162 sprite->setCameraMask(2);
163 }
164}

被这些函数引用 LightTest().

+ 这是这个函数的调用关系图:

◆ CREATE_FUNC()

LightTest::CREATE_FUNC ( LightTest  )

◆ SwitchLight()

void LightTest::SwitchLight ( cocos2d::Ref *  sender,
cocos2d::LightType  lightType 
)

在文件 LightTest.cpp259 行定义.

260{
261 switch (lightType)
262 {
263 case LightType::AMBIENT:
264 {
265 char str[32];
266 bool isON = !_ambientLight->isEnabled();
267 sprintf(str, "Ambient Light %s", isON == true? "ON":"OFF");
268 _ambientLight->setEnabled(isON);
269 _ambientLightLabel->setString(str);
270 }
271 break;
272
273 case LightType::DIRECTIONAL:
274 {
275 char str[32];
276 bool isON = !_directionalLight->isEnabled();
277 sprintf(str, "Directional Light %s", isON == true? "ON":"OFF");
278 _directionalLight->setEnabled(isON);
279 _directionalLightLabel->setString(str);
280 }
281 break;
282
283 case LightType::POINT:
284 {
285 char str[32];
286 bool isON = !_pointLight->isEnabled();
287 sprintf(str, "Point Light %s", isON == true? "ON":"OFF");
288 _pointLight->setEnabled(isON);
289 _pointLightLabel->setString(str);
290 }
291 break;
292
293 case LightType::SPOT:
294 {
295 char str[32];
296 bool isON = !_spotLight->isEnabled();
297 sprintf(str, "Spot Light %s", isON == true? "ON":"OFF");
298 _spotLight->setEnabled(isON);
299 _spotLightLabel->setString(str);
300 }
301 break;
302
303 default:
304 break;
305 }
306}

引用了 _ambientLight, _ambientLightLabel, _directionalLight, _directionalLightLabel, _pointLight, _pointLightLabel, _spotLight , 以及 _spotLightLabel.

被这些函数引用 LightTest().

+ 这是这个函数的调用关系图:

◆ title()

std::string LightTest::title ( ) const
overridevirtual

重载 TestCase .

在文件 LightTest.cpp101 行定义.

102{
103 return "Light Test";
104}

◆ update()

void LightTest::update ( float  delta)
overridevirtual

在文件 LightTest.cpp230 行定义.

231{
232 static float angleDelta = 0.0;
233
235 {
236 _directionalLight->setRotation3D(Vec3(-45.0, -CC_RADIANS_TO_DEGREES(angleDelta), 0.0f));
237 }
238
239 if (_pointLight)
240 {
241 _pointLight->setPositionX(100.0f * cosf(angleDelta + 2.0 * delta));
242 _pointLight->setPositionY(100.0f);
243 _pointLight->setPositionZ(100.0f * sinf(angleDelta + 2.0 * delta));
244 }
245
246 if (_spotLight)
247 {
248 _spotLight->setPositionX(100.0f * cosf(angleDelta + 4.0 * delta));
249 _spotLight->setPositionY(100.0f);
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)));
252 }
253
254 angleDelta += delta;
255
256 TestCase::update(delta);
257}

引用了 _directionalLight, _pointLight , 以及 _spotLight.

类成员变量说明

◆ _ambientLight

cocos2d::AmbientLight* LightTest::_ambientLight
private

在文件 LightTest.h53 行定义.

被这些函数引用 addLights(), SwitchLight() , 以及 ~LightTest().

◆ _ambientLightLabel

cocos2d::Label* LightTest::_ambientLightLabel
private

在文件 LightTest.h58 行定义.

被这些函数引用 LightTest() , 以及 SwitchLight().

◆ _directionalLight

cocos2d::DirectionLight* LightTest::_directionalLight
private

在文件 LightTest.h54 行定义.

被这些函数引用 addLights(), SwitchLight(), update() , 以及 ~LightTest().

◆ _directionalLightLabel

cocos2d::Label* LightTest::_directionalLightLabel
private

在文件 LightTest.h59 行定义.

被这些函数引用 LightTest(), SwitchLight() , 以及 ~LightTest().

◆ _pointLight

cocos2d::PointLight* LightTest::_pointLight
private

在文件 LightTest.h55 行定义.

被这些函数引用 addLights(), SwitchLight(), update() , 以及 ~LightTest().

◆ _pointLightLabel

cocos2d::Label* LightTest::_pointLightLabel
private

在文件 LightTest.h60 行定义.

被这些函数引用 LightTest(), SwitchLight() , 以及 ~LightTest().

◆ _spotLight

cocos2d::SpotLight* LightTest::_spotLight
private

在文件 LightTest.h56 行定义.

被这些函数引用 addLights(), SwitchLight(), update() , 以及 ~LightTest().

◆ _spotLightLabel

cocos2d::Label* LightTest::_spotLightLabel
private

在文件 LightTest.h61 行定义.

被这些函数引用 LightTest(), SwitchLight() , 以及 ~LightTest().


该类的文档由以下文件生成: