summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2022-07-25 22:49:18 +0200
committerkobewi <kobewi4e@gmail.com>2022-07-26 02:35:42 +0200
commit7006f7d69318f72017bcfbe21d9fb87cb96b5d7d (patch)
tree2f4084c0da9ec47a069a4d83d975d0f98d1a4eba /core/math
parent72b5a4335e914997ef46928034e8371724b29280 (diff)
Add some missing Vector4 methods
Diffstat (limited to 'core/math')
-rw-r--r--core/math/vector4.cpp22
-rw-r--r--core/math/vector4.h15
2 files changed, 32 insertions, 5 deletions
diff --git a/core/math/vector4.cpp b/core/math/vector4.cpp
index c2a6f8ead2..ed42d8bfb9 100644
--- a/core/math/vector4.cpp
+++ b/core/math/vector4.cpp
@@ -50,7 +50,7 @@ Vector4 Vector4::normalized() const {
}
bool Vector4::is_normalized() const {
- return Math::is_equal_approx(length_squared(), 1, (real_t)UNIT_EPSILON); //use less epsilon
+ return Math::is_equal_approx(length_squared(), 1, (real_t)UNIT_EPSILON); // Use less epsilon.
}
Vector4 Vector4::abs() const {
@@ -61,6 +61,26 @@ Vector4 Vector4::sign() const {
return Vector4(SIGN(x), SIGN(y), SIGN(z), SIGN(w));
}
+Vector4 Vector4::floor() const {
+ return Vector4(Math::floor(x), Math::floor(y), Math::floor(z), Math::floor(w));
+}
+
+Vector4 Vector4::ceil() const {
+ return Vector4(Math::ceil(x), Math::ceil(y), Math::ceil(z), Math::ceil(w));
+}
+
+Vector4 Vector4::round() const {
+ return Vector4(Math::round(x), Math::round(y), Math::round(z), Math::round(w));
+}
+
+Vector4 Vector4::lerp(const Vector4 &p_to, const real_t p_weight) const {
+ return Vector4(
+ x + (p_weight * (p_to.x - x)),
+ y + (p_weight * (p_to.y - y)),
+ z + (p_weight * (p_to.z - z)),
+ w + (p_weight * (p_to.w - w)));
+}
+
Vector4 Vector4::inverse() const {
return Vector4(1.0f / x, 1.0f / y, 1.0f / z, 1.0f / w);
}
diff --git a/core/math/vector4.h b/core/math/vector4.h
index 645c51db87..37ddb509d6 100644
--- a/core/math/vector4.h
+++ b/core/math/vector4.h
@@ -54,11 +54,13 @@ struct _NO_DISCARD_ Vector4 {
real_t components[4] = { 0, 0, 0, 0 };
};
- _FORCE_INLINE_ real_t &operator[](int idx) {
- return components[idx];
+ _FORCE_INLINE_ real_t &operator[](const int p_axis) {
+ DEV_ASSERT((unsigned int)p_axis < 4);
+ return components[p_axis];
}
- _FORCE_INLINE_ const real_t &operator[](int idx) const {
- return components[idx];
+ _FORCE_INLINE_ const real_t &operator[](const int p_axis) const {
+ DEV_ASSERT((unsigned int)p_axis < 4);
+ return components[p_axis];
}
_FORCE_INLINE_ real_t length_squared() const;
bool is_equal_approx(const Vector4 &p_vec4) const;
@@ -66,8 +68,13 @@ struct _NO_DISCARD_ Vector4 {
void normalize();
Vector4 normalized() const;
bool is_normalized() const;
+
Vector4 abs() const;
Vector4 sign() const;
+ Vector4 floor() const;
+ Vector4 ceil() const;
+ Vector4 round() const;
+ Vector4 lerp(const Vector4 &p_to, const real_t p_weight) const;
Vector4::Axis min_axis_index() const;
Vector4::Axis max_axis_index() const;