aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crepe/system/CollisionSystem.cpp10
-rw-r--r--src/test/CollisionTest.cpp12
2 files changed, 13 insertions, 9 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index 496224e..af8adce 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -193,13 +193,15 @@ CollisionSystem::collision_handler(CollisionInternal & data1, CollisionInternal
} else if (resolution.x != 0) {
resolution_direction = Direction::X_DIRECTION;
//checks if the other velocity has a value and if this object moved
- if (data1.rigidbody.data.linear_velocity.x != 0 && data1.rigidbody.data.linear_velocity.y != 0)
+ if (data1.rigidbody.data.linear_velocity.x != 0
+ && data1.rigidbody.data.linear_velocity.y != 0)
resolution.y = -data1.rigidbody.data.linear_velocity.y
* (resolution.x / data1.rigidbody.data.linear_velocity.x);
} else if (resolution.y != 0) {
resolution_direction = Direction::Y_DIRECTION;
//checks if the other velocity has a value and if this object moved
- if (data1.rigidbody.data.linear_velocity.x != 0 && data1.rigidbody.data.linear_velocity.y != 0)
+ if (data1.rigidbody.data.linear_velocity.x != 0
+ && data1.rigidbody.data.linear_velocity.y != 0)
resolution.x = -data1.rigidbody.data.linear_velocity.x
* (resolution.y / data1.rigidbody.data.linear_velocity.y);
}
@@ -320,7 +322,9 @@ void CollisionSystem::static_collision_handler(CollisionInfo & info) {
case Direction::BOTH:
//bounce
if (info.this_rigidbody.data.elastisity_coefficient > 0) {
- info.this_rigidbody.data.linear_velocity = -info.this_rigidbody.data.linear_velocity * info.this_rigidbody.data.elastisity_coefficient;
+ info.this_rigidbody.data.linear_velocity
+ = -info.this_rigidbody.data.linear_velocity
+ * info.this_rigidbody.data.elastisity_coefficient;
}
//stop movement
else {
diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp
index 5dbc670..2ad65fa 100644
--- a/src/test/CollisionTest.cpp
+++ b/src/test/CollisionTest.cpp
@@ -232,7 +232,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) {
collision_happend = true;
EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, -5);
- EXPECT_EQ(ev.info.resolution.y, -5);
+ EXPECT_EQ(ev.info.resolution.y, 5);
EXPECT_EQ(ev.info.resolution_direction,
crepe::CollisionSystem::Direction::X_DIRECTION);
};
@@ -240,7 +240,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) {
collision_happend = true;
EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
EXPECT_EQ(ev.info.resolution.x, 5);
- EXPECT_EQ(ev.info.resolution.y, 5);
+ EXPECT_EQ(ev.info.resolution.y, -5);
EXPECT_EQ(ev.info.resolution_direction,
crepe::CollisionSystem::Direction::X_DIRECTION);
};
@@ -260,7 +260,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) {
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
- EXPECT_EQ(ev.info.resolution.x, -5);
+ EXPECT_EQ(ev.info.resolution.x, 5);
EXPECT_EQ(ev.info.resolution.y, -5);
EXPECT_EQ(ev.info.resolution_direction,
crepe::CollisionSystem::Direction::Y_DIRECTION);
@@ -268,7 +268,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) {
script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
EXPECT_EQ(ev.info.this_collider.game_object_id, 2);
- EXPECT_EQ(ev.info.resolution.x, 5);
+ EXPECT_EQ(ev.info.resolution.x, -5);
EXPECT_EQ(ev.info.resolution.y, 5);
EXPECT_EQ(ev.info.resolution_direction,
crepe::CollisionSystem::Direction::Y_DIRECTION);
@@ -312,7 +312,7 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) {
collision_happend = true;
EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
EXPECT_EQ(ev.info.resolution.x, -5);
- EXPECT_EQ(ev.info.resolution.y, -5);
+ EXPECT_EQ(ev.info.resolution.y, 5);
EXPECT_EQ(ev.info.resolution_direction,
crepe::CollisionSystem::Direction::X_DIRECTION);
};
@@ -336,7 +336,7 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) {
script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) {
collision_happend = true;
EXPECT_EQ(ev.info.this_collider.game_object_id, 1);
- EXPECT_EQ(ev.info.resolution.x, -5);
+ EXPECT_EQ(ev.info.resolution.x, 5);
EXPECT_EQ(ev.info.resolution.y, -5);
EXPECT_EQ(ev.info.resolution_direction,
crepe::CollisionSystem::Direction::Y_DIRECTION);