summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2024-11-21 14:54:10 +0200
committerjussi2024-11-21 14:54:10 +0200
commit3d5eeac3d7e73a71cd476afed556e76fd9b5fe07 (patch)
treea518e6c69c64f35183011054ef35d2f86492cf94
parent6317547502e547de399b6d391be1947567a16a0a (diff)
downloadreilua-enhanced-3d5eeac3d7e73a71cd476afed556e76fd9b5fe07.tar.gz
reilua-enhanced-3d5eeac3d7e73a71cd476afed556e76fd9b5fe07.tar.bz2
reilua-enhanced-3d5eeac3d7e73a71cd476afed556e76fd9b5fe07.zip
New raylib 5.5 raymath functions.
-rw-r--r--API.md290
-rw-r--r--ReiLua_API.lua254
-rw-r--r--changelog2
-rw-r--r--include/rmath.h30
-rw-r--r--src/lua_core.c30
-rw-r--r--src/rmath.c480
6 files changed, 1086 insertions, 0 deletions
diff --git a/API.md b/API.md
index 66e0531..717375d 100644
--- a/API.md
+++ b/API.md
@@ -8835,6 +8835,22 @@ Calculate reflected vector to normal
---
+> result = RL.Vector2Min( Vector2 v1, Vector2 v2 )
+
+Get min value for each pair of components
+
+- Success return Vector2
+
+---
+
+> result = RL.Vector2Max( Vector2 v1, Vector2 v2 )
+
+Get max value for each pair of components
+
+- Success return Vector2
+
+---
+
> result = RL.Vector2Rotate( Vector2 v, float angle )
Rotate vector by angle
@@ -8884,6 +8900,18 @@ Check whether two given vectors are almost equal
---
+> result = RL.Vector2Refract( Vector2 v, Vector2 n, float r )
+
+Compute the direction of a refracted ray
+v: normalized direction of the incoming ray
+n: normalized normal vector of the interface of two optical media
+r: ratio of the refractive index of the medium from where the ray comes
+ to the refractive index of the medium on the other side of the surface
+
+- Success return Vector2
+
+---
+
## Math - Vector 3
---
@@ -9089,6 +9117,14 @@ Rotates a vector around an axis
---
+> result = RL.Vector3MoveTowards( Vector3 v, Vector3 target, float maxDistance )
+
+Move Vector towards target
+
+- Success return Vector3
+
+---
+
> result = RL.Vector3Lerp( Vector3 v1, Vector3 v2, float amount )
Calculate linear interpolation between two vectors
@@ -9097,6 +9133,15 @@ Calculate linear interpolation between two vectors
---
+> result = RL.Vector3CubicHermite( Vector3 v1, Vector3 tangent1, Vector3 v2, Vector3 tangent2, float amount )
+
+Calculate cubic hermite interpolation between two vectors and their tangents
+as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
+
+- Success return Vector3
+
+---
+
> result = RL.Vector3Reflect( Vector3 v, Vector3 normal )
Calculate reflected vector to normal
@@ -9185,6 +9230,186 @@ on the other side of the surface
---
+## Math - Vector4
+
+---
+
+> result = RL.Vector4Zero()
+
+Vector with components value 0.0f
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4One()
+
+Vector with components value 1.0f
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Add( Vector4 v1, Vector4 v2 )
+
+Add two vectors
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4AddValue( Vector4 v, float add )
+
+Add vector and float value
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Subtract( Vector4 v1, Vector4 v2 )
+
+Subtract two vectors
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4SubtractValue( Vector4 v, float sub )
+
+Subtract vector by float value
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Length( Vector4 v )
+
+Calculate vector length
+
+- Success return float
+
+---
+
+> result = RL.Vector4LengthSqr( Vector4 v )
+
+Calculate vector square length
+
+- Success return float
+
+---
+
+> result = RL.Vector4DotProduct( Vector4 v1, Vector4 v2 )
+
+Calculate two vectors dot product
+
+- Success return float
+
+---
+
+> result = RL.Vector4Distance( Vector4 v1, Vector4 v2 )
+
+Calculate distance between two vectors
+
+- Success return float
+
+---
+
+> result = RL.Vector4DistanceSqr( Vector4 v1, Vector4 v2 )
+
+Calculate square distance between two vectors
+
+- Success return float
+
+---
+
+> result = RL.Vector4Scale( Vector4 v, float scalar )
+
+Multiply vector by scalar
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Multiply( Vector4 v1, Vector4 v2 )
+
+Multiply vector by vector
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Negate( Vector4 v )
+
+Negate provided vector (invert direction)
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Divide( Vector4 v1, Vector4 v2 )
+
+Divide vector by vector
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Normalize( Vector4 v )
+
+Normalize provided vector
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Min( Vector4 v1, Vector4 v2 )
+
+Get min value for each pair of components
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Max( Vector4 v1, Vector4 v2 )
+
+Get max value for each pair of components
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Lerp( Vector4 v1, Vector4 v2, float amount )
+
+Calculate linear interpolation between two vectors
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4MoveTowards( Vector4 v, Vector4 target, float maxDistance )
+
+Move Vector towards target
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Invert( Vector4 v )
+
+Invert the given vector
+
+- Success return Vector4
+
+---
+
+> result = RL.Vector4Equals( Vector4 v1, Vector4 v2 )
+
+Check whether two given vectors are almost equal
+
+- Success return bool
+
+---
+
## Math - Matrix
---
@@ -9349,6 +9574,14 @@ Get camera look-at matrix (View matrix)
---
+> translation, rotation, scale = RL.MatrixDecompose( Matrix mat )
+
+Decompose a transformation matrix into its rotational, translational and scaling components
+
+- Success return Vector3, Quaternion, Vector3
+
+---
+
## Math - Quaternion
---
@@ -9465,6 +9698,15 @@ Calculates spherical linear interpolation between two quaternions
---
+> result = RL.QuaternionCubicHermiteSpline( Quaternion q1, Quaternion outTangent1, Quaternion q2, Quaternion inTangent2, float t )
+
+Calculate quaternion cubic spline interpolation using Cubic Hermite Spline algorithm
+as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
+
+- Success return Quaternion
+
+---
+
> result = RL.QuaternionFromVector3ToVector3( Vector3 from, Vector3 to )
Calculate quaternion based on the rotation from one vector to another
@@ -10202,6 +10444,28 @@ NOTE: We store current viewport dimensions
---
+> RL.rlSetClipPlanes( float nearPlane, float farPlane )
+
+Set clip planes distances
+
+---
+
+> distance = RL.rlGetCullDistanceNear()
+
+Get cull plane distance near
+
+- Success return float
+
+---
+
+> distance = RL.rlGetCullDistanceFar()
+
+Get cull plane distance far
+
+- Success return float
+
+---
+
## RLGL - Vertex level operations
---
@@ -10407,6 +10671,14 @@ Disable render texture (fbo), return to default framebuffer
---
+> framebuffer = RL.rlGetActiveFramebuffer()
+
+Get the currently active render texture (fbo), 0 for default framebuffer
+
+- Success return int
+
+---
+
> RL.rlActiveDrawBuffers( int count )
Activate multiple draw color buffers
@@ -10419,6 +10691,12 @@ Blit active framebuffer to main framebuffer
---
+> RL.rlBindFramebuffer( int target, int framebuffer )
+
+Bind framebuffer (FBO)
+
+---
+
## RLGL - General render state
---
@@ -10471,6 +10749,12 @@ Disable backface culling
---
+> RL.rlColorMask( bool r, bool g, bool b, bool a )
+
+Color mask control
+
+---
+
> RL.rlSetCullFace( int mode )
Set face culling mode
@@ -10977,6 +11261,12 @@ Set shader value matrix
---
+> RL.rlSetUniformMatrices( int locIndex, Matrix{} mat )
+
+Set shader value matrices
+
+---
+
> RL.rlSetUniformSampler( int locIndex, int textureId )
Set shader value sampler
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index c7d0c8a..b781fd3 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -5884,6 +5884,20 @@ function RL.Vector2Lerp( v1, v2, amount ) end
---@return any result
function RL.Vector2Reflect( v, normal ) end
+---Get min value for each pair of components
+---- Success return Vector2
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector2Min( v1, v2 ) end
+
+---Get max value for each pair of components
+---- Success return Vector2
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector2Max( v1, v2 ) end
+
---Rotate vector by angle
---- Success return Vector2
---@param v table
@@ -5929,6 +5943,18 @@ function RL.Vector2ClampValue( v, min, max ) end
---@return any result
function RL.Vector2Equals( v1, v2 ) end
+---Compute the direction of a refracted ray
+---v: normalized direction of the incoming ray
+---n: normalized normal vector of the interface of two optical media
+---r: ratio of the refractive index of the medium from where the ray comes
+--- to the refractive index of the medium on the other side of the surface
+---- Success return Vector2
+---@param v table
+---@param n table
+---@param r number
+---@return any result
+function RL.Vector2Refract( v, n, r ) end
+
-- Math - Vector 3
---Vector with components value 0.0f
@@ -6100,6 +6126,14 @@ function RL.Vector3RotateByQuaternion( v, q ) end
---@return any result
function RL.Vector3RotateByAxisAngle( v, axis, angle ) end
+---Move Vector towards target
+---- Success return Vector3
+---@param v table
+---@param target table
+---@param maxDistance number
+---@return any result
+function RL.Vector3MoveTowards( v, target, maxDistance ) end
+
---Calculate linear interpolation between two vectors
---- Success return Vector3
---@param v1 table
@@ -6108,6 +6142,17 @@ function RL.Vector3RotateByAxisAngle( v, axis, angle ) end
---@return any result
function RL.Vector3Lerp( v1, v2, amount ) end
+---Calculate cubic hermite interpolation between two vectors and their tangents
+---as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
+---- Success return Vector3
+---@param v1 table
+---@param tangent1 table
+---@param v2 table
+---@param tangent2 table
+---@param amount number
+---@return any result
+function RL.Vector3CubicHermite( v1, tangent1, v2, tangent2, amount ) end
+
---Calculate reflected vector to normal
---- Success return Vector3
---@param v table
@@ -6191,6 +6236,155 @@ function RL.Vector3Equals( v1, v2 ) end
---@return any result
function RL.Vector3Refract( v, n, r ) end
+-- Math - Vector4
+
+---Vector with components value 0.0f
+---- Success return Vector4
+---@return any result
+function RL.Vector4Zero() end
+
+---Vector with components value 1.0f
+---- Success return Vector4
+---@return any result
+function RL.Vector4One() end
+
+---Add two vectors
+---- Success return Vector4
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4Add( v1, v2 ) end
+
+---Add vector and float value
+---- Success return Vector4
+---@param v table
+---@param add number
+---@return any result
+function RL.Vector4AddValue( v, add ) end
+
+---Subtract two vectors
+---- Success return Vector4
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4Subtract( v1, v2 ) end
+
+---Subtract vector by float value
+---- Success return Vector4
+---@param v table
+---@param sub number
+---@return any result
+function RL.Vector4SubtractValue( v, sub ) end
+
+---Calculate vector length
+---- Success return float
+---@param v table
+---@return any result
+function RL.Vector4Length( v ) end
+
+---Calculate vector square length
+---- Success return float
+---@param v table
+---@return any result
+function RL.Vector4LengthSqr( v ) end
+
+---Calculate two vectors dot product
+---- Success return float
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4DotProduct( v1, v2 ) end
+
+---Calculate distance between two vectors
+---- Success return float
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4Distance( v1, v2 ) end
+
+---Calculate square distance between two vectors
+---- Success return float
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4DistanceSqr( v1, v2 ) end
+
+---Multiply vector by scalar
+---- Success return Vector4
+---@param v table
+---@param scalar number
+---@return any result
+function RL.Vector4Scale( v, scalar ) end
+
+---Multiply vector by vector
+---- Success return Vector4
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4Multiply( v1, v2 ) end
+
+---Negate provided vector (invert direction)
+---- Success return Vector4
+---@param v table
+---@return any result
+function RL.Vector4Negate( v ) end
+
+---Divide vector by vector
+---- Success return Vector4
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4Divide( v1, v2 ) end
+
+---Normalize provided vector
+---- Success return Vector4
+---@param v table
+---@return any result
+function RL.Vector4Normalize( v ) end
+
+---Get min value for each pair of components
+---- Success return Vector4
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4Min( v1, v2 ) end
+
+---Get max value for each pair of components
+---- Success return Vector4
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4Max( v1, v2 ) end
+
+---Calculate linear interpolation between two vectors
+---- Success return Vector4
+---@param v1 table
+---@param v2 table
+---@param amount number
+---@return any result
+function RL.Vector4Lerp( v1, v2, amount ) end
+
+---Move Vector towards target
+---- Success return Vector4
+---@param v table
+---@param target table
+---@param maxDistance number
+---@return any result
+function RL.Vector4MoveTowards( v, target, maxDistance ) end
+
+---Invert the given vector
+---- Success return Vector4
+---@param v table
+---@return any result
+function RL.Vector4Invert( v ) end
+
+---Check whether two given vectors are almost equal
+---- Success return bool
+---@param v1 table
+---@param v2 table
+---@return any result
+function RL.Vector4Equals( v1, v2 ) end
+
-- Math - Matrix
---Compute matrix determinant
@@ -6331,6 +6525,14 @@ function RL.MatrixOrtho( left, right, bottom, top, near, far ) end
---@return any result
function RL.MatrixLookAt( eye, target, up ) end
+---Decompose a transformation matrix into its rotational, translational and scaling components
+---- Success return Vector3, Quaternion, Vector3
+---@param mat table
+---@return any translation
+---@return any rotation
+---@return any scale
+function RL.MatrixDecompose( mat ) end
+
-- Math - Quaternion
---Add two quaternions
@@ -6429,6 +6631,17 @@ function RL.QuaternionNlerp( q1, q2, amount ) end
---@return any result
function RL.QuaternionSlerp( q1, q2, amount ) end
+---Calculate quaternion cubic spline interpolation using Cubic Hermite Spline algorithm
+---as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
+---- Success return Quaternion
+---@param q1 table
+---@param outTangent1 table
+---@param q2 table
+---@param inTangent2 table
+---@param t number
+---@return any result
+function RL.QuaternionCubicHermiteSpline( q1, outTangent1, q2, inTangent2, t ) end
+
---Calculate quaternion based on the rotation from one vector to another
---- Success return Quaternion
---@param from table
@@ -7138,6 +7351,22 @@ function RL.rlOrtho( left, right, bottom, top, znear, zfar ) end
---@return any RL.rlViewport
function RL.rlViewport( viewport ) end
+---Set clip planes distances
+---@param nearPlane number
+---@param farPlane number
+---@return any RL.rlSetClipPlanes
+function RL.rlSetClipPlanes( nearPlane, farPlane ) end
+
+---Get cull plane distance near
+---- Success return float
+---@return any distance
+function RL.rlGetCullDistanceNear() end
+
+---Get cull plane distance far
+---- Success return float
+---@return any distance
+function RL.rlGetCullDistanceFar() end
+
-- RLGL - Vertex level operations
---Initialize drawing mode (how to organize vertex)
@@ -7298,6 +7527,11 @@ function RL.rlEnableFramebuffer( id ) end
---@return any RL.rlDisableFramebuffer
function RL.rlDisableFramebuffer() end
+---Get the currently active render texture (fbo), 0 for default framebuffer
+---- Success return int
+---@return any framebuffer
+function RL.rlGetActiveFramebuffer() end
+
---Activate multiple draw color buffers
---@param count integer
---@return any RL.rlActiveDrawBuffers
@@ -7310,6 +7544,12 @@ function RL.rlActiveDrawBuffers( count ) end
---@return any RL.rlBlitFramebuffer
function RL.rlBlitFramebuffer( srcRect, dstRect, bufferMask ) end
+---Bind framebuffer (FBO)
+---@param target integer
+---@param framebuffer integer
+---@return any RL.rlBindFramebuffer
+function RL.rlBindFramebuffer( target, framebuffer ) end
+
-- RLGL - General render state
---Enable color blending
@@ -7344,6 +7584,14 @@ function RL.rlEnableBackfaceCulling() end
---@return any RL.rlDisableBackfaceCulling
function RL.rlDisableBackfaceCulling() end
+---Color mask control
+---@param r boolean
+---@param g boolean
+---@param b boolean
+---@param a boolean
+---@return any RL.rlColorMask
+function RL.rlColorMask( r, g, b, a ) end
+
---Set face culling mode
---@param mode integer
---@return any RL.rlSetCullFace
@@ -7777,6 +8025,12 @@ function RL.rlSetUniform( locIndex, value, uniformType, count ) end
---@return any RL.rlSetUniformMatrix
function RL.rlSetUniformMatrix( locIndex, mat ) end
+---Set shader value matrices
+---@param locIndex integer
+---@param mat table
+---@return any RL.rlSetUniformMatrices
+function RL.rlSetUniformMatrices( locIndex, mat ) end
+
---Set shader value sampler
---@param locIndex integer
---@param textureId integer
diff --git a/changelog b/changelog
index b6cabf4..3465f39 100644
--- a/changelog
+++ b/changelog
@@ -20,6 +20,8 @@ DETAILED CHANGES:
- ADDED: DrawModelPoints, DrawModelPointsEx, ExportMeshAsCode and UpdateModelAnimationBones.
- ADDED: rlSetClipPlanes, rlGetCullDistanceNear, rlGetCullDistanceFar, rlGetActiveFramebuffer,
rlBindFramebuffer, rlColorMask and rlSetUniformMatrices.
+ - ADDED: Vector2Min, Vector2Max, Vector2Refract, Vector3MoveTowards, Vector3CubicHermite,
+ QuaternionCubicHermiteSpline, MatrixDecompose and Vector4* functions.
------------------------------------------------------------------------
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0
diff --git a/include/rmath.h b/include/rmath.h
index 07132aa..20c4049 100644
--- a/include/rmath.h
+++ b/include/rmath.h
@@ -34,12 +34,15 @@ int lmathVector2Normalize( lua_State* L );
int lmathVector2Transform( lua_State* L );
int lmathVector2Lerp( lua_State* L );
int lmathVector2Reflect( lua_State* L );
+int lmathVector2Min( lua_State* L );
+int lmathVector2Max( lua_State* L );
int lmathVector2Rotate( lua_State* L );
int lmathVector2MoveTowards( lua_State* L );
int lmathVector2Invert( lua_State* L );
int lmathVector2Clamp( lua_State* L );
int lmathVector2ClampValue( lua_State* L );
int lmathVector2Equals( lua_State* L );
+int lmathVector2Refract( lua_State* L );
/* Vector3. */
int lmathVector3Zero( lua_State* L );
int lmathVector3One( lua_State* L );
@@ -66,7 +69,9 @@ int lmathVector3OrthoNormalize( lua_State* L );
int lmathVector3Transform( lua_State* L );
int lmathVector3RotateByQuaternion( lua_State* L );
int lmathVector3RotateByAxisAngle( lua_State* L );
+int lmathVector3MoveTowards( lua_State* L );
int lmathVector3Lerp( lua_State* L );
+int lmathVector3CubicHermite( lua_State* L );
int lmathVector3Reflect( lua_State* L );
int lmathVector3Min( lua_State* L );
int lmathVector3Max( lua_State* L );
@@ -77,6 +82,29 @@ int lmathVector3Clamp( lua_State* L );
int lmathVector3ClampValue( lua_State* L );
int lmathVector3Equals( lua_State* L );
int lmathVector3Refract( lua_State* L );
+/* Vector4. */
+int lmathVector4Zero( lua_State* L );
+int lmathVector4One( lua_State* L );
+int lmathVector4Add( lua_State* L );
+int lmathVector4AddValue( lua_State* L );
+int lmathVector4Subtract( lua_State* L );
+int lmathVector4SubtractValue( lua_State* L );
+int lmathVector4Length( lua_State* L );
+int lmathVector4LengthSqr( lua_State* L );
+int lmathVector4DotProduct( lua_State* L );
+int lmathVector4Distance( lua_State* L );
+int lmathVector4DistanceSqr( lua_State* L );
+int lmathVector4Scale( lua_State* L );
+int lmathVector4Multiply( lua_State* L );
+int lmathVector4Negate( lua_State* L );
+int lmathVector4Divide( lua_State* L );
+int lmathVector4Normalize( lua_State* L );
+int lmathVector4Min( lua_State* L );
+int lmathVector4Max( lua_State* L );
+int lmathVector4Lerp( lua_State* L );
+int lmathVector4MoveTowards( lua_State* L );
+int lmathVector4Invert( lua_State* L );
+int lmathVector4Equals( lua_State* L );
/* Matrix. */
int lmathMatrixDeterminant( lua_State* L );
int lmathMatrixTrace( lua_State* L );
@@ -98,6 +126,7 @@ int lmathMatrixFrustum( lua_State* L );
int lmathMatrixPerspective( lua_State* L );
int lmathMatrixOrtho( lua_State* L );
int lmathMatrixLookAt( lua_State* L );
+int lmathMatrixDecompose( lua_State* L );
/* Quaternion. */
int lmathQuaternionAdd( lua_State* L );
int lmathQuaternionAddValue( lua_State* L );
@@ -113,6 +142,7 @@ int lmathQuaternionDivide( lua_State* L );
int lmathQuaternionLerp( lua_State* L );
int lmathQuaternionNlerp( lua_State* L );
int lmathQuaternionSlerp( lua_State* L );
+int lmathQuaternionCubicHermiteSpline( lua_State* L );
int lmathQuaternionFromVector3ToVector3( lua_State* L );
int lmathQuaternionFromMatrix( lua_State* L );
int lmathQuaternionToMatrix( lua_State* L );
diff --git a/src/lua_core.c b/src/lua_core.c
index cdaa4d0..7150d6d 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -2005,12 +2005,15 @@ void luaRegister() {
assingGlobalFunction( "Vector2Transform", lmathVector2Transform );
assingGlobalFunction( "Vector2Lerp", lmathVector2Lerp );
assingGlobalFunction( "Vector2Reflect", lmathVector2Reflect );
+ assingGlobalFunction( "Vector2Min", lmathVector2Min );
+ assingGlobalFunction( "Vector2Max", lmathVector2Max );
assingGlobalFunction( "Vector2Rotate", lmathVector2Rotate );
assingGlobalFunction( "Vector2MoveTowards", lmathVector2MoveTowards );
assingGlobalFunction( "Vector2Invert", lmathVector2Invert );
assingGlobalFunction( "Vector2Clamp", lmathVector2Clamp );
assingGlobalFunction( "Vector2ClampValue", lmathVector2ClampValue );
assingGlobalFunction( "Vector2Equals", lmathVector2Equals );
+ assingGlobalFunction( "Vector2Refract", lmathVector2Refract );
/* Vector3. */
assingGlobalFunction( "Vector3Zero", lmathVector3Zero );
assingGlobalFunction( "Vector3One", lmathVector3One );
@@ -2037,7 +2040,9 @@ void luaRegister() {
assingGlobalFunction( "Vector3Transform", lmathVector3Transform );
assingGlobalFunction( "Vector3RotateByQuaternion", lmathVector3RotateByQuaternion );
assingGlobalFunction( "Vector3RotateByAxisAngle", lmathVector3RotateByAxisAngle );
+ assingGlobalFunction( "Vector3MoveTowards", lmathVector3MoveTowards );
assingGlobalFunction( "Vector3Lerp", lmathVector3Lerp );
+ assingGlobalFunction( "Vector3CubicHermite", lmathVector3CubicHermite );
assingGlobalFunction( "Vector3Reflect", lmathVector3Reflect );
assingGlobalFunction( "Vector3Min", lmathVector3Min );
assingGlobalFunction( "Vector3Max", lmathVector3Max );
@@ -2048,6 +2053,29 @@ void luaRegister() {
assingGlobalFunction( "Vector3ClampValue", lmathVector3ClampValue );
assingGlobalFunction( "Vector3Equals", lmathVector3Equals );
assingGlobalFunction( "Vector3Refract", lmathVector3Refract );
+ /* Vector4. */
+ assingGlobalFunction( "Vector4Zero", lmathVector4Zero );
+ assingGlobalFunction( "Vector4One", lmathVector4One );
+ assingGlobalFunction( "Vector4Add", lmathVector4Add );
+ assingGlobalFunction( "Vector4AddValue", lmathVector4AddValue );
+ assingGlobalFunction( "Vector4Subtract", lmathVector4Subtract );
+ assingGlobalFunction( "Vector4SubtractValue", lmathVector4SubtractValue );
+ assingGlobalFunction( "Vector4Length", lmathVector4Length );
+ assingGlobalFunction( "Vector4LengthSqr", lmathVector4LengthSqr );
+ assingGlobalFunction( "Vector4DotProduct", lmathVector4DotProduct );
+ assingGlobalFunction( "Vector4Distance", lmathVector4Distance );
+ assingGlobalFunction( "Vector4DistanceSqr", lmathVector4DistanceSqr );
+ assingGlobalFunction( "Vector4Scale", lmathVector4Scale );
+ assingGlobalFunction( "Vector4Multiply", lmathVector4Multiply );
+ assingGlobalFunction( "Vector4Negate", lmathVector4Negate );
+ assingGlobalFunction( "Vector4Divide", lmathVector4Divide );
+ assingGlobalFunction( "Vector4Normalize", lmathVector4Normalize );
+ assingGlobalFunction( "Vector4Min", lmathVector4Min );
+ assingGlobalFunction( "Vector4Max", lmathVector4Max );
+ assingGlobalFunction( "Vector4Lerp", lmathVector4Lerp );
+ assingGlobalFunction( "Vector4MoveTowards", lmathVector4MoveTowards );
+ assingGlobalFunction( "Vector4Invert", lmathVector4Invert );
+ assingGlobalFunction( "Vector4Equals", lmathVector4Equals );
/* Matrix. */
assingGlobalFunction( "MatrixDeterminant", lmathMatrixDeterminant );
assingGlobalFunction( "MatrixTrace", lmathMatrixTrace );
@@ -2069,6 +2097,7 @@ void luaRegister() {
assingGlobalFunction( "MatrixPerspective", lmathMatrixPerspective );
assingGlobalFunction( "MatrixOrtho", lmathMatrixOrtho );
assingGlobalFunction( "MatrixLookAt", lmathMatrixLookAt );
+ assingGlobalFunction( "MatrixDecompose", lmathMatrixDecompose );
/* Quaternion. */
assingGlobalFunction( "QuaternionAdd", lmathQuaternionAdd );
assingGlobalFunction( "QuaternionAddValue", lmathQuaternionAddValue );
@@ -2084,6 +2113,7 @@ void luaRegister() {
assingGlobalFunction( "QuaternionLerp", lmathQuaternionLerp );
assingGlobalFunction( "QuaternionNlerp", lmathQuaternionNlerp );
assingGlobalFunction( "QuaternionSlerp", lmathQuaternionSlerp );
+ assingGlobalFunction( "QuaternionCubicHermiteSpline", lmathQuaternionCubicHermiteSpline );
assingGlobalFunction( "QuaternionFromVector3ToVector3", lmathQuaternionFromVector3ToVector3 );
assingGlobalFunction( "QuaternionFromMatrix", lmathQuaternionFromMatrix );
assingGlobalFunction( "QuaternionToMatrix", lmathQuaternionToMatrix );
diff --git a/src/rmath.c b/src/rmath.c
index 15d5323..40e8cb8 100644
--- a/src/rmath.c
+++ b/src/rmath.c
@@ -483,6 +483,38 @@ int lmathVector2Reflect( lua_State* L ) {
}
/*
+> result = RL.Vector2Min( Vector2 v1, Vector2 v2 )
+
+Get min value for each pair of components
+
+- Success return Vector2
+*/
+int lmathVector2Min( lua_State* L ) {
+ Vector2 v1 = uluaGetVector2( L, 1 );
+ Vector2 v2 = uluaGetVector2( L, 2 );
+
+ uluaPushVector2( L, Vector2Min( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector2Max( Vector2 v1, Vector2 v2 )
+
+Get max value for each pair of components
+
+- Success return Vector2
+*/
+int lmathVector2Max( lua_State* L ) {
+ Vector2 v1 = uluaGetVector2( L, 1 );
+ Vector2 v2 = uluaGetVector2( L, 2 );
+
+ uluaPushVector2( L, Vector2Max( v1, v2 ) );
+
+ return 1;
+}
+
+/*
> result = RL.Vector2Rotate( Vector2 v, float angle )
Rotate vector by angle
@@ -582,6 +614,27 @@ int lmathVector2Equals( lua_State* L ) {
}
/*
+> result = RL.Vector2Refract( Vector2 v, Vector2 n, float r )
+
+Compute the direction of a refracted ray
+v: normalized direction of the incoming ray
+n: normalized normal vector of the interface of two optical media
+r: ratio of the refractive index of the medium from where the ray comes
+ to the refractive index of the medium on the other side of the surface
+
+- Success return Vector2
+*/
+int lmathVector2Refract( lua_State* L ) {
+ Vector2 v = uluaGetVector2( L, 1 );
+ Vector2 n = uluaGetVector2( L, 2 );
+ float r = luaL_checknumber( L, 3 );
+
+ uluaPushVector2( L, Vector2Refract( v, n, r ) );
+
+ return 1;
+}
+
+/*
## Math - Vector 3
*/
@@ -980,6 +1033,23 @@ int lmathVector3RotateByAxisAngle( lua_State* L ) {
}
/*
+> result = RL.Vector3MoveTowards( Vector3 v, Vector3 target, float maxDistance )
+
+Move Vector towards target
+
+- Success return Vector3
+*/
+int lmathVector3MoveTowards( lua_State* L ) {
+ Vector3 v = uluaGetVector3( L, 1 );
+ Vector3 target = uluaGetVector3( L, 2 );
+ float maxDistance = luaL_checknumber( L, 3 );
+
+ uluaPushVector3( L, Vector3MoveTowards( v, target, maxDistance ) );
+
+ return 1;
+}
+
+/*
> result = RL.Vector3Lerp( Vector3 v1, Vector3 v2, float amount )
Calculate linear interpolation between two vectors
@@ -997,6 +1067,26 @@ int lmathVector3Lerp( lua_State* L ) {
}
/*
+> result = RL.Vector3CubicHermite( Vector3 v1, Vector3 tangent1, Vector3 v2, Vector3 tangent2, float amount )
+
+Calculate cubic hermite interpolation between two vectors and their tangents
+as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
+
+- Success return Vector3
+*/
+int lmathVector3CubicHermite( lua_State* L ) {
+ Vector3 v1 = uluaGetVector3( L, 1 );
+ Vector3 tangent1 = uluaGetVector3( L, 2 );
+ Vector3 v2 = uluaGetVector3( L, 3 );
+ Vector3 tangent2 = uluaGetVector3( L, 4 );
+ float amount = luaL_checknumber( L, 5 );
+
+ uluaPushVector3( L, Vector3CubicHermite( v1, tangent1, v2, tangent2, amount ) );
+
+ return 1;
+}
+
+/*
> result = RL.Vector3Reflect( Vector3 v, Vector3 normal )
Calculate reflected vector to normal
@@ -1170,6 +1260,353 @@ int lmathVector3Refract( lua_State* L ) {
}
/*
+## Math - Vector4
+*/
+
+/*
+> result = RL.Vector4Zero()
+
+Vector with components value 0.0f
+
+- Success return Vector4
+*/
+int lmathVector4Zero( lua_State* L ) {
+ uluaPushVector4( L, Vector4Zero() );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4One()
+
+Vector with components value 1.0f
+
+- Success return Vector4
+*/
+int lmathVector4One( lua_State* L ) {
+ uluaPushVector4( L, Vector4One() );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Add( Vector4 v1, Vector4 v2 )
+
+Add two vectors
+
+- Success return Vector4
+*/
+int lmathVector4Add( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ uluaPushVector4( L, Vector4Add( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4AddValue( Vector4 v, float add )
+
+Add vector and float value
+
+- Success return Vector4
+*/
+int lmathVector4AddValue( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+ float add = luaL_checknumber( L, 2 );
+
+ uluaPushVector4( L, Vector4AddValue( v, add ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Subtract( Vector4 v1, Vector4 v2 )
+
+Subtract two vectors
+
+- Success return Vector4
+*/
+int lmathVector4Subtract( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ uluaPushVector4( L, Vector4Subtract( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4SubtractValue( Vector4 v, float sub )
+
+Subtract vector by float value
+
+- Success return Vector4
+*/
+int lmathVector4SubtractValue( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+ float sub = luaL_checknumber( L, 2 );
+
+ uluaPushVector4( L, Vector4SubtractValue( v, sub ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Length( Vector4 v )
+
+Calculate vector length
+
+- Success return float
+*/
+int lmathVector4Length( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+
+ lua_pushnumber( L, Vector4Length( v ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4LengthSqr( Vector4 v )
+
+Calculate vector square length
+
+- Success return float
+*/
+int lmathVector4LengthSqr( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+
+ lua_pushnumber( L, Vector4LengthSqr( v ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4DotProduct( Vector4 v1, Vector4 v2 )
+
+Calculate two vectors dot product
+
+- Success return float
+*/
+int lmathVector4DotProduct( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ lua_pushnumber( L, Vector4DotProduct( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Distance( Vector4 v1, Vector4 v2 )
+
+Calculate distance between two vectors
+
+- Success return float
+*/
+int lmathVector4Distance( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ lua_pushnumber( L, Vector4Distance( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4DistanceSqr( Vector4 v1, Vector4 v2 )
+
+Calculate square distance between two vectors
+
+- Success return float
+*/
+int lmathVector4DistanceSqr( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ lua_pushnumber( L, Vector4DistanceSqr( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Scale( Vector4 v, float scalar )
+
+Multiply vector by scalar
+
+- Success return Vector4
+*/
+int lmathVector4Scale( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+ float scalar = luaL_checknumber( L, 2 );
+
+ uluaPushVector4( L, Vector4Scale( v, scalar ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Multiply( Vector4 v1, Vector4 v2 )
+
+Multiply vector by vector
+
+- Success return Vector4
+*/
+int lmathVector4Multiply( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ uluaPushVector4( L, Vector4Multiply( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Negate( Vector4 v )
+
+Negate provided vector (invert direction)
+
+- Success return Vector4
+*/
+int lmathVector4Negate( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+
+ uluaPushVector4( L, Vector4Negate( v ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Divide( Vector4 v1, Vector4 v2 )
+
+Divide vector by vector
+
+- Success return Vector4
+*/
+int lmathVector4Divide( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ uluaPushVector4( L, Vector4Divide( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Normalize( Vector4 v )
+
+Normalize provided vector
+
+- Success return Vector4
+*/
+int lmathVector4Normalize( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+
+ uluaPushVector4( L, Vector4Normalize( v ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Min( Vector4 v1, Vector4 v2 )
+
+Get min value for each pair of components
+
+- Success return Vector4
+*/
+int lmathVector4Min( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ uluaPushVector4( L, Vector4Min( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Max( Vector4 v1, Vector4 v2 )
+
+Get max value for each pair of components
+
+- Success return Vector4
+*/
+int lmathVector4Max( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ uluaPushVector4( L, Vector4Max( v1, v2 ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Lerp( Vector4 v1, Vector4 v2, float amount )
+
+Calculate linear interpolation between two vectors
+
+- Success return Vector4
+*/
+int lmathVector4Lerp( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+ float amount = luaL_checknumber( L, 3 );
+
+ uluaPushVector4( L, Vector4Lerp( v1, v2, amount ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4MoveTowards( Vector4 v, Vector4 target, float maxDistance )
+
+Move Vector towards target
+
+- Success return Vector4
+*/
+int lmathVector4MoveTowards( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+ Vector4 target = uluaGetVector4( L, 2 );
+ float maxDistance = luaL_checknumber( L, 3 );
+
+ uluaPushVector4( L, Vector4MoveTowards( v, target, maxDistance ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Invert( Vector4 v )
+
+Invert the given vector
+
+- Success return Vector4
+*/
+int lmathVector4Invert( lua_State* L ) {
+ Vector4 v = uluaGetVector4( L, 1 );
+
+ uluaPushVector4( L, Vector4Invert( v ) );
+
+ return 1;
+}
+
+/*
+> result = RL.Vector4Equals( Vector4 v1, Vector4 v2 )
+
+Check whether two given vectors are almost equal
+
+- Success return bool
+*/
+int lmathVector4Equals( lua_State* L ) {
+ Vector4 v1 = uluaGetVector4( L, 1 );
+ Vector4 v2 = uluaGetVector4( L, 2 );
+
+ lua_pushboolean( L, Vector4Equals( v1, v2 ) == 1 );
+
+ return 1;
+}
+
+/*
## Math - Matrix
*/
@@ -1491,6 +1928,29 @@ int lmathMatrixLookAt( lua_State* L ) {
}
/*
+> translation, rotation, scale = RL.MatrixDecompose( Matrix mat )
+
+Decompose a transformation matrix into its rotational, translational and scaling components
+
+- Success return Vector3, Quaternion, Vector3
+*/
+int lmathMatrixDecompose( lua_State* L ) {
+ Matrix mat = uluaGetMatrix( L, 1 );
+
+ Vector3 translation = { 0 };
+ Quaternion rotation = { 0 };
+ Vector3 scale = { 0 };
+
+ MatrixDecompose( mat, &translation, &rotation, &scale );
+
+ uluaPushVector3( L, translation );
+ uluaPushQuaternion( L, rotation );
+ uluaPushVector3( L, scale );
+
+ return 3;
+}
+
+/*
## Math - Quaternion
*/
@@ -1716,6 +2176,26 @@ int lmathQuaternionSlerp( lua_State* L ) {
}
/*
+> result = RL.QuaternionCubicHermiteSpline( Quaternion q1, Quaternion outTangent1, Quaternion q2, Quaternion inTangent2, float t )
+
+Calculate quaternion cubic spline interpolation using Cubic Hermite Spline algorithm
+as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
+
+- Success return Quaternion
+*/
+int lmathQuaternionCubicHermiteSpline( lua_State* L ) {
+ Quaternion q1 = uluaGetQuaternion( L, 1 );
+ Quaternion outTangent1 = uluaGetQuaternion( L, 2 );
+ Quaternion q2 = uluaGetQuaternion( L, 3 );
+ Quaternion inTangent2 = uluaGetQuaternion( L, 4 );
+ float t = luaL_checknumber( L, 5 );
+
+ uluaPushQuaternion( L, QuaternionCubicHermiteSpline( q1, outTangent1, q2, inTangent2, t ) );
+
+ return 1;
+}
+
+/*
> result = RL.QuaternionFromVector3ToVector3( Vector3 from, Vector3 to )
Calculate quaternion based on the rotation from one vector to another