New math functions.

This commit is contained in:
jussi
2022-08-19 16:20:59 +03:00
parent 8972ac89f4
commit e5f437d05e
6 changed files with 615 additions and 2 deletions

151
API.md
View File

@@ -4726,6 +4726,24 @@ Remap input value within input range to output range
--- ---
> result = RL_Wrap( float value, float min, float max )
Wrap input value from min to max
- Failure return false
- Success return float
---
> result = RL_FloatEquals( float x, float y )
Check whether two given floats are almost equal
- Failure return false
- Success return int
---
## Math - Vector2 ## Math - Vector2
--- ---
@@ -4818,6 +4836,15 @@ Calculate distance between two vectors
--- ---
> result = RL_Vector2DistanceSqr( Vector2 v1, Vector2 v2 )
Calculate square distance between two vectors
- Failure return false
- Success return float
---
> result = RL_Vector2Angle( Vector2 v1, Vector2 v2 ) > result = RL_Vector2Angle( Vector2 v1, Vector2 v2 )
Calculate angle from two vectors Calculate angle from two vectors
@@ -4872,6 +4899,15 @@ Normalize provided vector
--- ---
> result = RL_Vector2Transform( Vector2 v, Matrix mat )
Transforms a Vector2 by a given Matrix
- Failure return false
- Success return Vector2
---
> result = RL_Vector2Lerp( Vector2 v1, Vector2 v2, float amount ) > result = RL_Vector2Lerp( Vector2 v1, Vector2 v2, float amount )
Calculate linear interpolation between two vectors Calculate linear interpolation between two vectors
@@ -4908,6 +4944,43 @@ Move Vector towards target
--- ---
> result = RL_Vector2Invert( Vector2 v )
Invert the given vector
- Failure return false
- Success return Vector2
---
> result = RL_Vector2Clamp( Vector2 v, Vector2 min, Vector2 max )
Clamp the components of the vector between
min and max values specified by the given vectors
- Failure return false
- Success return Vector2
---
> result = RL_Vector2ClampValue( Vector2 v, float min, float max )
Clamp the magnitude of the vector between two min and max values
- Failure return false
- Success return Vector2
---
> result = RL_Vector2Equals( Vector2 v1, Vector2 v2 )
Check whether two given vectors are almost equal
- Failure return false
- Success return int
---
## Math - Vector 3 ## Math - Vector 3
--- ---
@@ -5036,6 +5109,15 @@ Calculate distance between two vectors
--- ---
> result = RL_Vector3DistanceSqr( Vector3 v1, Vector3 v2 )
Calculate square distance between two vectors
- Failure return false
- Success return float
---
> result = RL_Vector3Angle( Vector3 v1, Vector3 v2 ) > result = RL_Vector3Angle( Vector3 v1, Vector3 v2 )
Calculate angle between two vectors Calculate angle between two vectors
@@ -5100,6 +5182,15 @@ Transform a vector by quaternion rotation
--- ---
> result = RL_Vector3RotateByAxisAngle( Vector3 v, Vector3 axis, float angle )
Rotates a vector around an axis
- Failure return false
- Success return Vector3
---
> result = RL_Vector3Lerp( Vector3 v1, Vector3 v2, float amount ) > result = RL_Vector3Lerp( Vector3 v1, Vector3 v2, float amount )
Calculate linear interpolation between two vectors Calculate linear interpolation between two vectors
@@ -5156,6 +5247,57 @@ NOTE: We are avoiding calling other raymath functions despite available
--- ---
> result = RL_Vector3Invert( Vector3 v )
Invert the given vector
- Failure return false
- Success return Vector3
---
> result = RL_Vector3Clamp( Vector3 v, Vector3 min, Vector3 max )
Clamp the components of the vector between
min and max values specified by the given vectors
- Failure return false
- Success return Vector3
---
> result = RL_Vector3ClampValue( Vector3 v, float min, float max )
Clamp the magnitude of the vector between two values
- Failure return false
- Success return Vector3
---
> result = RL_Vector3Equals( Vector3 v1, Vector3 v2 )
Check whether two given vectors are almost equal
- Failure return false
- Success return int
---
> result = RL_Vector3Refract( Vector3 v, Vector3 n, float r )
Compute the direction of a refracted ray where v specifies the
normalized direction of the incoming ray, n specifies the
normalized normal vector of the interface of two optical media,
and r specifies the 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
- Failure return false
- Success return Vector3
---
## Math - Matrix ## Math - Matrix
--- ---
@@ -5543,6 +5685,15 @@ Transform a quaternion given a transformation matrix
--- ---
> result = RL_QuaternionEquals( Quaternion q1, Quaternion q2 )
Check whether two given quaternions are almost equal
- Failure return false
- Success return int
---
## Gui - Global ## Gui - Global
--- ---

