-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75663bf
commit 2778cb4
Showing
13 changed files
with
287 additions
and
5 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
33 changes: 33 additions & 0 deletions
33
GameEngine/src/Exodia/Scene/Components/DefaultComponents/ParticleComponent.hpp
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,33 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** R-Type | ||
** File description: | ||
** ParticleComponent | ||
*/ | ||
|
||
#ifndef PARTICLECOMPONENT_HPP_ | ||
#define PARTICLECOMPONENT_HPP_ | ||
|
||
// Exodia ECS includes | ||
#include "Scene/Components/Component.hpp" | ||
|
||
// External includes | ||
#include <glm/glm.hpp> | ||
|
||
namespace Exodia { | ||
|
||
struct ParticleComponent : public Component { | ||
float LifeTime; | ||
float LifeRemaining; | ||
glm::vec4 ColorBegin; | ||
glm::vec4 ColorEnd; | ||
float SizeBegin; | ||
float SizeEnd; | ||
|
||
ParticleComponent(ParticleComponent const &) = default; | ||
ParticleComponent() = default; | ||
ParticleComponent(float lifeTime, const glm::vec4 &colorBegin, const glm::vec4 &colorEnd, float sizeBegin, float sizeEnd) : LifeTime(lifeTime), LifeRemaining(lifeTime), ColorBegin(colorBegin), ColorEnd(colorEnd), SizeBegin(sizeBegin), SizeEnd(sizeEnd) {}; | ||
}; | ||
}; | ||
|
||
#endif /* !PARTICLECOMPONENT_HPP_ */ |
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
40 changes: 40 additions & 0 deletions
40
GameEngine/src/Exodia/Scene/System/Particle/ParticleSystem.cpp
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,40 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** R-Type | ||
** File description: | ||
** ParticleSystem | ||
*/ | ||
|
||
#include "ParticleSystem.hpp" | ||
#include <glm/gtx/compatibility.hpp> | ||
|
||
namespace Exodia { | ||
|
||
///////////// | ||
// Methods // | ||
///////////// | ||
|
||
void ParticleSystem::Update(World *world, Timestep ts) | ||
{ | ||
world->ForEach<TransformComponent, RigidBody2DComponent, ParticleComponent, SpriteRendererComponent>([&](Entity *entity, auto transform, auto rigidBody, auto particle, auto sprite) { | ||
auto &tc = transform.Get(); | ||
auto &rb = rigidBody.Get(); | ||
auto &pc = particle.Get(); | ||
auto &sc = sprite.Get(); | ||
|
||
if (pc.LifeRemaining <= 0.0f) { | ||
world->DestroyEntity(entity); | ||
|
||
return; | ||
} | ||
float life = pc.LifeRemaining / pc.LifeTime; | ||
float size = glm::lerp(pc.SizeEnd, pc.SizeBegin, life); | ||
glm::vec4 color = glm::lerp(pc.ColorEnd, pc.ColorBegin, life); | ||
|
||
pc.LifeRemaining -= ts; | ||
sc.Color.a = color.a * life; | ||
tc.Rotation.z += 0.01f * ts; | ||
tc.Scale = glm::vec3(size); | ||
}); | ||
} | ||
}; |
30 changes: 30 additions & 0 deletions
30
GameEngine/src/Exodia/Scene/System/Particle/ParticleSystem.hpp
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,30 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** R-Type | ||
** File description: | ||
** ParticleSystem | ||
*/ | ||
|
||
#ifndef PARTICLESYSTEM_HPP_ | ||
#define PARTICLESYSTEM_HPP_ | ||
|
||
// Exodia ECS Interface includes | ||
#include "Exodia-ECS.hpp" | ||
|
||
// Exodia Scene includes | ||
#include "Scene/Components/Components.hpp" | ||
|
||
namespace Exodia { | ||
|
||
class ParticleSystem : public EntitySystem { | ||
|
||
///////////// | ||
// Methods // | ||
///////////// | ||
public: | ||
|
||
virtual void Update(World *world, Timestep ts) override; | ||
}; | ||
}; | ||
|
||
#endif /* !PARTICLESYSTEM_HPP_ */ |
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 |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** R-Type | ||
** File description: | ||
** Particle | ||
*/ | ||
|
||
#ifndef PARTICLE_HPP_ | ||
#define PARTICLE_HPP_ | ||
|
||
// Exodia includes | ||
#include "Exodia.hpp" | ||
|
||
namespace RType { | ||
|
||
using namespace Exodia; | ||
|
||
class ParticleController : public ScriptableEntity { | ||
|
||
//////////////// | ||
// Structures // | ||
//////////////// | ||
public: | ||
|
||
struct ParticleProps { | ||
glm::vec2 Position; | ||
glm::vec2 Velocity; | ||
glm::vec2 VelocityVariation; | ||
glm::vec4 ColorBegin; | ||
glm::vec4 ColorEnd; | ||
float SizeBegin; | ||
float SizeEnd; | ||
float SizeVariation; | ||
float LifeTime = 1.0f; | ||
|
||
int NumParticles = 1; | ||
}; | ||
|
||
///////////// | ||
// Methods // | ||
///////////// | ||
public: | ||
|
||
void OnCreate() override | ||
{ | ||
// Smoke Particles | ||
_SmokeParticle.Position = { 0.0f, 0.0f }; | ||
_SmokeParticle.Velocity = { -2.0f, 0.0f }; | ||
_SmokeParticle.VelocityVariation = { 4.0f, 2.0f }; | ||
_SmokeParticle.SizeBegin = 0.35f; | ||
_SmokeParticle.SizeEnd = 0.0f; | ||
_SmokeParticle.SizeVariation = 0.15f; | ||
_SmokeParticle.ColorBegin = { 0.8f, 0.8f, 0.8f, 1.0f }; | ||
_SmokeParticle.ColorEnd = { 0.6f, 0.6f, 0.6f, 1.0f }; | ||
_SmokeParticle.LifeTime = 4.0f; | ||
|
||
// Engine Particles | ||
_EngineParticle.Position = { 0.0f, 0.0f }; | ||
_EngineParticle.Velocity = { -2.0f, 0.0f }; | ||
_EngineParticle.VelocityVariation = { 3.0f, 1.0f }; | ||
_EngineParticle.SizeBegin = 0.5f; | ||
_EngineParticle.SizeEnd = 0.0f; | ||
_EngineParticle.SizeVariation = 0.3f; | ||
_EngineParticle.ColorBegin = { 254 / 255.0f, 109 / 255.0f, 41 / 255.0f, 1.0f }; | ||
_EngineParticle.ColorEnd = { 254 / 255.0f, 212 / 255.0f, 123 / 255.0f, 1.0f }; | ||
_EngineParticle.LifeTime = 1.0f; | ||
_EngineParticle.NumParticles = 999; | ||
} | ||
|
||
void OnUpdate(Timestep ts) override | ||
{ | ||
_Time += ts; | ||
|
||
if (_Time > _SmokeNextEmitTime) { | ||
Emit(_SmokeParticle); | ||
|
||
_SmokeNextEmitTime += _SmokeEmitInterval; | ||
} | ||
} | ||
|
||
void OnKeyPressed(int keycode) override | ||
{ | ||
if (keycode == Key::SPACE) { | ||
glm::vec2 mousePos = Input::GetMousePosition(); | ||
|
||
_EngineParticle.Position = mousePos; | ||
|
||
Emit(_EngineParticle); | ||
} | ||
} | ||
|
||
private: | ||
|
||
void Emit(ParticleProps &props) | ||
{ | ||
std::mt19937 engine; | ||
std::uniform_real_distribution<float> distribution(0.0f, 1.0f); | ||
|
||
for (int i = 0; i < props.NumParticles; i++) { | ||
GameObject particle = HandleEntity.GetScene()->CreateNewEntity("Particle #" + std::to_string(i)); | ||
|
||
TransformComponent &tc = particle.GetComponent<TransformComponent>(); | ||
|
||
tc.Translation.x = props.Position.x + Input::GetMousePosition().x; | ||
tc.Translation.y = props.Position.y + Input::GetMousePosition().y; | ||
tc.Rotation.z = (float)distribution(engine); | ||
tc.Scale = glm::vec3(props.SizeBegin + props.SizeVariation * ((float)distribution(engine) - 0.5f)); | ||
|
||
SpriteRendererComponent &src = particle.AddComponent<SpriteRendererComponent>(); | ||
|
||
src.Color = props.ColorBegin; | ||
|
||
ParticleComponent &pc = particle.AddComponent<ParticleComponent>(); | ||
|
||
pc.LifeTime = props.LifeTime; | ||
pc.LifeRemaining = props.LifeTime; | ||
pc.ColorBegin = props.ColorBegin; | ||
pc.ColorEnd = props.ColorEnd; | ||
pc.SizeBegin = props.SizeBegin + props.SizeVariation * ((float)distribution(engine) - 0.5f); | ||
pc.SizeEnd = props.SizeEnd; | ||
|
||
RigidBody2DComponent &rbc = particle.AddComponent<RigidBody2DComponent>(); | ||
|
||
rbc.Type = RigidBody2DComponent::BodyType::Dynamic; | ||
rbc.Velocity = props.Velocity; | ||
rbc.Velocity.x += props.VelocityVariation.x * ((float)distribution(engine) - 0.5f); | ||
rbc.Velocity.y += props.VelocityVariation.y * ((float)distribution(engine) - 0.5f); | ||
rbc.GravityScale = 0.0f; | ||
rbc.Mass = 0.0f; | ||
} | ||
} | ||
|
||
/////////////// | ||
// Atributes // | ||
/////////////// | ||
private: | ||
|
||
ParticleProps _SmokeParticle; | ||
ParticleProps _EngineParticle; | ||
|
||
float _Time; | ||
float _SmokeEmitInterval; | ||
float _SmokeNextEmitTime; | ||
}; | ||
}; | ||
|
||
#endif /* !PARTICLE_HPP_ */ |