2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
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.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-10 09:47:41 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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 "CCPUSphereSurfaceEmitter.h"
|
|
|
|
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
|
|
|
|
#include "extensions/Particle3D/PU/CCPUUtil.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
// Constants
|
|
|
|
const float PUSphereSurfaceEmitter::DEFAULT_RADIUS = 10.0f;
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------
|
2021-12-25 10:04:45 +08:00
|
|
|
PUSphereSurfaceEmitter::PUSphereSurfaceEmitter() : PUEmitter(), _radius(DEFAULT_RADIUS) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
float PUSphereSurfaceEmitter::getRadius() const
|
|
|
|
{
|
|
|
|
return _radius;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
void PUSphereSurfaceEmitter::setRadius(const float radius)
|
|
|
|
{
|
|
|
|
_radius = radius;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
void PUSphereSurfaceEmitter::initParticlePosition(PUParticle3D* particle)
|
|
|
|
{
|
|
|
|
// Generate a random unit vector to calculate a point on the sphere. This unit vector is
|
|
|
|
// also used as direction vector if mAutoDirection has been set.
|
|
|
|
_randomVector.set(CCRANDOM_MINUS1_1(), CCRANDOM_MINUS1_1(), CCRANDOM_MINUS1_1());
|
|
|
|
_randomVector.normalize();
|
2021-12-25 10:04:45 +08:00
|
|
|
// ParticleSystem* sys = mParentTechnique->getParentSystem();
|
|
|
|
// if (sys)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
Mat4 rotMat;
|
2021-12-25 10:04:45 +08:00
|
|
|
Mat4::createRotation(static_cast<PUParticleSystem3D*>(_particleSystem)->getDerivedOrientation(), &rotMat);
|
|
|
|
particle->position =
|
|
|
|
getDerivedPosition() + rotMat * (Vec3(_emitterScale.x * _randomVector.x, _emitterScale.y * _randomVector.y,
|
|
|
|
_emitterScale.z * _randomVector.z) *
|
|
|
|
_radius);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
// else
|
2019-11-23 20:27:39 +08:00
|
|
|
//{
|
|
|
|
// particle->position = getDerivedPosition() + (_mEmitterScale * _randomVector * _radius);
|
2021-12-25 10:04:45 +08:00
|
|
|
// }
|
2019-11-23 20:27:39 +08:00
|
|
|
particle->originalPosition = particle->position;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
void PUSphereSurfaceEmitter::initParticleDirection(PUParticle3D* particle)
|
|
|
|
{
|
|
|
|
if (_autoDirection)
|
|
|
|
{
|
|
|
|
// The value of the direction vector that has been set does not have a meaning for
|
|
|
|
// the sphere surface emitter.
|
|
|
|
float angle = 0.0f;
|
|
|
|
generateAngle(angle);
|
|
|
|
if (angle != 0.0f)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
// particle->direction = _randomVector.randomDeviant(angle, mUpVector);
|
|
|
|
particle->direction = PUUtil::randomDeviant(_randomVector, angle, _upVector);
|
2019-11-23 20:27:39 +08:00
|
|
|
particle->originalDirection = particle->direction;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
particle->direction = _randomVector;
|
2019-11-23 20:27:39 +08:00
|
|
|
particle->originalDirection = particle->direction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use the standard way
|
|
|
|
PUEmitter::initParticleDirection(particle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PUSphereSurfaceEmitter* PUSphereSurfaceEmitter::create()
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
auto pe = new PUSphereSurfaceEmitter();
|
2019-11-23 20:27:39 +08:00
|
|
|
pe->autorelease();
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void PUSphereSurfaceEmitter::copyAttributesTo(PUEmitter* emitter)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
PUEmitter::copyAttributesTo(emitter);
|
|
|
|
|
|
|
|
PUSphereSurfaceEmitter* sphereSurfaceEmitter = static_cast<PUSphereSurfaceEmitter*>(emitter);
|
2021-12-25 10:04:45 +08:00
|
|
|
sphereSurfaceEmitter->_radius = _radius;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PUSphereSurfaceEmitter* PUSphereSurfaceEmitter::clone()
|
|
|
|
{
|
|
|
|
auto be = PUSphereSurfaceEmitter::create();
|
|
|
|
copyAttributesTo(be);
|
|
|
|
return be;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|