View File

@@ -38,7 +38,8 @@ Vector2.meta = {
return len return len
end, end,
__eq = function( v1, v2 ) __eq = function( v1, v2 )
return v1.x == v2.x and v1.y == v2.y -- return v1.x == v2.x and v1.y == v2.y
return RL_Vector2Equals( v1, v2 ) == 1
end, end,
} }
@@ -114,6 +115,10 @@ function Vector2:distance( v2 )
return RL_Vector2Distance( self, v2 ) return RL_Vector2Distance( self, v2 )
end end
function Vector2:distanceSqr( v2 )
return RL_Vector2DistanceSqr( self, v2 )
end
function Vector2:angle( v2 ) function Vector2:angle( v2 )
return RL_Vector2Angle( self, v2 ) return RL_Vector2Angle( self, v2 )
end end
@@ -126,6 +131,10 @@ function Vector2:normalize()
return Vector2:new( RL_Vector2Normalize( self ) ) return Vector2:new( RL_Vector2Normalize( self ) )
end end
function Vector2:transform( mat )
return Vector2:new( RL_Vector2Transform( self, mat ) )
end
function Vector2:lerp( v2, value ) function Vector2:lerp( v2, value )
return Vector2:new( RL_Vector2Lerp( self, v2, value ) ) return Vector2:new( RL_Vector2Lerp( self, v2, value ) )
end end
@@ -142,4 +151,20 @@ function Vector2:moveTowards( target, maxDistance )
return Vector2:new( RL_Vector2MoveTowards( self, target, maxDistance ) ) return Vector2:new( RL_Vector2MoveTowards( self, target, maxDistance ) )
end end
function Vector2:invert()
return Vector2:new( RL_Vector2Invert( self ) )
end
function Vector2:clamp( min, max )
return Vector2:new( RL_Vector2Clamp( self, min, max ) )
end
function Vector2:clampValue( min, max )
return Vector2:new( RL_Vector2ClampValue( self, min, max ) )
end
function Vector2:equals( v2 )
return RL_Vector2Equals( self, v2 )
end
return Vector2 return Vector2

View File

@@ -38,7 +38,8 @@ Vector3.meta = {
return len return len
end, end,
__eq = function( v1, v2 ) __eq = function( v1, v2 )
return v1.x == v2.x and v1.y == v2.y and v1.z == v2.z -- return v1.x == v2.x and v1.y == v2.y and v1.z == v2.z
return RL_Vector3Equals( v1, v2 ) == 1
end, end,
} }
@@ -128,6 +129,10 @@ function Vector3:distance( v2 )
return RL_Vector3Distance( self, v2 ) return RL_Vector3Distance( self, v2 )
end end
function Vector3:distanceSqr( v2 )
return RL_Vector3DistanceSqr( self, v2 )
end
function Vector3:angle( v2 ) function Vector3:angle( v2 )
return RL_Vector3Angle( self, v2 ) return RL_Vector3Angle( self, v2 )
end end
@@ -153,6 +158,10 @@ function Vector3:rotateByQuaternion( q )
return Vector3:new( RL_Vector3RotateByQuaternion( self, q ) ) return Vector3:new( RL_Vector3RotateByQuaternion( self, q ) )
end end
function Vector3:rotateByAxisAngle( axis, angle )
return Vector3:new( RL_Vector3RotateByAxisAngle( self, axis, angle ) )
end
function Vector3:lerp( v2, value ) function Vector3:lerp( v2, value )
return Vector3:new( RL_Vector3Lerp( self, v2, value ) ) return Vector3:new( RL_Vector3Lerp( self, v2, value ) )
end end
@@ -161,4 +170,20 @@ function Vector3:reflect( normal )
return Vector3:new( RL_Vector3Reflect( self, normal ) ) return Vector3:new( RL_Vector3Reflect( self, normal ) )
end end
function Vector3:invert()
return Vector3:new( RL_Vector3Invert( self ) )
end
function Vector3:clamp( min, max )
return Vector3:new( RL_Vector3Clamp( self, min, max ) )
end
function Vector3:clampValue( min, max )
return Vector3:new( RL_Vector3ClampValue( self, min, max ) )
end
function Vector3:equals( v2 )
return RL_Vector3Equals( self, v2 )
end
return Vector3 return Vector3

