From c35e253e2bdb643d1d6b8b0bc9ccb4c8b1c9f5d5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 17 Mar 2024 20:41:54 +0000 Subject: [PATCH 1/3] Update raylib_api.* by CI --- parser/output/raylib_api.json | 14 ++++++++++---- parser/output/raylib_api.lua | 14 ++++++++++---- parser/output/raylib_api.txt | 15 ++++++++++----- parser/output/raylib_api.xml | 11 ++++++----- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/parser/output/raylib_api.json b/parser/output/raylib_api.json index ec8d57a8ce02..427e03779a69 100644 --- a/parser/output/raylib_api.json +++ b/parser/output/raylib_api.json @@ -335,6 +335,12 @@ "type": "UNKNOWN", "value": "SHADER_LOC_MAP_METALNESS", "description": "" + }, + { + "name": "GetMouseRay", + "type": "UNKNOWN", + "value": "GetScreenToWorldRay", + "description": "Compatibility hack for previous raylib versions" } ], "structs": [ @@ -3873,12 +3879,12 @@ }, { "name": "GetScreenToWorldRay", - "description": "Get a ray trace from mouse position", + "description": "Get a ray trace from screen position (i.e mouse)", "returnType": "Ray", "params": [ { "type": "Vector2", - "name": "mousePosition" + "name": "position" }, { "type": "Camera", @@ -3888,12 +3894,12 @@ }, { "name": "GetScreenToWorldRayEx", - "description": "Get a ray trace from mouse position in a viewport", + "description": "Get a ray trace from screen position (i.e mouse) in a viewport", "returnType": "Ray", "params": [ { "type": "Vector2", - "name": "mousePosition" + "name": "position" }, { "type": "Camera", diff --git a/parser/output/raylib_api.lua b/parser/output/raylib_api.lua index 01c1abf307b7..20315afd065e 100644 --- a/parser/output/raylib_api.lua +++ b/parser/output/raylib_api.lua @@ -335,6 +335,12 @@ return { type = "UNKNOWN", value = "SHADER_LOC_MAP_METALNESS", description = "" + }, + { + name = "GetMouseRay", + type = "UNKNOWN", + value = "GetScreenToWorldRay", + description = "Compatibility hack for previous raylib versions" } }, structs = { @@ -3636,19 +3642,19 @@ return { }, { name = "GetScreenToWorldRay", - description = "Get a ray trace from mouse position", + description = "Get a ray trace from screen position (i.e mouse)", returnType = "Ray", params = { - {type = "Vector2", name = "mousePosition"}, + {type = "Vector2", name = "position"}, {type = "Camera", name = "camera"} } }, { name = "GetScreenToWorldRayEx", - description = "Get a ray trace from mouse position in a viewport", + description = "Get a ray trace from screen position (i.e mouse) in a viewport", returnType = "Ray", params = { - {type = "Vector2", name = "mousePosition"}, + {type = "Vector2", name = "position"}, {type = "Camera", name = "camera"}, {type = "float", name = "width"}, {type = "float", name = "height"} diff --git a/parser/output/raylib_api.txt b/parser/output/raylib_api.txt index d49ac33e4f3a..6a1c17c056bc 100644 --- a/parser/output/raylib_api.txt +++ b/parser/output/raylib_api.txt @@ -1,5 +1,5 @@ -Defines found: 56 +Defines found: 57 Define 001: RAYLIB_H Name: RAYLIB_H @@ -281,6 +281,11 @@ Define 056: SHADER_LOC_MAP_SPECULAR Type: UNKNOWN Value: SHADER_LOC_MAP_METALNESS Description: +Define 057: GetMouseRay + Name: GetMouseRay + Type: UNKNOWN + Value: GetScreenToWorldRay + Description: Compatibility hack for previous raylib versions Structures found: 34 @@ -1424,14 +1429,14 @@ Function 083: UnloadShader() (1 input parameters) Function 084: GetScreenToWorldRay() (2 input parameters) Name: GetScreenToWorldRay Return type: Ray - Description: Get a ray trace from mouse position - Param[1]: mousePosition (type: Vector2) + Description: Get a ray trace from screen position (i.e mouse) + Param[1]: position (type: Vector2) Param[2]: camera (type: Camera) Function 085: GetScreenToWorldRayEx() (4 input parameters) Name: GetScreenToWorldRayEx Return type: Ray - Description: Get a ray trace from mouse position in a viewport - Param[1]: mousePosition (type: Vector2) + Description: Get a ray trace from screen position (i.e mouse) in a viewport + Param[1]: position (type: Vector2) Param[2]: camera (type: Camera) Param[3]: width (type: float) Param[4]: height (type: float) diff --git a/parser/output/raylib_api.xml b/parser/output/raylib_api.xml index 45697f24d7ae..c34c4c5ae2e0 100644 --- a/parser/output/raylib_api.xml +++ b/parser/output/raylib_api.xml @@ -1,6 +1,6 @@ - + @@ -57,6 +57,7 @@ + @@ -902,12 +903,12 @@ - - + + - - + + From c1c98513481539ab82a1fed9bb683f77d2e5cdbc Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Tue, 15 Oct 2024 13:31:59 -0700 Subject: [PATCH 2/3] Add math operators for C++ to raymath --- src/raymath.h | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 315 insertions(+) diff --git a/src/raymath.h b/src/raymath.h index 62d52f8fd447..8c8eba2f0f8a 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -2580,4 +2580,319 @@ RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotatio } } + +// optional C++ math operators +// define RAYLIB_DISABLE_VECTOR_OPERATORS to disable +#if defined(__cplusplus) && !defined(RAYLIB_DISABLE_VECTOR_OPERATORS) + +//------------------Vector2-----------------// +static constexpr Vector2 Vector2Zeros = { 0, 0 }; +static constexpr Vector2 Vector2Ones = { 1, 1 }; +static constexpr Vector2 Vector2UnitX = { 1, 0 }; +static constexpr Vector2 Vector2UnitY = { 0, 1 }; + +inline Vector2 operator + (const Vector2& lhs, const Vector2& rhs) +{ + return Vector2Add(lhs, rhs); +} + +inline const Vector2& operator += (Vector2& lhs, const Vector2& rhs) +{ + lhs = Vector2Add(lhs, rhs); + return lhs; +} + +inline Vector2 operator - (const Vector2& lhs, const Vector2& rhs) +{ + return Vector2Subtract(lhs, rhs); +} + +inline const Vector2& operator -= (Vector2& lhs, const Vector2& rhs) +{ + lhs = Vector2Subtract(lhs, rhs); + return lhs; +} + +inline Vector2 operator * (const Vector2& lhs, const float& rhs) +{ + return Vector2Scale(lhs, rhs); +} + +inline const Vector2& operator *= (Vector2& lhs, const float& rhs) +{ + lhs = Vector2Scale(lhs, rhs); + return lhs; +} + +inline Vector2 operator * (const Vector2& lhs, const Vector2& rhs) +{ + return Vector2Multiply(lhs, rhs); +} + +inline const Vector2& operator *= (Vector2& lhs, const Vector2& rhs) +{ + lhs = Vector2Multiply(lhs, rhs); + return lhs; +} + +inline Vector2 operator * (const Vector2& lhs, const Matrix& rhs) +{ + return Vector2Transform(lhs, rhs); +} + +inline const Vector2& operator -= (Vector2& lhs, const Matrix& rhs) +{ + lhs = Vector2Transform(lhs, rhs); + return lhs; +} + +inline Vector2 operator / (const Vector2& lhs, const float& rhs) +{ + return Vector2Scale(lhs, 1.0f / rhs); +} + +inline const Vector2& operator /= (Vector2& lhs, const float& rhs) +{ + lhs = Vector2Scale(lhs, rhs); + return lhs; +} + +inline Vector2 operator / (const Vector2& lhs, const Vector2& rhs) +{ + return Vector2Divide(lhs, rhs); +} + +inline const Vector2& operator /= (Vector2& lhs, const Vector2& rhs) +{ + lhs = Vector2Divide(lhs, rhs); + return lhs; +} + +inline bool operator == (const Vector2& lhs, const Vector2& rhs) +{ + return FloatEquals(lhs.x, rhs.x) && FloatEquals(lhs.y, rhs.y); +} + +inline bool operator != (const Vector2& lhs, const Vector2& rhs) +{ + return !FloatEquals(lhs.x, rhs.x) || !FloatEquals(lhs.y, rhs.y); +} + +//------------------Vector3-----------------// +static constexpr Vector3 Vector3Zeros = { 0, 0, 0 }; +static constexpr Vector3 Vector3Ones = { 1, 1, 1 }; +static constexpr Vector3 Vector3UnitX = { 1, 0, 0 }; +static constexpr Vector3 Vector3UnitY = { 0, 1, 0 }; +static constexpr Vector3 Vector3UnitZ = { 0, 0, 1 }; + +inline Vector3 operator + (const Vector3& lhs, const Vector3& rhs) +{ + return Vector3Add(lhs, rhs); +} + +inline const Vector3& operator += (Vector3& lhs, const Vector3& rhs) +{ + lhs = Vector3Add(lhs, rhs); + return lhs; +} + +inline Vector3 operator - (const Vector3& lhs, const Vector3& rhs) +{ + return Vector3Subtract(lhs, rhs); +} + +inline const Vector3& operator -= (Vector3& lhs, const Vector3& rhs) +{ + lhs = Vector3Subtract(lhs, rhs); + return lhs; +} + +inline Vector3 operator * (const Vector3& lhs, const float& rhs) +{ + return Vector3Scale(lhs, rhs); +} + +inline const Vector3& operator *= (Vector3& lhs, const float& rhs) +{ + lhs = Vector3Scale(lhs, rhs); + return lhs; +} + +inline Vector3 operator * (const Vector3& lhs, const Vector3& rhs) +{ + return Vector3Multiply(lhs, rhs); +} + +inline const Vector3& operator *= (Vector3& lhs, const Vector3& rhs) +{ + lhs = Vector3Multiply(lhs, rhs); + return lhs; +} + +inline Vector3 operator * (const Vector3& lhs, const Matrix& rhs) +{ + return Vector3Transform(lhs, rhs); +} + +inline const Vector3& operator -= (Vector3& lhs, const Matrix& rhs) +{ + lhs = Vector3Transform(lhs, rhs); + return lhs; +} + +inline Vector3 operator / (const Vector3& lhs, const float& rhs) +{ + return Vector3Scale(lhs, 1.0f / rhs); +} + +inline const Vector3& operator /= (Vector3& lhs, const float& rhs) +{ + lhs = Vector3Scale(lhs, rhs); + return lhs; +} + +inline Vector3 operator / (const Vector3& lhs, const Vector3& rhs) +{ + return Vector3Divide(lhs, rhs); +} + +inline const Vector3& operator /= (Vector3& lhs, const Vector3& rhs) +{ + lhs = Vector3Divide(lhs, rhs); + return lhs; +} + +inline bool operator == (const Vector3& lhs, const Vector3& rhs) +{ + return FloatEquals(lhs.x, rhs.x) && FloatEquals(lhs.y, rhs.y) && FloatEquals(lhs.z, rhs.z); +} + +inline bool operator != (const Vector3& lhs, const Vector3& rhs) +{ + return !FloatEquals(lhs.x, rhs.x) || !FloatEquals(lhs.y, rhs.y) || !FloatEquals(lhs.z, rhs.z); +} + +//------------------Vector4-----------------// +static constexpr Vector4 Vector4Zeros = { 0, 0, 0, 0 }; +static constexpr Vector4 Vector4Ones = { 1, 1, 1, 1 }; +static constexpr Vector4 Vector4UnitX = { 1, 0, 0, 0 }; +static constexpr Vector4 Vector4UnitY = { 0, 1, 0, 0 }; +static constexpr Vector4 Vector4UnitZ = { 0, 0, 1, 0 }; +static constexpr Vector4 Vector4UnitW = { 0, 0, 0, 1 }; + +inline Vector4 operator + (const Vector4& lhs, const Vector4& rhs) +{ + return Vector4Add(lhs, rhs); +} + +inline const Vector4& operator += (Vector4& lhs, const Vector4& rhs) +{ + lhs = Vector4Add(lhs, rhs); + return lhs; +} + +inline Vector4 operator - (const Vector4& lhs, const Vector4& rhs) +{ + return Vector4Subtract(lhs, rhs); +} + +inline const Vector4& operator -= (Vector4& lhs, const Vector4& rhs) +{ + lhs = Vector4Subtract(lhs, rhs); + return lhs; +} + +inline Vector4 operator * (const Vector4& lhs, const float& rhs) +{ + return Vector4Scale(lhs, rhs); +} + +inline const Vector4& operator *= (Vector4& lhs, const float& rhs) +{ + lhs = Vector4Scale(lhs, rhs); + return lhs; +} + +inline Vector4 operator * (const Vector4& lhs, const Vector4& rhs) +{ + return Vector4Multiply(lhs, rhs); +} + +inline const Vector4& operator *= (Vector4& lhs, const Vector4& rhs) +{ + lhs = Vector4Multiply(lhs, rhs); + return lhs; +} + +inline Vector4 operator / (const Vector4& lhs, const float& rhs) +{ + return Vector4Scale(lhs, 1.0f / rhs); +} + +inline const Vector4& operator /= (Vector4& lhs, const float& rhs) +{ + lhs = Vector4Scale(lhs, rhs); + return lhs; +} + +inline Vector4 operator / (const Vector4& lhs, const Vector4& rhs) +{ + return Vector4Divide(lhs, rhs); +} + +inline const Vector4& operator /= (Vector4& lhs, const Vector4& rhs) +{ + lhs = Vector4Divide(lhs, rhs); + return lhs; +} + +inline bool operator == (const Vector4& lhs, const Vector4& rhs) +{ + return FloatEquals(lhs.x, rhs.x) && FloatEquals(lhs.y, rhs.y) && FloatEquals(lhs.z, rhs.z) && FloatEquals(lhs.w, rhs.w); +} + +inline bool operator != (const Vector4& lhs, const Vector4& rhs) +{ + return !FloatEquals(lhs.x, rhs.x) || !FloatEquals(lhs.y, rhs.y) || !FloatEquals(lhs.z, rhs.z) || !FloatEquals(lhs.w, rhs.w); +} + +//------------------Quaternion-----------------// +static constexpr Quaternion QuaternionZeros = { 0, 0, 0, 0 }; +static constexpr Quaternion QuaternionOnes = { 1, 1, 1, 1 }; +static constexpr Quaternion QuaternionUnitX = { 0, 0, 0, 1 }; + +inline Quaternion operator + (const Quaternion& lhs, const float& rhs) +{ + return QuaternionAddValue(lhs, rhs); +} + +inline const Quaternion& operator += (Quaternion& lhs, const float& rhs) +{ + lhs = QuaternionAddValue(lhs, rhs); + return lhs; +} + +inline Quaternion operator - (const Quaternion& lhs, const float& rhs) +{ + return QuaternionSubtractValue(lhs, rhs); +} + +inline const Quaternion& operator -= (Quaternion& lhs, const float& rhs) +{ + lhs = QuaternionSubtractValue(lhs, rhs); + return lhs; +} + +inline Quaternion operator * (const Quaternion& lhs, const Matrix& rhs) +{ + return QuaternionTransform(lhs, rhs); +} + +inline const Quaternion& operator *= (Quaternion& lhs, const Matrix& rhs) +{ + lhs = QuaternionTransform(lhs, rhs); + return lhs; +} +#endif // C++ operators + #endif // RAYMATH_H From 6d601738344c9455c78e6da80bb70b009328f134 Mon Sep 17 00:00:00 2001 From: Jeffery Myers Date: Wed, 16 Oct 2024 18:08:36 -0700 Subject: [PATCH 3/3] better #define for disabling C++ operators --- src/raymath.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/raymath.h b/src/raymath.h index 8c8eba2f0f8a..84e1ff806476 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -26,7 +26,9 @@ * #define RAYMATH_STATIC_INLINE * Define static inline functions code, so #include header suffices for use. * This may use up lots of memory. -* +* +* #define RAYMATH_DISABLE_OPERATORS +* Disables C++ operator overloads for raymath types. * * LICENSE: zlib/libpng * @@ -2583,7 +2585,7 @@ RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotatio // optional C++ math operators // define RAYLIB_DISABLE_VECTOR_OPERATORS to disable -#if defined(__cplusplus) && !defined(RAYLIB_DISABLE_VECTOR_OPERATORS) +#if defined(__cplusplus) && !defined(RAYMATH_DISABLE_OPERATORS) //------------------Vector2-----------------// static constexpr Vector2 Vector2Zeros = { 0, 0 };