Skip to content

Commit

Permalink
#102 Update subgroup sync color & life from parent group
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 4, 2020
1 parent aff6397 commit 82d53b5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ namespace Skylicht
float life = Life;
float lifeTime = LifeTime;
bool haveRotate = HaveRotate;
int parentIndex = ParentIndex;

core::vector3df lastPosition = LastPosition;
core::vector3df position = Position;
core::vector3df rotation = Rotation;
core::vector3df velocity = Velocity;
Expand All @@ -94,18 +96,22 @@ namespace Skylicht
Age = p.Age;
Life = p.Life;
LifeTime = p.LifeTime;
LastPosition = p.LastPosition;
Position = p.Position;
Rotation = p.Rotation;
Velocity = p.Velocity;
HaveRotate = p.HaveRotate;
ParentIndex = p.ParentIndex;

p.Age = age;
p.Life = life;
p.LifeTime = lifeTime;
p.LastPosition = lastPosition;
p.Position = position;
p.Rotation = rotation;
p.Velocity = velocity;
p.HaveRotate = haveRotate;
p.ParentIndex = parentIndex;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace Skylicht
{
CSubGroup::CSubGroup(CGroup *group) :
m_parentGroup(group),
m_followParentTransform(false)
m_followParentTransform(false),
m_emitterWorldOrientation(false)
{
m_parentGroup->addCallback(this);

Expand Down Expand Up @@ -166,21 +167,22 @@ namespace Skylicht
if (m_followParentTransform == true)
return pos;

core::vector3df ret = m_position + pos;
core::vector3df ret = m_position + m_rotate * pos;
return ret;
}

core::vector3df CSubGroup::getTransformVector(const core::vector3df& vec)
{
if (m_emitterWorldOrientation == true)
return CGroup::getTransformVector(vec);

core::vector3df ret = m_rotate * vec;
return ret;
}
}

void CSubGroup::setFollowParentTransform(bool b)
void CSubGroup::syncParentParams(bool life, bool color)
{
m_followParentTransform = b;

m_parentSystem->setEnable(b);
((CParentRelativeSystem*)m_parentSystem)->syncParams(life, color);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace Skylicht
core::vector3df m_direction;
core::quaternion m_rotate;

bool m_followParentTransform;
bool m_followParentTransform;
bool m_emitterWorldOrientation;

public:
CSubGroup(CGroup *group);
Expand All @@ -66,7 +67,18 @@ namespace Skylicht

virtual core::vector3df getTransformVector(const core::vector3df& vec);

void setFollowParentTransform(bool b);
inline void setFollowParentTransform(bool b)
{
m_followParentTransform = b;
m_parentSystem->setEnable(b);
}

inline void setEmitterWorldOrientation(bool b)
{
m_emitterWorldOrientation = b;
}

void syncParentParams(bool life, bool color);

inline CGroup* getParentGroup()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ namespace Skylicht
{
namespace Particle
{
CParentRelativeSystem::CParentRelativeSystem()
CParentRelativeSystem::CParentRelativeSystem() :
m_syncLife(false),
m_syncColor(false)
{

}
Expand Down Expand Up @@ -60,7 +62,24 @@ namespace Skylicht

if (p->ParentIndex >= 0)
{
p->Position = (p->Position - p->LastPosition) + baseParticles[p->ParentIndex].Position;
CParticle &parent = baseParticles[p->ParentIndex];

p->Position = (p->Position - p->LastPosition) + parent.Position;

if (m_syncLife == true)
{
p->Age = parent.Age;
p->Life = parent.Life;
p->LifeTime = parent.LifeTime;
}

if (m_syncColor == true)
{
p->Params[ColorR] = parent.Params[ColorR];
p->Params[ColorG] = parent.Params[ColorG];
p->Params[ColorB] = parent.Params[ColorB];
p->Params[ColorA] = parent.Params[ColorA];
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ namespace Skylicht
{
class CParentRelativeSystem : public ISystem
{
protected:
bool m_syncLife;
bool m_syncColor;

public:
CParentRelativeSystem();

virtual ~CParentRelativeSystem();

virtual void update(CParticle *particles, int num, CGroup *group, float dt);

void syncParams(bool life, bool color)
{
m_syncLife = life;
m_syncColor = color;
}
};
}
}
13 changes: 7 additions & 6 deletions Samples/ParticlesMagicSkill/Source/SampleParticlesMagicSkill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void SampleParticlesMagicSkill::initParticleSystem(Particle::CParticleComponent

Particle::CCylinder* cylinder = factory->createCylinderZone(core::vector3df(), core::vector3df(0.0f, 1.0f, 0.0f), 0.6, 0.1f);
Particle::CPoint* point = factory->createPointZone();
Particle::CCylinder* trailCylinder = factory->createCylinderZone(core::vector3df(0.0f, -0.3f, 0.0f), core::vector3df(0.0f, 1.0f, 0.0f), 0.2, 0.7f);

// GROUP: SPARK
Particle::CGroup *sparkGroup = ps->createParticleGroup();
Expand Down Expand Up @@ -176,17 +177,17 @@ void SampleParticlesMagicSkill::initParticleSystem(Particle::CParticleComponent
arcane->SizeZ = 0.6f;
arcaneGroup->setRenderer(arcane);
arcaneGroup->setFollowParentTransform(true);
arcaneGroup->syncParentParams(true, true);

texture = CTextureManager::getInstance()->getTexture("Particles/Textures/Arcane/arcane_twirl.png");
arcane->setMaterialType(Particle::Addtive, Particle::Camera);
arcane->getMaterial()->setTexture(0, texture);
arcane->getMaterial()->applyMaterial();

arcaneGroup->createModel(Particle::ColorA)->setStart(1.0f)->setEnd(0.0f);
arcaneGroup->createModel(Particle::RotateSpeedZ)->setStart(3.0f, 5.0f);
arcaneGroup->createModel(Particle::RotateZ)->setStart(0.0f, core::PI);
arcaneGroup->LifeMin = 4.0f;
arcaneGroup->LifeMin = 8.0f;
arcaneGroup->LifeMax = 8.0f;

Particle::CEmitter *arcaneEmitter = factory->createNormalEmitter(false);
arcaneEmitter->setFlow(100.0f);
Expand All @@ -212,15 +213,15 @@ void SampleParticlesMagicSkill::initParticleSystem(Particle::CParticleComponent
sphereGroup->createModel(Particle::ColorA)->setStart(1.0f)->setEnd(0.0f);
sphereGroup->createModel(Particle::RotateSpeedZ)->setStart(3.0f, 5.0f);
sphereGroup->createModel(Particle::RotateZ)->setStart(0.0f, core::PI);
sphereGroup->LifeMin = 1.0f;
sphereGroup->LifeMin = 2.0f;
sphereGroup->LifeMin = 0.5f;
sphereGroup->LifeMax = 1.5f;
sphereGroup->Friction = 1.0f;

Particle::CEmitter *sphereEmitter = factory->createSphericEmitter(-CTransform::s_oy, 0.0f, 60.0f * core::DEGTORAD);
sphereEmitter->setFlow(10.0f);
sphereEmitter->setTank(-1);
sphereEmitter->setForce(0.6f, 1.0f);
sphereEmitter->setZone(point);
sphereEmitter->setForce(0.0f, 0.6f);
sphereEmitter->setZone(trailCylinder);
sphereGroup->addEmitter(sphereEmitter);
}

Expand Down

0 comments on commit 82d53b5

Please sign in to comment.