From a733457285f26dae629e9625fcb13475a28577b7 Mon Sep 17 00:00:00 2001 From: Silver1063 Date: Sun, 11 Oct 2020 15:47:01 -0700 Subject: [PATCH 1/2] Update Vector3 slide to match godot implementation It wasn't the same before and resulted in weird behavior, its better now. --- include/core/Vector3.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index d8790978..16c2a102 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -264,7 +264,7 @@ struct Vector3 { void rotate(const Vector3 &p_axis, real_t p_phi); inline Vector3 slide(const Vector3 &by) const { - return by - *this * this->dot(by); + return *this - by * this->dot(by); } void snap(real_t p_val); From 96ae052e06efc24c02f184e07f21c1213c02e4db Mon Sep 17 00:00:00 2001 From: Silver1063 Date: Sun, 11 Oct 2020 17:31:23 -0700 Subject: [PATCH 2/2] Added missing Vector3 slerp and Vector3 project Vector3 slerp and Vector3 project were missing from godot cpp so I added them. --- include/core/Vector3.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 16c2a102..5971787b 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -165,6 +165,11 @@ struct Vector3 { z + (p_t * (p_b.z - z))); } + inline Vector3 slerp(const Vector3 &p_b, real_t p_t) const { + real_t theta = angle_to(p_b); + return rotated(cross(p_b).normalized(), theta * p_t); + } + Vector3 cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const; Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const { @@ -206,6 +211,10 @@ struct Vector3 { return x * b.x + y * b.y + z * b.z; } + inline Vector3 project(const Vector3 &p_b) const { + return p_b * (dot(p_b) / p_b.length_squared()); + } + inline real_t angle_to(const Vector3 &b) const { return std::atan2(cross(b).length(), dot(b)); }