From a2e6f7a5efab2fcf765429aa6985a6faca750c74 Mon Sep 17 00:00:00 2001 From: NHodgesVFX Date: Tue, 4 Feb 2020 16:33:43 -0500 Subject: [PATCH 1/2] Fix Vector's Bounce Reflect Fixes Vector 2 and 3 bounce and reflect methods to match gdscript Co-Authored-By: Bruno Campos Move calculation to reflect fix commit squash fix style --- include/core/Vector2.hpp | 4 ++-- include/core/Vector3.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 99ac60f..5364330 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -180,8 +180,8 @@ struct Vector2 { return -reflect(p_normal); } - inline Vector2 reflect(const Vector2 &p_vec) const { - return p_vec - *this * this->dot(p_vec) * 2.0; + inline Vector2 reflect(const Vector2 &p_normal) const { + return -(*this -p_normal * this->dot(p_normal) * 2.0); } inline real_t angle() const { diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 2d78f21..8b39113 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -238,8 +238,8 @@ struct Vector3 { return v; } - inline Vector3 reflect(const Vector3 &by) const { - return by - *this * this->dot(by) * 2.f; + inline Vector3 reflect(const Vector3 &p_normal) const { + return -(*this - p_normal * this->dot(p_normal) * 2.f); } inline Vector3 rotated(const Vector3 &axis, const real_t phi) const { From 82476108bab5d59d2fddec97138296d7b9ae4494 Mon Sep 17 00:00:00 2001 From: NHodgesVFX Date: Thu, 6 Feb 2020 18:44:50 -0500 Subject: [PATCH 2/2] Fix Style Issues --- include/core/Vector2.hpp | 2 +- include/core/Vector3.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 5364330..d7c00b5 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -181,7 +181,7 @@ struct Vector2 { } inline Vector2 reflect(const Vector2 &p_normal) const { - return -(*this -p_normal * this->dot(p_normal) * 2.0); + return -(*this - p_normal * this->dot(p_normal) * 2.0); } inline real_t angle() const { diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 8b39113..144e369 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -239,7 +239,7 @@ struct Vector3 { } inline Vector3 reflect(const Vector3 &p_normal) const { - return -(*this - p_normal * this->dot(p_normal) * 2.f); + return -(*this - p_normal * this->dot(p_normal) * 2.0); } inline Vector3 rotated(const Vector3 &axis, const real_t phi) const {