Skip to content

Commit

Permalink
feat: #102 Update imgui particle test
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Sep 11, 2020
1 parent 9661618 commit 44b5c98
Show file tree
Hide file tree
Showing 11 changed files with 786 additions and 100 deletions.
10 changes: 5 additions & 5 deletions Projects/Skylicht/Components/Source/GridPlane/CGridPlaneData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Skylicht
{
clearBuffer();

SColor color(255, 100, 100, 100);
SColor color(255, 50, 50, 50);

core::vector3df start;
core::vector3df end;
Expand All @@ -56,9 +56,9 @@ namespace Skylicht
for (int i = 0; i <= NumGrid; i++)
{
if (i == NumGrid / 2)
color = SColor(255, 255, 255, 255);
else
color = SColor(255, 100, 100, 100);
else
color = SColor(255, 50, 50, 50);

addLineVertexBatch(start, end, color);

Expand All @@ -72,9 +72,9 @@ namespace Skylicht
for (int i = 0; i <= NumGrid; i++)
{
if (i == NumGrid / 2)
color = SColor(255, 255, 255, 255);
else
color = SColor(255, 100, 100, 100);
else
color = SColor(255, 50, 50, 50);

addLineVertexBatch(start, end, color);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,23 @@ namespace Skylicht
return &m_factory;
}

inline CParticleBufferData* getData()
{
return m_data;
}

CGroup* createParticleGroup();

inline u32 getNumOfGroup()
{
return m_data->Groups.size();
}

inline CGroup* getGroup(int i)
{
return m_data->Groups[i];
}

void removeParticleGroup(CGroup* group);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace Skylicht
return p;
}

void CGroup::update(bool updateBuffer)
void CGroup::update(bool visible)
{
if (m_zone == NULL)
return;
Expand All @@ -108,11 +108,19 @@ namespace Skylicht
CParticle *particles = m_particles.pointer();
u32 numParticles = m_particles.size();

// update particle system
m_particleSystem->update(particles, numParticles, this, dt);
if (visible == true)
{
// update particle system
m_particleSystem->update(particles, numParticles, this, dt);

for (ISystem *s : m_systems)
s->update(particles, numParticles, this, dt);
for (ISystem *s : m_systems)
s->update(particles, numParticles, this, dt);
}
else
{
// we just update life time of hide particle
m_particleSystem->updateLifeTime(particles, numParticles, this, dt);
}

if (numParticles > 0)
m_bbox.reset(particles[0].Position);
Expand All @@ -136,8 +144,8 @@ namespace Skylicht
}
}

// update instancing buffer
if (updateBuffer == true)
// update instancing buffer
if (visible == true)
m_bufferSystem->update(particles, numParticles, this, dt);

u32 emiterId = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace Skylicht

virtual ~CGroup();

void update(bool updateBuffer);
void update(bool visible);

inline void setWorldMatrix(const core::matrix4& m)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace Skylicht
{
m_start1 = f1;
m_start2 = f2;

m_haveStart = true;
return this;
}
Expand All @@ -84,6 +85,7 @@ namespace Skylicht
{
m_end1 = f1;
m_end2 = f2;

m_haveEnd = true;
return this;
}
Expand All @@ -98,6 +100,26 @@ namespace Skylicht
return m_haveEnd;
}

float getStartValue1()
{
return m_start1;
}

float getStartValue2()
{
return m_start2;
}

float getEndValue1()
{
return m_end1;
}

float getEndValue2()
{
return m_end2;
}

float getRandomStart();

float getRandomEnd();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace Skylicht
{
enum EParticleParams
{
ScaleX = 0,
Scale = 0,
ScaleX,
ScaleY,
ScaleZ,
ColorR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ namespace Skylicht
nbBorn = core::max_(0, m_tank);
m_tank = 0;
}
else if (m_tank >= 0)
else if (m_tank < 0)
{
m_fraction += m_flow * deltaTime * 0.001f;
nbBorn = static_cast<int>(m_fraction);
m_fraction -= nbBorn;
}
else if (m_tank > 0)
{
m_fraction += m_flow * deltaTime * 0.001f;
nbBorn = static_cast<int>(m_fraction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ namespace Skylicht

}

void CParticleSystem::updateLifeTime(CParticle *particles, int num, CGroup *group, float dt)
{
dt = dt * 0.001f;

CParticle *p;

#pragma omp parallel for private(p)
for (int i = 0; i < num; i++)
{
p = particles + i;

// update life time
p->Age = p->Age + dt;

if (!p->Immortal)
p->Life -= dt;
}
}

void CParticleSystem::update(CParticle *particles, int num, CGroup *group, float dt)
{
dt = dt * 0.001f;
Expand Down Expand Up @@ -137,6 +156,13 @@ namespace Skylicht

// update param value
params[t] = p->StartValue[t] + (p->EndValue[t] - p->StartValue[t]) * y;

if (t == Scale)
{
params[ScaleX] = params[Scale];
params[ScaleY] = params[Scale];
params[ScaleZ] = params[Scale];
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace Skylicht

virtual ~CParticleSystem();

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

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

0 comments on commit 44b5c98

Please sign in to comment.