Skip to content

Commit

Permalink
feat: #102 add straight emitter & sphere zone
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Sep 7, 2020
1 parent ceb5f88 commit a70a81c
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ namespace Skylicht
return e;
}

CStraightEmitter* CFactory::createStraightEmitter(const core::vector3df& direction)
{
CStraightEmitter *e = new CStraightEmitter();
e->setDirection(direction);
m_emitters.push_back(e);
return e;
}

void CFactory::deleteEmitter(CEmitter *e)
{
std::vector<CEmitter*>::iterator i = std::find(m_emitters.begin(), m_emitters.end(), e);
Expand Down Expand Up @@ -91,6 +99,13 @@ namespace Skylicht
return z;
}

CSphere* CFactory::createSphereZone(const core::vector3df& pos, float radius)
{
CSphere *z = new CSphere(pos, radius);
m_zones.push_back(z);
return z;
}

void CFactory::deleteZone(CZone *z)
{
std::vector<CZone*>::iterator i = std::find(m_zones.begin(), m_zones.end(), z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ This file is part of the "Skylicht Engine".
#include "Emitters/CEmitter.h"

#include "Renderers/CQuadRenderer.h"

#include "Zones/CPoint.h"
#include "Zones/CSphere.h"

#include "Emitters/CRandomEmitter.h"
#include "Emitters/CStraightEmitter.h"

namespace Skylicht
{
Expand All @@ -50,6 +54,8 @@ namespace Skylicht

CRandomEmitter* createRandomEmitter();

CStraightEmitter* createStraightEmitter(const core::vector3df& direction);

void deleteEmitter(CEmitter *e);

CQuadRenderer* createQuadRenderer();
Expand All @@ -58,6 +64,8 @@ namespace Skylicht

CPoint* createPointZone();

CSphere* createSphereZone(const core::vector3df& pos, float radius);

void deleteZone(CZone *z);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace Skylicht

enum EEmitter
{
Random
Random,
Straight,
};

class CEmitter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
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.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "CStraightEmitter.h"
#include "ParticleSystem/Particles/CParticle.h"

namespace Skylicht
{
namespace Particle
{
CStraightEmitter::CStraightEmitter() :
CEmitter(Straight),
m_direction(0.0f, 1.0f, 0.0f)
{

}

CStraightEmitter::~CStraightEmitter()
{

}

void CStraightEmitter::generateVelocity(CParticle& particle, float speed, CZone* zone)
{
particle.Velocity = m_direction * speed;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
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.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#pragma once

#include "CEmitter.h"

namespace Skylicht
{
namespace Particle
{
class CStraightEmitter : public CEmitter
{
protected:
core::vector3df m_direction;

public:
CStraightEmitter();

virtual ~CStraightEmitter();

inline void setDirection(const core::vector3df& d)
{
m_direction = d;
m_direction.normalize();
}

inline const core::vector3df& getDirection()
{
return m_direction;
}

virtual void generateVelocity(CParticle& particle, float speed, CZone* zone);
};
}
}
19 changes: 11 additions & 8 deletions Samples/Particles/Source/SampleParticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ void SampleParticles::initFireParticle(Particle::CParticleComponent *particleCom
Particle::CGroup *group = particleComponent->createParticleGroup();

// create start point
Particle::CZone *zone = group->setZone(factory->createPointZone());
zone->setPosition(core::vector3df(0.0f, 0.0f, 0.0f));
// Particle::CZone *zone = group->setZone(factory->createPointZone());
Particle::CZone *zone = group->setZone(factory->createSphereZone(core::vector3df(0.0f, 0.0f, 0.0f), 1.0f));

// create emitter
Particle::CEmitter *emitter = group->addEmitter(factory->createRandomEmitter());
// Particle::CEmitter *emitter = group->addEmitter(factory->createRandomEmitter());
Particle::CEmitter *emitter = group->addEmitter(factory->createStraightEmitter(core::vector3df(0.0f, 0.0f, 1.0f)));
emitter->setTank(0);
emitter->setFlow(300.0f);
emitter->setFlow(500.0f);
emitter->setForce(0.0f, 0.0f);
emitter->setEmitFullZone(false);

// create renderer
Particle::CQuadRenderer *quadRenderer = factory->createQuadRenderer();
Expand All @@ -90,15 +93,15 @@ void SampleParticles::initFireParticle(Particle::CParticleComponent *particleCom
quadRenderer->getMaterial()->applyMaterial();

// create model
group->Gravity.set(0.0f, 0.4f, 0.0f);
group->Gravity.set(0.0f, 0.1f, 0.0f);

group->createModel(Particle::RotateSpeedZ)->setStart(2.0f);

group->createModel(Particle::FrameIndex)->setStart(0.0f, 3.0f);

group->createModel(Particle::ScaleX)->setStart(0.5f)->setEnd(4.0f, 6.0f);
group->createModel(Particle::ScaleY)->setStart(0.5f)->setEnd(4.0f, 6.0f);
group->createModel(Particle::ScaleZ)->setStart(0.5f)->setEnd(4.0f, 6.0f);
group->createModel(Particle::ScaleX)->setStart(0.1f)->setEnd(0.7f, 1.0f);
group->createModel(Particle::ScaleY)->setStart(0.1f)->setEnd(0.7f, 1.0f);
group->createModel(Particle::ScaleZ)->setStart(0.1f)->setEnd(0.7f, 1.0f);

group->createModel(Particle::ColorA)->setStart(1.0f)->setEnd(0.0f);
group->createModel(Particle::ColorR)->setStart(0.8f)->setEnd(1.0f);
Expand Down

0 comments on commit a70a81c

Please sign in to comment.