PuzzleSDK
Particle3DTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2012 cocos2d-x.org
3 Copyright (c) 2013-2016 Chukong Technologies Inc.
4 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5
6 http://www.cocos2d-x.org
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 ****************************************************************************/
26
27#include "Particle3DTest.h"
28#include "Particle3D/CCParticleSystem3D.h"
29#include "Particle3D/PU/CCPUParticleSystem3D.h"
30
32
33#define PARTICLE_SYSTEM_TAG 0x0001
34
35Particle3DTests::Particle3DTests()
36{
52}
53
54std::string Particle3DTestDemo::title() const
55{
56 return "Particle3D Test";
57}
58
60{
61 if (!TestCase::init()) return false;
62
63 FileUtils::getInstance()->addSearchPath("Particle3D/materials");
64 FileUtils::getInstance()->addSearchPath("Particle3D/scripts");
65 FileUtils::getInstance()->addSearchPath("Sprite3DTest");
66 //FileUtils::getInstance()->addSearchPath("Particle3D/textures");
67
68 Size size = Director::getInstance()->getWinSize();
69 _camera = Camera::createPerspective(30.0f, size.width / size.height, 1.0f, 1000.0f);
70 _camera->setPosition3D(Vec3(0.0f, 0.0f, 100.0f));
71 _camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
72 _camera->setCameraFlag(CameraFlag::USER1);
73 this->addChild(_camera);
74
75 auto listener = EventListenerTouchAllAtOnce::create();
76 listener->onTouchesBegan = CC_CALLBACK_2(Particle3DTestDemo::onTouchesBegan, this);
77 listener->onTouchesMoved = CC_CALLBACK_2(Particle3DTestDemo::onTouchesMoved, this);
78 listener->onTouchesEnded = CC_CALLBACK_2(Particle3DTestDemo::onTouchesEnded, this);
79 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
80
81
82 TTFConfig config("fonts/tahoma.ttf",10);
83 _particleLab = Label::createWithTTF(config,"Particle Count: 0",TextHAlignment::LEFT);
84 _particleLab->retain();
85 _particleLab->setPosition(Vec2(0.0f, size.height / 6.0f));
86 _particleLab->setAnchorPoint(Vec2(0.0f, 0.0f));
87 this->addChild(_particleLab);
88
89 scheduleUpdate();
90 return true;
91}
92
93void Particle3DTestDemo::onTouchesBegan(const std::vector<Touch*>& touches, cocos2d::Event *event)
94{
95
96}
97
98void Particle3DTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event)
99{
100 if (touches.size())
101 {
102 auto touch = touches[0];
103 auto delta = touch->getDelta();
104
105 _angle -= CC_DEGREES_TO_RADIANS(delta.x);
106 _camera->setPosition3D(Vec3(100.0f * sinf(_angle), 0.0f, 100.0f * cosf(_angle)));
107 _camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
108 }
109}
110
111void Particle3DTestDemo::onTouchesEnded(const std::vector<Touch*>& touches, cocos2d::Event *event)
112{
113
114}
115
117: _angle(0.0f)
118{
119
120}
121
122void Particle3DTestDemo::update( float delta )
123{
124 ParticleSystem3D *ps = static_cast<ParticleSystem3D *>(this->getChildByTag(PARTICLE_SYSTEM_TAG));
125 if (ps){
126 unsigned int count = 0;
127 auto children = ps->getChildren();
128 for (auto iter : children){
129 ParticleSystem3D *child = dynamic_cast<ParticleSystem3D *>(iter);
130 if (child){
131 count += child->getAliveParticleCount();
132 }
133 }
134
135 char str[128];
136 sprintf(str, "Particle Count: %d", count);
137 _particleLab->setString(str);
138 }
139}
140
142{
143 _particleLab->release();
144}
145
147{
148 return "AdvancedSystem";
149}
150
152{
154 return false;
155
156 auto rootps = PUParticleSystem3D::create("advancedLodSystem.pu");
157 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
158
159 auto scale = ScaleBy::create(1.0f, 2.0f, 2.0f, 2.0f);
160 auto rotate = RotateBy::create(1.0f, Vec3(0.0f, 0.0f, 100.0f));
161 rootps->runAction(RepeatForever::create(Sequence::create(rotate, nullptr)));
162 rootps->runAction(RepeatForever::create(Sequence::create(scale, scale->reverse(), nullptr)));
163 rootps->startParticleSystem();
164
165
166 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
167
168 return true;
169}
170
172{
173 return "BlackHole";
174}
175
177{
179 return false;
180
181 auto rootps = PUParticleSystem3D::create("blackHole.pu", "pu_mediapack_01.material");
182 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
183 rootps->setPosition(-25.0f, 0.0f);
184 auto moveby = MoveBy::create(2.0f, Vec2(50.0f, 0.0f));
185 auto moveby1 = MoveBy::create(2.0f, Vec2(-50.0f, 0.0f));
186// auto scale = ScaleBy::create(1.0f, 2.0f, 2.0f, 2.0f);
187// auto rotate = RotateBy::create(1.0f, Vec3(100.0f, 100.0f, 100.0f));
188 rootps->runAction(RepeatForever::create(Sequence::create(moveby, moveby1, nullptr)));
189 //rootps->runAction(RepeatForever::create(Sequence::create(scale, scale->reverse(), nullptr)));
190 //rootps->runAction(RepeatForever::create(Sequence::create(rotate, nullptr)));
191 rootps->startParticleSystem();
192
193 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
194
195 return true;
196}
197
199{
200 return "Hypno";
201}
202
204{
206 return false;
207
208 auto rootps = PUParticleSystem3D::create("hypno.pu", "pu_mediapack_01.material");
209 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
210// auto scale = ScaleBy::create(1.0f, 2.0f, 2.0f, 2.0f);
211// auto rotate = RotateBy::create(1.0f, Vec3(0.0, 100.0f, 0.0f));
212 //rootps->runAction(RepeatForever::create(Sequence::create(scale, scale->reverse(), nullptr)));
213 //rootps->runAction(RepeatForever::create(Sequence::create(rotate, nullptr)));
214 rootps->startParticleSystem();
215
216 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
217
218 return true;
219}
220
222{
223 return "TimeShift";
224}
225
227{
229 return false;
230
231 auto rootps = PUParticleSystem3D::create("timeShift.pu", "pu_mediapack_01.material");
232 rootps->setScale(2.0f);
233 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
234 rootps->startParticleSystem();
235
236 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
237
238 return true;
239}
240
242{
243 return "UVAnim";
244}
245
247{
249 return false;
250
251 auto rootps = PUParticleSystem3D::create("UVAnimation.pu", "pu_mediapack_01.material");
252 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
253 rootps->startParticleSystem();
254
255 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
256
257 return true;
258}
259
261{
262 return "Fire";
263}
264
266{
268 return false;
269
270 auto rootps = PUParticleSystem3D::create("mp_torch.pu", "pu_mediapack_01.material");
271 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
272 rootps->setScale(5.0f);
273 rootps->startParticleSystem();
274
275 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
276
277 return true;
278}
279
281{
282 return "LineStreak";
283}
284
286{
288 return false;
289
290 auto rootps = PUParticleSystem3D::create("lineStreak.pu", "pu_mediapack_01.material");
291 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
292 rootps->setScale(5.0f);
293 //rootps->runAction(RepeatForever::create(Sequence::create(rotate, nullptr)));
294 rootps->startParticleSystem();
295 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
296
297
298 //auto sprite = Sprite::create("pump_streak_04.png");
299 //sprite->setCameraMask((unsigned short)CameraFlag::USER1);
300 //sprite->setScale(0.5f);
301 //this->addChild(sprite);
302
303 return true;
304}
305
307{
308 return "ElectricBeamSystem";
309}
310
312{
314 return false;
315
316
317 auto rootps = PUParticleSystem3D::create("electricBeamSystem.pu");
318 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
319 rootps->startParticleSystem();
320 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
321
322 return true;
323}
324
326{
327 return "flareShield";
328}
329
331{
333 return false;
334
335
336 auto rootps = PUParticleSystem3D::create("flareShield.pu");
337 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
338 //rootps->setScale(0.25f);
339 rootps->startParticleSystem();
340 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
341
342 return true;
343}
344
346{
347 return "LightningBolt";
348}
349
351{
353 return false;
354
355
356 auto rootps = PUParticleSystem3D::create("lightningBolt.pu");
357 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
358 //rootps->setScale(0.25f);
359 rootps->startParticleSystem();
360 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
361
362 return true;
363}
364
366{
367 return "ExplosionSystem";
368}
369
371{
373 return false;
374
375
376 auto rootps = PUParticleSystem3D::create("explosionSystem.pu");
377 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
378 //rootps->setScale(5.0f);
379 //rootps->setPosition(-25.0f, 0.0f);
380 //auto moveby = MoveBy::create(2.0f, Vec2(50.0f, 0.0f));
381 //auto moveby1 = MoveBy::create(2.0f, Vec2(-50.0f, 0.0f));
382 //rootps->runAction(RepeatForever::create(Sequence::create(moveby, moveby1, nullptr)));
383 rootps->startParticleSystem();
384 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
385
386 return true;
387}
388
390{
391 return "CanOfWorms";
392}
393
395{
397 return false;
398
399 auto rootps = PUParticleSystem3D::create("canOfWorms.pu");
400 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
401 rootps->startParticleSystem();
402 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
403
404 return true;
405}
406
408{
409 return "RibbonTrailTest";
410}
411
413{
415 return false;
416
417 auto rootps = PUParticleSystem3D::create("ribbonTrailTest.pu");
418 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
419 rootps->startParticleSystem();
420 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
421
422 return true;
423}
424
426{
427 return "WeaponTrail";
428}
429
431{
433 return false;
434
435 auto rootps = PUParticleSystem3D::create("weaponTrail.pu");
436 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
437 rootps->startParticleSystem();
438 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
439
440 return true;
441}
442
444{
445 return "Particle3DWithSprite3D";
446}
447
449{
451 return false;
452
453 std::string c3bfileName = "Sprite3DTest/orc.c3b";
454 auto sprite = Sprite3D::create(c3bfileName);
455 this->addChild(sprite);
456 sprite->setPosition3D(Vec3(-20.0f, 0.0f, 0.0f));
457 sprite->setRotation3D(Vec3(0, 180, 0));
458 sprite->setCameraMask((unsigned short)CameraFlag::USER1);
459 //sprite->setOpacity(100);
460 auto animation = Animation3D::create(c3bfileName);
461 if (animation)
462 {
463 auto animate = Animate3D::create(animation);
464 sprite->runAction(RepeatForever::create(animate));
465 }
466
467 auto billboard = BillBoard::create("Images/Icon.png");
468 billboard->setPosition3D(Vec3(20.0f, 0.0f, 0.0f));
469 billboard->setScale(0.2f);
470 billboard->setCameraMask((unsigned short)CameraFlag::USER1);
471 this->addChild(billboard);
472
473
474 auto rootps = PUParticleSystem3D::create("lineStreak.pu");
475 rootps->setCameraMask((unsigned short)CameraFlag::USER1);
476 rootps->startParticleSystem();
477 this->addChild(rootps, 0, PARTICLE_SYSTEM_TAG);
478
479 return true;
480}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
#define PARTICLE_SYSTEM_TAG
USING_NS_CC
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
cocos2d::Camera * _camera
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual bool init() override
virtual ~Particle3DTestDemo()
cocos2d::Label * _particleLab
virtual std::string title() const override
void onTouchesBegan(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual void update(float delta) override
virtual bool init() override
virtual std::string subtitle() const override
virtual bool init() override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual bool init() override
virtual bool init() override
virtual std::string subtitle() const override