View File

@@ -8,6 +8,8 @@ int lmathClamp( lua_State *L );
int lmathLerp( lua_State *L ); int lmathLerp( lua_State *L );
int lmathNormalize( lua_State *L ); int lmathNormalize( lua_State *L );
int lmathRemap( lua_State *L ); int lmathRemap( lua_State *L );
int lmathWrap( lua_State *L );
int lmathFloatEquals( lua_State *L );
/* Vector2. */ /* Vector2. */
int lmathVector2Zero( lua_State *L ); int lmathVector2Zero( lua_State *L );
int lmathVector2One( lua_State *L ); int lmathVector2One( lua_State *L );
@@ -19,16 +21,22 @@ int lmathVector2Length( lua_State *L );
int lmathVector2LengthSqr( lua_State *L ); int lmathVector2LengthSqr( lua_State *L );
int lmathVector2DotProduct( lua_State *L ); int lmathVector2DotProduct( lua_State *L );
int lmathVector2Distance( lua_State *L ); int lmathVector2Distance( lua_State *L );
int lmathVector2DistanceSqr( lua_State *L );
int lmathVector2Angle( lua_State *L ); int lmathVector2Angle( lua_State *L );
int lmathVector2Scale( lua_State *L ); int lmathVector2Scale( lua_State *L );
int lmathVector2Multiply( lua_State *L ); int lmathVector2Multiply( lua_State *L );
int lmathVector2Negate( lua_State *L ); int lmathVector2Negate( lua_State *L );
int lmathVector2Divide( lua_State *L ); int lmathVector2Divide( lua_State *L );
int lmathVector2Normalize( lua_State *L ); int lmathVector2Normalize( lua_State *L );
int lmathVector2Transform( lua_State *L );
int lmathVector2Lerp( lua_State *L ); int lmathVector2Lerp( lua_State *L );
int lmathVector2Reflect( lua_State *L ); int lmathVector2Reflect( lua_State *L );
int lmathVector2Rotate( lua_State *L ); int lmathVector2Rotate( lua_State *L );
int lmathVector2MoveTowards( 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 );
/* Vector3. */ /* Vector3. */
int lmathVector3Zero( lua_State *L ); int lmathVector3Zero( lua_State *L );
int lmathVector3One( lua_State *L ); int lmathVector3One( lua_State *L );
@@ -44,6 +52,7 @@ int lmathVector3Length( lua_State *L );
int lmathVector3LengthSqr( lua_State *L ); int lmathVector3LengthSqr( lua_State *L );
int lmathVector3DotProduct( lua_State *L ); int lmathVector3DotProduct( lua_State *L );
int lmathVector3Distance( lua_State *L ); int lmathVector3Distance( lua_State *L );
int lmathVector3DistanceSqr( lua_State *L );
int lmathVector3Angle( lua_State *L ); int lmathVector3Angle( lua_State *L );
int lmathVector3Negate( lua_State *L ); int lmathVector3Negate( lua_State *L );
int lmathVector3Divide( lua_State *L ); int lmathVector3Divide( lua_State *L );
@@ -57,6 +66,11 @@ int lmathVector3Min( lua_State *L );
int lmathVector3Max( lua_State *L ); int lmathVector3Max( lua_State *L );
int lmathVector3Barycenter( lua_State *L ); int lmathVector3Barycenter( lua_State *L );
int lmathVector3Unproject( lua_State *L ); int lmathVector3Unproject( lua_State *L );
int lmathVector3Invert( lua_State *L );
int lmathVector3Clamp( lua_State *L );
int lmathVector3ClampValue( lua_State *L );
int lmathVector3Equals( lua_State *L );
int lmathVector3Refract( lua_State *L );
/* Matrix. */ /* Matrix. */
int lmathMatrixDeterminant( lua_State *L ); int lmathMatrixDeterminant( lua_State *L );
int lmathMatrixTrace( lua_State *L ); int lmathMatrixTrace( lua_State *L );
@@ -101,3 +115,4 @@ int lmathQuaternionToAxisAngle( lua_State *L );
int lmathQuaternionFromEuler( lua_State *L ); int lmathQuaternionFromEuler( lua_State *L );
int lmathQuaternionToEuler( lua_State *L ); int lmathQuaternionToEuler( lua_State *L );
int lmathQuaternionTransform( lua_State *L ); int lmathQuaternionTransform( lua_State *L );
int lmathQuaternionEquals( lua_State *L );

