aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crepe/system/ParticleSystem.cpp17
-rw-r--r--src/test/ParticleTest.cpp44
2 files changed, 54 insertions, 7 deletions
diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp
index 85321f0..48fe1d7 100644
--- a/src/crepe/system/ParticleSystem.cpp
+++ b/src/crepe/system/ParticleSystem.cpp
@@ -52,8 +52,10 @@ void ParticleSystem::emit_particle(ParticleEmitter & emitter,const Transform& tr
double min_angle = emitter.data.min_angle;
double max_angle = emitter.data.max_angle;
double random_angle;
-
- if (min_angle <= max_angle) {
+ if(min_angle == max_angle){
+ random_angle = min_angle;
+ }
+ else if (min_angle <= max_angle) {
// Standard range (e.g., 10 to 20 degrees)
double angle_offset = max_angle - min_angle;
random_angle = min_angle + static_cast<double>(std::rand() % static_cast<uint32_t>(angle_offset));
@@ -70,8 +72,15 @@ void ParticleSystem::emit_particle(ParticleEmitter & emitter,const Transform& tr
// Generate a random speed between min_speed and max_speed
double speed_offset = emitter.data.max_speed - emitter.data.min_speed;
- double random_speed = emitter.data.min_speed + static_cast<double>(std::rand() % static_cast<uint32_t>(speed_offset));
-
+ double random_speed = 0.0;
+ if(emitter.data.max_speed == emitter.data.min_speed)
+ {
+ random_speed = emitter.data.min_speed;
+ }
+ else {
+ random_speed = emitter.data.min_speed + static_cast<double>(std::rand() % static_cast<uint32_t>(speed_offset));
+ }
+
// Convert random_angle to radians
double angle_radians = random_angle * DEG_TO_RAD;
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp
index 368a1f6..1b949e3 100644
--- a/src/test/ParticleTest.cpp
+++ b/src/test/ParticleTest.cpp
@@ -74,8 +74,10 @@ TEST_F(ParticlesTest, spawnParticle) {
emitter.data.end_lifespan = 5;
emitter.data.boundary.height = 100;
emitter.data.boundary.width = 100;
- emitter.data.max_speed = 1;
- emitter.data.max_angle = 1;
+ emitter.data.max_speed = 0.1;
+ emitter.data.max_angle = 0.1;
+ emitter.data.max_speed = 10;
+ emitter.data.max_angle = 10;
particle_system.update();
//check if nothing happend
EXPECT_EQ(emitter.data.particles[0].active, 0);
@@ -89,7 +91,7 @@ TEST_F(ParticlesTest, spawnParticle) {
EXPECT_EQ(emitter.data.particles[2].active, 1);
particle_system.update();
EXPECT_EQ(emitter.data.particles[3].active, 1);
-
+
for (auto& particle : emitter.data.particles) {
// Check velocity range
EXPECT_GE(particle.velocity.x, emitter.data.min_speed); // Speed should be greater than or equal to min_speed
@@ -103,3 +105,39 @@ TEST_F(ParticlesTest, spawnParticle) {
}
}
+
+TEST_F(ParticlesTest, moveParticleHorizontal) {
+ Config::get_instance().physics.gravity = 1;
+ ComponentManager & mgr = ComponentManager::get_instance();
+ ParticleEmitter & emitter = mgr.get_components_by_id<ParticleEmitter>(0).front().get();
+ emitter.data.end_lifespan = 100;
+ emitter.data.boundary.height = 100;
+ emitter.data.boundary.width = 100;
+ emitter.data.min_speed = 1;
+ emitter.data.max_speed = 1;
+ emitter.data.max_angle = 0;
+ emitter.data.emission_rate = 1;
+ for (int a = 1; a < emitter.data.boundary.width/2; a++) {
+ particle_system.update();
+ EXPECT_EQ(emitter.data.particles[0].position.x,a);
+ }
+}
+
+
+TEST_F(ParticlesTest, moveParticleVertical) {
+ Config::get_instance().physics.gravity = 1;
+ ComponentManager & mgr = ComponentManager::get_instance();
+ ParticleEmitter & emitter = mgr.get_components_by_id<ParticleEmitter>(0).front().get();
+ emitter.data.end_lifespan = 100;
+ emitter.data.boundary.height = 100;
+ emitter.data.boundary.width = 100;
+ emitter.data.min_speed = 1;
+ emitter.data.max_speed = 1;
+ emitter.data.min_angle = 90;
+ emitter.data.max_angle = 90;
+ emitter.data.emission_rate = 1;
+ for (int a = 1; a < emitter.data.boundary.width/2; a++) {
+ particle_system.update();
+ EXPECT_EQ(emitter.data.particles[0].position.y,a);
+ }
+}