diff options
-rw-r--r-- | core/color.h | 4 | ||||
-rw-r--r-- | core/math/quat.h | 4 | ||||
-rw-r--r-- | core/math/vector2.h | 30 | ||||
-rw-r--r-- | core/variant_op.cpp | 63 |
4 files changed, 98 insertions, 3 deletions
diff --git a/core/color.h b/core/color.h index 096e97e9ae..2dbbc52905 100644 --- a/core/color.h +++ b/core/color.h @@ -234,4 +234,8 @@ bool Color::operator<(const Color &p_color) const { } } +_FORCE_INLINE_ Color operator*(const real_t &p_real, const Color &p_color) { + return p_color * p_real; +} + #endif // COLOR_H diff --git a/core/math/quat.h b/core/math/quat.h index 8619ea3c5c..3152b7d233 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -224,4 +224,8 @@ bool Quat::operator!=(const Quat &p_quat) const { return x != p_quat.x || y != p_quat.y || z != p_quat.z || w != p_quat.w; } +_FORCE_INLINE_ Quat operator*(const real_t &p_real, const Quat &p_quat) { + return p_quat * p_real; +} + #endif // QUAT_H diff --git a/core/math/vector2.h b/core/math/vector2.h index 0966d3392f..f41bcc15bc 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -150,7 +150,19 @@ _FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) return p_vec - *this * (dot(p_vec) - p_d); } -_FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) { +_FORCE_INLINE_ Vector2 operator*(float p_scalar, const Vector2 &p_vec) { + return p_vec * p_scalar; +} + +_FORCE_INLINE_ Vector2 operator*(double p_scalar, const Vector2 &p_vec) { + return p_vec * p_scalar; +} + +_FORCE_INLINE_ Vector2 operator*(int32_t p_scalar, const Vector2 &p_vec) { + return p_vec * p_scalar; +} + +_FORCE_INLINE_ Vector2 operator*(int64_t p_scalar, const Vector2 &p_vec) { return p_vec * p_scalar; } @@ -304,6 +316,22 @@ struct Vector2i { } }; +_FORCE_INLINE_ Vector2i operator*(const int32_t &p_scalar, const Vector2i &p_vector) { + return p_vector * p_scalar; +} + +_FORCE_INLINE_ Vector2i operator*(const int64_t &p_scalar, const Vector2i &p_vector) { + return p_vector * p_scalar; +} + +_FORCE_INLINE_ Vector2i operator*(const float &p_scalar, const Vector2i &p_vector) { + return p_vector * p_scalar; +} + +_FORCE_INLINE_ Vector2i operator*(const double &p_scalar, const Vector2i &p_vector) { + return p_vector * p_scalar; +} + typedef Vector2i Size2i; typedef Vector2i Point2i; diff --git a/core/variant_op.cpp b/core/variant_op.cpp index ec4eea05bf..533b056f91 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -1031,6 +1031,9 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, case FLOAT: { _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._float); } + case INT: { + _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._int); + } default: _RETURN_FAIL; } @@ -1062,8 +1065,64 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } } - DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, INT, *, _int); - DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, FLOAT, *, _float); + CASE_TYPE(math, OP_MULTIPLY, INT) { + if (p_b.type == INT) { + _RETURN(p_a._data._int * p_b._data._int); + } + if (p_b.type == FLOAT) { + _RETURN(p_a._data._int * p_b._data._float); + } + if (p_b.type == VECTOR2) { + _RETURN(p_a._data._int * *reinterpret_cast<const Vector2 *>(p_b._data._mem)); + } + if (p_b.type == VECTOR3) { + _RETURN(p_a._data._int * *reinterpret_cast<const Vector3 *>(p_b._data._mem)); + } + if (p_b.type == VECTOR2I) { + _RETURN(p_a._data._int * *reinterpret_cast<const Vector2i *>(p_b._data._mem)); + } + if (p_b.type == VECTOR3I) { + _RETURN(p_a._data._int * *reinterpret_cast<const Vector3i *>(p_b._data._mem)); + } + if (p_b.type == QUAT) { + _RETURN(p_a._data._int * *reinterpret_cast<const Quat *>(p_b._data._mem)); + } + if (p_b.type == COLOR) { + _RETURN(p_a._data._int * *reinterpret_cast<const Color *>(p_b._data._mem)); + } + + _RETURN_FAIL + } + + CASE_TYPE(math, OP_MULTIPLY, FLOAT) { + if (p_b.type == INT) { + _RETURN(p_a._data._float * p_b._data._int); + } + if (p_b.type == FLOAT) { + _RETURN(p_a._data._float * p_b._data._float); + } + if (p_b.type == VECTOR2) { + _RETURN(p_a._data._float * *reinterpret_cast<const Vector2 *>(p_b._data._mem)); + } + if (p_b.type == VECTOR3) { + _RETURN(p_a._data._float * *reinterpret_cast<const Vector3 *>(p_b._data._mem)); + } + if (p_b.type == VECTOR2I) { + _RETURN(p_a._data._float * *reinterpret_cast<const Vector2i *>(p_b._data._mem)); + } + if (p_b.type == VECTOR3I) { + _RETURN(p_a._data._float * *reinterpret_cast<const Vector3i *>(p_b._data._mem)); + } + if (p_b.type == QUAT) { + _RETURN(p_a._data._float * *reinterpret_cast<const Quat *>(p_b._data._mem)); + } + if (p_b.type == COLOR) { + _RETURN(p_a._data._float * *reinterpret_cast<const Color *>(p_b._data._mem)); + } + + _RETURN_FAIL + } + DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2, *, Vector2); DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2I, *, Vector2i); DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3, *, Vector3); |