View File

@@ -1097,6 +1097,8 @@ void luaRegister() {
lua_register( L, "RL_Lerp", lmathLerp ); lua_register( L, "RL_Lerp", lmathLerp );
lua_register( L, "RL_Normalize", lmathNormalize ); lua_register( L, "RL_Normalize", lmathNormalize );
lua_register( L, "RL_Remap", lmathRemap ); lua_register( L, "RL_Remap", lmathRemap );
lua_register( L, "RL_Wrap", lmathWrap );
lua_register( L, "RL_FloatEquals", lmathFloatEquals );
/* Vector2. */ /* Vector2. */
lua_register( L, "RL_Vector2Zero", lmathVector2Zero ); lua_register( L, "RL_Vector2Zero", lmathVector2Zero );
lua_register( L, "RL_Vector2One", lmathVector2One ); lua_register( L, "RL_Vector2One", lmathVector2One );
@@ -1108,16 +1110,22 @@ void luaRegister() {
lua_register( L, "RL_Vector2LengthSqr", lmathVector2LengthSqr ); lua_register( L, "RL_Vector2LengthSqr", lmathVector2LengthSqr );
lua_register( L, "RL_Vector2DotProduct", lmathVector2DotProduct ); lua_register( L, "RL_Vector2DotProduct", lmathVector2DotProduct );
lua_register( L, "RL_Vector2Distance", lmathVector2Distance ); lua_register( L, "RL_Vector2Distance", lmathVector2Distance );
lua_register( L, "RL_Vector2DistanceSqr", lmathVector2DistanceSqr );
lua_register( L, "RL_Vector2Angle", lmathVector2Angle ); lua_register( L, "RL_Vector2Angle", lmathVector2Angle );
lua_register( L, "RL_Vector2Scale", lmathVector2Scale ); lua_register( L, "RL_Vector2Scale", lmathVector2Scale );
lua_register( L, "RL_Vector2Multiply", lmathVector2Multiply ); lua_register( L, "RL_Vector2Multiply", lmathVector2Multiply );
lua_register( L, "RL_Vector2Negate", lmathVector2Negate ); lua_register( L, "RL_Vector2Negate", lmathVector2Negate );
lua_register( L, "RL_Vector2Divide", lmathVector2Divide ); lua_register( L, "RL_Vector2Divide", lmathVector2Divide );
lua_register( L, "RL_Vector2Normalize", lmathVector2Normalize ); lua_register( L, "RL_Vector2Normalize", lmathVector2Normalize );
lua_register( L, "RL_Vector2Transform", lmathVector2Transform );
lua_register( L, "RL_Vector2Lerp", lmathVector2Lerp ); lua_register( L, "RL_Vector2Lerp", lmathVector2Lerp );
lua_register( L, "RL_Vector2Reflect", lmathVector2Reflect ); lua_register( L, "RL_Vector2Reflect", lmathVector2Reflect );
lua_register( L, "RL_Vector2Rotate", lmathVector2Rotate ); lua_register( L, "RL_Vector2Rotate", lmathVector2Rotate );
lua_register( L, "RL_Vector2MoveTowards", lmathVector2MoveTowards ); lua_register( L, "RL_Vector2MoveTowards", lmathVector2MoveTowards );
lua_register( L, "RL_Vector2Invert", lmathVector2Invert );
lua_register( L, "RL_Vector2Clamp", lmathVector2Clamp );
lua_register( L, "RL_Vector2ClampValue", lmathVector2ClampValue );
lua_register( L, "RL_Vector2Equals", lmathVector2Equals );
/* Vector3. */ /* Vector3. */
lua_register( L, "RL_Vector3Zero", lmathVector3Zero ); lua_register( L, "RL_Vector3Zero", lmathVector3Zero );
lua_register( L, "RL_Vector3One", lmathVector3One ); lua_register( L, "RL_Vector3One", lmathVector3One );
@@ -1133,6 +1141,7 @@ void luaRegister() {
lua_register( L, "RL_Vector3LengthSqr", lmathVector3LengthSqr ); lua_register( L, "RL_Vector3LengthSqr", lmathVector3LengthSqr );
lua_register( L, "RL_Vector3DotProduct", lmathVector3DotProduct ); lua_register( L, "RL_Vector3DotProduct", lmathVector3DotProduct );
lua_register( L, "RL_Vector3Distance", lmathVector3Distance ); lua_register( L, "RL_Vector3Distance", lmathVector3Distance );
lua_register( L, "RL_Vector3DistanceSqr", lmathVector3DistanceSqr );
lua_register( L, "RL_Vector3Angle", lmathVector3Angle ); lua_register( L, "RL_Vector3Angle", lmathVector3Angle );
lua_register( L, "RL_Vector3Negate", lmathVector3Negate ); lua_register( L, "RL_Vector3Negate", lmathVector3Negate );
lua_register( L, "RL_Vector3Divide", lmathVector3Divide ); lua_register( L, "RL_Vector3Divide", lmathVector3Divide );
@@ -1146,6 +1155,11 @@ void luaRegister() {
lua_register( L, "RL_Vector3Max", lmathVector3Max ); lua_register( L, "RL_Vector3Max", lmathVector3Max );
lua_register( L, "RL_Vector3Barycenter", lmathVector3Barycenter ); lua_register( L, "RL_Vector3Barycenter", lmathVector3Barycenter );
lua_register( L, "RL_Vector3Unproject", lmathVector3Unproject ); lua_register( L, "RL_Vector3Unproject", lmathVector3Unproject );
lua_register( L, "RL_Vector3Invert", lmathVector3Invert );
lua_register( L, "RL_Vector3Clamp", lmathVector3Clamp );
lua_register( L, "RL_Vector3ClampValue", lmathVector3ClampValue );
lua_register( L, "RL_Vector3Equals", lmathVector3Equals );
lua_register( L, "RL_Vector3Refract", lmathVector3Refract );
/* Matrix. */ /* Matrix. */
lua_register( L, "RL_MatrixDeterminant", lmathMatrixDeterminant ); lua_register( L, "RL_MatrixDeterminant", lmathMatrixDeterminant );
lua_register( L, "RL_MatrixTrace", lmathMatrixTrace ); lua_register( L, "RL_MatrixTrace", lmathMatrixTrace );
@@ -1190,6 +1204,7 @@ void luaRegister() {
lua_register( L, "RL_QuaternionFromEuler", lmathQuaternionFromEuler ); lua_register( L, "RL_QuaternionFromEuler", lmathQuaternionFromEuler );
lua_register( L, "RL_QuaternionToEuler", lmathQuaternionToEuler ); lua_register( L, "RL_QuaternionToEuler", lmathQuaternionToEuler );
lua_register( L, "RL_QuaternionTransform", lmathQuaternionTransform ); lua_register( L, "RL_QuaternionTransform", lmathQuaternionTransform );
lua_register( L, "RL_QuaternionEquals", lmathQuaternionEquals );
/* Gui. */ /* Gui. */
/* Global. */ /* Global. */

View File

@@ -110,6 +110,51 @@ int lmathRemap( lua_State *L ) {
return 1; return 1;
} }
/*
> result = RL_Wrap( float value, float min, float max )
Wrap input value from min to max
- Failure return false
- Success return float
*/
int lmathWrap( lua_State *L ) {
if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Wrap( float value, float min, float max )" );
lua_pushboolean( L, false );
return 1;
}
float max = lua_tonumber( L, -1 );
float min = lua_tonumber( L, -2 );
float value = lua_tonumber( L, -3 );
lua_pushnumber( L, Wrap( value, min, max ) );
return 1;
}
/*
> result = RL_FloatEquals( float x, float y )
Check whether two given floats are almost equal
- Failure return false
- Success return int
*/
int lmathFloatEquals( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_FloatEquals( float x, float y )" );
lua_pushboolean( L, false );
return 1;
}
float y = lua_tonumber( L, -1 );
float x = lua_tonumber( L, -2 );
lua_pushinteger( L, FloatEquals( x, y ) );
return 1;
}
/* /*
## Math - Vector2 ## Math - Vector2
*/ */
@@ -320,6 +365,29 @@ int lmathVector2Distance( lua_State *L ) {
return 1; return 1;
} }
/*
> result = RL_Vector2DistanceSqr( Vector2 v1, Vector2 v2 )
Calculate square distance between two vectors
- Failure return false
- Success return float
*/
int lmathVector2DistanceSqr( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2DistanceSqr( Vector2 v1, Vector2 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
lua_pushnumber( L, Vector2DistanceSqr( v1, v2 ) );
return 1;
}
/* /*
> result = RL_Vector2Angle( Vector2 v1, Vector2 v2 ) > result = RL_Vector2Angle( Vector2 v1, Vector2 v2 )
@@ -454,6 +522,29 @@ int lmathVector2Normalize( lua_State *L ) {
return 1; return 1;
} }
/*
> result = RL_Vector2Transform( Vector2 v, Matrix mat )
Transforms a Vector2 by a given Matrix
- Failure return false
- Success return Vector2
*/
int lmathVector2Transform( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Transform( Vector2 v, Matrix mat )" );
lua_pushboolean( L, false );
return 1;
}
Matrix mat = uluaGetMatrix( L );
lua_pop( L, 1 );
Vector2 v = uluaGetVector2( L );
uluaPushVector2( L, Vector2Transform( v, mat ) );
return 1;
}
/* /*
> result = RL_Vector2Lerp( Vector2 v1, Vector2 v2, float amount ) > result = RL_Vector2Lerp( Vector2 v1, Vector2 v2, float amount )
@@ -550,6 +641,101 @@ int lmathVector2MoveTowards( lua_State *L ) {
return 1; return 1;
} }
/*
> result = RL_Vector2Invert( Vector2 v )
Invert the given vector
- Failure return false
- Success return Vector2
*/
int lmathVector2Invert( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Invert( Vector2 v )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v = uluaGetVector2( L );
uluaPushVector2( L, Vector2Invert( v ) );
return 1;
}
/*
> result = RL_Vector2Clamp( Vector2 v, Vector2 min, Vector2 max )
Clamp the components of the vector between
min and max values specified by the given vectors
- Failure return false
- Success return Vector2
*/
int lmathVector2Clamp( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Clamp( Vector2 v, Vector2 min, Vector2 max )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 max = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 min = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v = uluaGetVector2( L );
uluaPushVector2( L, Vector2Clamp( v, min, max ) );
return 1;
}
/*
> result = RL_Vector2ClampValue( Vector2 v, float min, float max )
Clamp the magnitude of the vector between two min and max values
- Failure return false
- Success return Vector2
*/
int lmathVector2ClampValue( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2ClampValue( Vector2 v, float min, float max )" );
lua_pushboolean( L, false );
return 1;
}
float max = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float min = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 v = uluaGetVector2( L );
uluaPushVector2( L, Vector2ClampValue( v, min, max ) );
return 1;
}
/*
> result = RL_Vector2Equals( Vector2 v1, Vector2 v2 )
Check whether two given vectors are almost equal
- Failure return false
- Success return int
*/
int lmathVector2Equals( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector2Equals( Vector2 v1, Vector2 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 v2 = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 v1 = uluaGetVector2( L );
lua_pushinteger( L, Vector2Equals( v1, v2 ) );
return 1;
}
/* /*
## Math - Vector 3 ## Math - Vector 3
*/ */
@@ -850,6 +1036,29 @@ int lmathVector3Distance( lua_State *L ) {
return 1; return 1;
} }
/*
> result = RL_Vector3DistanceSqr( Vector3 v1, Vector3 v2 )
Calculate square distance between two vectors
- Failure return false
- Success return float
*/
int lmathVector3DistanceSqr( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3DistanceSqr( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
lua_pushnumber( L, Vector3DistanceSqr( v1, v2 ) );
return 1;
}
/* /*
> result = RL_Vector3Angle( Vector3 v1, Vector3 v2 ) > result = RL_Vector3Angle( Vector3 v1, Vector3 v2 )
@@ -1011,6 +1220,31 @@ int lmathVector3RotateByQuaternion( lua_State *L ) {
return 1; return 1;
} }
/*
> result = RL_Vector3RotateByAxisAngle( Vector3 v, Vector3 axis, float angle )
Rotates a vector around an axis
- Failure return false
- Success return Vector3
*/
int lmathVector3RotateByAxisAngle( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3RotateByAxisAngle( Vector3 v, Vector3 axis, float angle )" );
lua_pushboolean( L, false );
return 1;
}
float angle = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector3 axis = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v = uluaGetVector3( L );
uluaPushVector3( L, Vector3RotateByAxisAngle( v, axis, angle ) );
return 1;
}
/* /*
> result = RL_Vector3Lerp( Vector3 v1, Vector3 v2, float amount ) > result = RL_Vector3Lerp( Vector3 v1, Vector3 v2, float amount )
@@ -1159,6 +1393,131 @@ int lmathVector3Unproject( lua_State *L ) {
return 1; return 1;
} }
/*
> result = RL_Vector3Invert( Vector3 v )
Invert the given vector
- Failure return false
- Success return Vector3
*/
int lmathVector3Invert( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Invert( Vector3 v )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v = uluaGetVector3( L );
uluaPushVector3( L, Vector3Invert( v ) );
return 1;
}
/*
> result = RL_Vector3Clamp( Vector3 v, Vector3 min, Vector3 max )
Clamp the components of the vector between
min and max values specified by the given vectors
- Failure return false
- Success return Vector3
*/
int lmathVector3Clamp( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Clamp( Vector3 v, Vector3 min, Vector3 max )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 max = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 min = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v = uluaGetVector3( L );
uluaPushVector3( L, Vector3Clamp( v, min, max ) );
return 1;
}
/*
> result = RL_Vector3ClampValue( Vector3 v, float min, float max )
Clamp the magnitude of the vector between two values
- Failure return false
- Success return Vector3
*/
int lmathVector3ClampValue( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3ClampValue( Vector3 v, float min, float max )" );
lua_pushboolean( L, false );
return 1;
}
float max = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float min = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector3 v = uluaGetVector3( L );
uluaPushVector3( L, Vector3ClampValue( v, min, max ) );
return 1;
}
/*
> result = RL_Vector3Equals( Vector3 v1, Vector3 v2 )
Check whether two given vectors are almost equal
- Failure return false
- Success return int
*/
int lmathVector3Equals( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Equals( Vector3 v1, Vector3 v2 )" );
lua_pushboolean( L, false );
return 1;
}
Vector3 v2 = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v1 = uluaGetVector3( L );
lua_pushinteger( L, Vector3Equals( v1, v2 ) );
return 1;
}
/*
> result = RL_Vector3Refract( Vector3 v, Vector3 n, float r )
Compute the direction of a refracted ray where v specifies the
normalized direction of the incoming ray, n specifies the
normalized normal vector of the interface of two optical media,
and r specifies the 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
- Failure return false
- Success return Vector3
*/
int lmathVector3Refract( lua_State *L ) {
if ( !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Vector3Refract( Vector3 v, Vector3 n, float r )" );
lua_pushboolean( L, false );
return 1;
}
float r = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector3 n = uluaGetVector3( L );
lua_pop( L, 1 );
Vector3 v = uluaGetVector3( L );
uluaPushVector3( L, Vector3Refract( v, n, r ) );
return 1;
}
/* /*
## Math - Matrix ## Math - Matrix
*/ */
@@ -2101,3 +2460,26 @@ int lmathQuaternionTransform( lua_State *L ) {
return 1; return 1;
} }
/*
> result = RL_QuaternionEquals( Quaternion q1, Quaternion q2 )
Check whether two given quaternions are almost equal
- Failure return false
- Success return int
*/
int lmathQuaternionEquals( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_QuaternionEquals( Quaternion q1, Quaternion q2 )" );
lua_pushboolean( L, false );
return 1;
}
Quaternion q2 = uluaGetQuaternion( L );
lua_pop( L, 1 );
Quaternion q1 = uluaGetQuaternion( L );
lua_pushinteger( L, QuaternionEquals( q1, q2 ) );
return 1;
}