summaryrefslogtreecommitdiffstats
path: root/include/core/Vector3.hpp
diff options
context:
space:
mode:
authorMarc <marc.gilleron@gmail.com>2021-01-31 19:32:56 +0000
committerGitHub <noreply@github.com>2021-01-31 19:32:56 +0000
commit1aab5e3962e311caebae04f44fff9c4e1cd7d9c0 (patch)
treec55e3435691883c62bed6375c6b236a9715c85c7 /include/core/Vector3.hpp
parent2559c70e274f9239cd29c434ab262c46f6dc8552 (diff)
parent35f78dea5196d4d676946a84c10206a5cb1a1fa0 (diff)
downloadredot-cpp-1aab5e3962e311caebae04f44fff9c4e1cd7d9c0.tar.gz
Merge branch 'master' into master
Diffstat (limited to 'include/core/Vector3.hpp')
-rw-r--r--include/core/Vector3.hpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp
index 2d78f21..5971787 100644
--- a/include/core/Vector3.hpp
+++ b/include/core/Vector3.hpp
@@ -7,7 +7,7 @@
#include "String.hpp"
-#include <cmath>
+#include <Math.hpp>
namespace godot {
@@ -165,8 +165,20 @@ 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 {
+ Vector3 v = *this;
+ Vector3 vd = p_to - v;
+ real_t len = vd.length();
+ return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta;
+ }
+
Vector3 bounce(const Vector3 &p_normal) const {
return -reflect(p_normal);
}
@@ -199,10 +211,20 @@ 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));
}
+ inline Vector3 direction_to(const Vector3 &p_b) const {
+ Vector3 ret(p_b.x - x, p_b.y - y, p_b.z - z);
+ ret.normalize();
+ return ret;
+ }
+
inline Vector3 floor() const {
return Vector3(::floor(x), ::floor(y), ::floor(z));
}
@@ -238,8 +260,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.0);
}
inline Vector3 rotated(const Vector3 &axis, const real_t phi) const {
@@ -251,7 +273,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);