-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/LastCoffeeStudio/LCSEngine
- Loading branch information
Showing
18 changed files
with
251 additions
and
10,834 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ enum TypeComponent | |
ANIMATION, | ||
AUDIOLISTENER, | ||
AUDIOSOURCE, | ||
PARTICLESYSTEM, | ||
BILLBOARDGRID | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "ParticleSystemComponent.h" | ||
#include "TransformComponent.h" | ||
#include "GameObject.h" | ||
|
||
ParticleSystemComponent::ParticleSystemComponent(GameObject* gameObject) : Component(gameObject, true, true) | ||
{ | ||
typeComponent = PARTICLESYSTEM; | ||
} | ||
|
||
|
||
ParticleSystemComponent::~ParticleSystemComponent() {} | ||
|
||
void ParticleSystemComponent::drawGUI() {} | ||
|
||
void ParticleSystemComponent::updateParticles(float deltaTime) | ||
{ | ||
//Update Active particles | ||
//if number of active particles less than total particles && timeSpawn | ||
//Instantiate new particle from inactive particles | ||
updateActiveParticles(deltaTime); | ||
spawnParticle(deltaTime); | ||
} | ||
|
||
void ParticleSystemComponent::updateActiveParticles(float deltaTime) | ||
{ | ||
for (std::list<Particle*>::iterator it = activeParticles.begin(); it != activeParticles.end();) | ||
{ | ||
(*it)->lifeTime -= deltaTime; | ||
if ((*it)->lifeTime < 0.f) | ||
{ | ||
(*it)->lifeTime = lifeTimeParticles; | ||
float3 posGameObject = ((TransformComponent*)gameObject->getComponent(TRANSFORM))->position; | ||
//(*it)->position = | ||
inactiveParticles.push_back(*it); | ||
it = activeParticles.erase(it); | ||
} | ||
else | ||
{ | ||
(*it)->position += (*it)->velocity * deltaTime; | ||
++it; | ||
} | ||
} | ||
} | ||
|
||
void ParticleSystemComponent::spawnParticle(float deltaTime) | ||
{ | ||
spawnCountdown -= deltaTime; | ||
if (spawnCountdown < 0.f && inactiveParticles.size() > 0 && activeParticles.size() < totalParticles) | ||
{ | ||
activeParticles.push_back(inactiveParticles.front()); | ||
inactiveParticles.pop_front(); | ||
spawnCountdown = spawnTime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
#ifndef __PARTICLESYSTEMCOMPONENT_H__ | ||
#define __PARTICLESYSTEMCOMPONENT_H__ | ||
|
||
#include "Component.h" | ||
#include "MathGeoLib/src/Math/float3.h" | ||
#include <list> | ||
|
||
typedef unsigned int GLuint; | ||
|
||
struct Particle | ||
{ | ||
float3 position = float3::zero; | ||
float3 velocity = float3::zero; | ||
float width = 0.f; | ||
float height = 0.f; | ||
float lifeTime = 0.f; | ||
float3 color = float3(1.f,1.f,1.f); | ||
GLuint sprite; | ||
|
||
}; | ||
|
||
class ParticleSystemComponent | ||
class ParticleSystemComponent : public Component | ||
{ | ||
public: | ||
ParticleSystemComponent(); | ||
ParticleSystemComponent(GameObject* gameObject); | ||
~ParticleSystemComponent(); | ||
void drawGUI(); | ||
void updateParticles(float deltaTime); | ||
|
||
public: | ||
std::vector<Particle*> particles; | ||
std::list<Particle*> activeParticles; | ||
std::list<Particle*> inactiveParticles; | ||
unsigned int totalParticles = 0; | ||
float widthEmisor = 0.f; | ||
float heightEmisor = 0.f; | ||
float lifeTimeParticles = 0.f; | ||
float spawnTime = 0.f; | ||
float spawnCountdown = 0.f; | ||
GLuint sprite; | ||
|
||
private: | ||
void updateActiveParticles(float deltaTime); | ||
void spawnParticle(float deltaTime); | ||
|
||
}; | ||
|
||
#endif //__PARTICLESYSTEMCOMPONENT_H__ |
Oops, something went wrong.