CCPUAffector.cpp
6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/****************************************************************************
Copyright (C) 2013 Henry van Merode. All rights reserved.
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
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 "extensions/Particle3D/PU/CCPUAffector.h"
#include "extensions/Particle3D/PU/CCPUEmitter.h"
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
NS_CC_BEGIN
PUAffector::PUAffector()
: _affectorScale(Vec3::ONE)
, _affectSpecialisation(AFSP_DEFAULT)
, _mass(1.0f)
{
}
PUAffector::~PUAffector()
{
_particleSystem = nullptr;
}
void PUAffector::updatePUAffector(PUParticle3D* /*particle*/, float /*delta*/)
{
}
const Vec3& PUAffector::getDerivedPosition()
{
PUParticleSystem3D *ps = static_cast<PUParticleSystem3D *>(_particleSystem);
if (ps){
Mat4 rotMat;
Mat4::createRotation(ps->getDerivedOrientation(), &rotMat);
_derivedPosition = ps->getDerivedPosition() + rotMat * Vec3(_position.x * _affectorScale.x, _position.y * _affectorScale.y, _position.z * _affectorScale.z);
//_particleSystem->getNodeToWorldTransform().transformPoint(_position, &_derivedPosition);
}
else
_derivedPosition = _position;
return _derivedPosition;
//if (mMarkedForEmission)
//{
// // Use the affector position, because it is emitted
// // If a particle is emitted, position and derived position are the same
// _derivedPosition = position;
//}
//else
//{
// // Add the techniques' derived position
// _derivedPosition = mParentTechnique->getDerivedPosition() +
// mParentTechnique->getParentSystem()->getDerivedOrientation() * (_mAffectorScale * position);
//}
//return _derivedPosition;
}
float PUAffector::calculateAffectSpecialisationFactor( const PUParticle3D* particle )
{
// Assume that particle->totalTimeToLive != 0, which is reasonable
switch (_affectSpecialisation)
{
case AFSP_DEFAULT:
return 1.0f;
break;
// This means that older particles will be affected MORE than just emitted particles
case AFSP_TTL_INCREASE:
{
if (particle)
{
return particle->timeFraction;
}
else
{
return 1.0f;
}
}
break;
// This means that older particles will be affected LESS than just emitted particles
case AFSP_TTL_DECREASE:
{
if (particle)
{
return 1.0f - particle->timeFraction;
}
else
{
return 1.0f;
}
}
break;
default:
return 1.0f;
break;
}
}
void PUAffector::notifyStart()
{
}
void PUAffector::notifyStop()
{
}
void PUAffector::notifyPause()
{
}
void PUAffector::notifyResume()
{
}
void PUAffector::preUpdateAffector( float /*deltaTime*/ )
{
}
void PUAffector::postUpdateAffector( float /*deltaTime*/ )
{
}
void PUAffector::prepare()
{
}
void PUAffector::unPrepare()
{
}
void PUAffector::initParticleForEmission( PUParticle3D* /*particle*/ )
{
}
void PUAffector::notifyRescaled(const Vec3& scale)
{
_affectorScale = scale;
}
void PUAffector::firstParticleUpdate( PUParticle3D* /*particle*/, float /*deltaTime*/ )
{
}
void PUAffector::setMass( float mass )
{
_mass = mass;
}
float PUAffector::getMass() const
{
return _mass;
}
void PUAffector::copyAttributesTo( PUAffector* affector )
{
affector->setName(_name);
affector->setAffectorType(_affectorType);
affector->_position = _position;
affector->_isEnabled = _isEnabled;
affector->_particleSystem = _particleSystem;
affector->_affectorScale = _affectorScale;
affector->_affectSpecialisation = _affectSpecialisation;
affector->_excludedEmitters = _excludedEmitters;
}
void PUAffector::addEmitterToExclude( const std::string& emitterName )
{
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
if (iter == _excludedEmitters.end()){
_excludedEmitters.push_back(emitterName);
}
}
void PUAffector::removeEmitterToExclude( const std::string& emitterName )
{
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
if (iter != _excludedEmitters.end()){
_excludedEmitters.erase(iter);
}
}
void PUAffector::process( PUParticle3D* particle, float delta, bool firstParticle )
{
if (firstParticle){
firstParticleUpdate(particle, delta);
}
if (!_excludedEmitters.empty() && particle->parentEmitter){
// Return if the emitter which emits this particle is part of the vector
std::string emitterName = particle->parentEmitter->getName();
auto iter = std::find(_excludedEmitters.begin(), _excludedEmitters.end(), emitterName);
if (iter != _excludedEmitters.end())
{
return;
}
}
updatePUAffector(particle, delta);
}
NS_CC_END