-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ParticleEmitter component. #60
Added one to the default scene.
- Loading branch information
1 parent
aac020b
commit e422ff5
Showing
4 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "ParticleEmitter.hpp" | ||
|
||
namespace Component | ||
{ | ||
ParticleEmitter::ParticleEmitter(const TextureRef& p_texture) | ||
: diffuse{p_texture} | ||
, emit_position{glm::vec3(0.f)} | ||
, emit_velocity_min{glm::vec3(-0.5f, 1.f, -0.5f)} | ||
, emit_velocity_max{glm::vec3( 0.5f, 1.f, 0.5f)} | ||
, spawn_period{1.f} | ||
, time_to_next_spawn{0.f} // Spawn on creation. | ||
, spawn_count{3u} | ||
, lifetime{7.f} | ||
, max_particle_count{1000} | ||
, particles{} | ||
{ | ||
particles.reserve(max_particle_count); | ||
} | ||
} |
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,35 @@ | ||
#pragma once | ||
|
||
#include "Component/Texture.hpp" | ||
#include "glm/vec3.hpp" | ||
#include "glm/vec4.hpp" | ||
|
||
#include "Utility/Config.hpp" | ||
|
||
namespace Component | ||
{ | ||
struct Particle | ||
{ | ||
glm::vec4 position; | ||
glm::vec4 velocity; | ||
DeltaTime lifetime; | ||
}; | ||
|
||
class ParticleEmitter | ||
{ | ||
public: | ||
ParticleEmitter(const TextureRef& p_texture); | ||
|
||
TextureRef diffuse; // Texture applied to all the particles. | ||
glm::vec3 emit_position; // Position particles emit from. | ||
glm::vec3 emit_velocity_min; // Minimum starting velocity in m/s. | ||
glm::vec3 emit_velocity_max; // Maximum starting velocity in m/s. | ||
DeltaTime spawn_period; // Duration between particle spawn attempts. | ||
DeltaTime time_to_next_spawn; // Duration remaining to next spawn attempt. | ||
size_t spawn_count; // How many particles to spawn every spawn_period. | ||
DeltaTime lifetime; // Duration in seconds a particle stays alive before being removed. | ||
size_t max_particle_count; // Max number of particles that can be alive concurrently. | ||
|
||
std::vector<Particle> particles; | ||
}; | ||
} |
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