Add some missing Vector4 methods
This commit is contained in:
parent
72b5a4335e
commit
7006f7d693
6 changed files with 75 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1731,8 +1731,12 @@ static void _register_variant_builtin_methods() {
|
|||
bind_method(Vector4, max_axis_index, sarray(), varray());
|
||||
bind_method(Vector4, length, sarray(), varray());
|
||||
bind_method(Vector4, length_squared, sarray(), varray());
|
||||
bind_method(Vector4, sign, sarray(), varray());
|
||||
bind_method(Vector4, abs, sarray(), varray());
|
||||
bind_method(Vector4, sign, sarray(), varray());
|
||||
bind_method(Vector4, floor, sarray(), varray());
|
||||
bind_method(Vector4, ceil, sarray(), varray());
|
||||
bind_method(Vector4, round, sarray(), varray());
|
||||
bind_method(Vector4, lerp, sarray("to", "weight"), varray());
|
||||
bind_method(Vector4, clamp, sarray("min", "max"), varray());
|
||||
bind_method(Vector4, normalized, sarray(), varray());
|
||||
bind_method(Vector4, is_normalized, sarray(), varray());
|
||||
|
|
|
@ -819,6 +819,8 @@ INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Vector2, double, real_t, 2)
|
|||
INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Vector2i, int64_t, int32_t, 2)
|
||||
INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Vector3, double, real_t, 3)
|
||||
INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Vector3i, int64_t, int32_t, 3)
|
||||
INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Vector4, double, real_t, 4)
|
||||
INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Vector4i, int64_t, int32_t, 4)
|
||||
INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Quaternion, double, real_t, 4)
|
||||
INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Color, double, float, 4)
|
||||
|
||||
|
@ -883,6 +885,8 @@ void register_indexed_setters_getters() {
|
|||
REGISTER_INDEXED_MEMBER(Vector2i);
|
||||
REGISTER_INDEXED_MEMBER(Vector3);
|
||||
REGISTER_INDEXED_MEMBER(Vector3i);
|
||||
REGISTER_INDEXED_MEMBER(Vector4);
|
||||
REGISTER_INDEXED_MEMBER(Vector4i);
|
||||
REGISTER_INDEXED_MEMBER(Quaternion);
|
||||
REGISTER_INDEXED_MEMBER(Color);
|
||||
REGISTER_INDEXED_MEMBER(Transform2D);
|
||||
|
|
|
@ -40,6 +40,11 @@
|
|||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="ceil" qualifiers="const">
|
||||
<return type="Vector4" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="clamp" qualifiers="const">
|
||||
<return type="Vector4" />
|
||||
<argument index="0" name="min" type="Vector4" />
|
||||
|
@ -53,6 +58,11 @@
|
|||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="floor" qualifiers="const">
|
||||
<return type="Vector4" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="inverse" qualifiers="const">
|
||||
<return type="Vector4" />
|
||||
<description>
|
||||
|
@ -79,6 +89,13 @@
|
|||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="lerp" qualifiers="const">
|
||||
<return type="Vector4" />
|
||||
<argument index="0" name="to" type="Vector4" />
|
||||
<argument index="1" name="weight" type="float" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="max_axis_index" qualifiers="const">
|
||||
<return type="int" />
|
||||
<description>
|
||||
|
@ -94,6 +111,11 @@
|
|||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="round" qualifiers="const">
|
||||
<return type="Vector4" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="sign" qualifiers="const">
|
||||
<return type="Vector4" />
|
||||
<description>
|
||||
|
@ -217,6 +239,12 @@
|
|||
<description>
|
||||
</description>
|
||||
</operator>
|
||||
<operator name="operator []">
|
||||
<return type="float" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</operator>
|
||||
<operator name="operator unary+">
|
||||
<return type="Vector4" />
|
||||
<description>
|
||||
|
|
|
@ -194,6 +194,12 @@
|
|||
<description>
|
||||
</description>
|
||||
</operator>
|
||||
<operator name="operator []">
|
||||
<return type="int" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</operator>
|
||||
<operator name="operator unary+">
|
||||
<return type="Vector4i" />
|
||||
<description>
|
||||
|
|
Loading…
Add table
Reference in a new issue