Spline functions.

This commit is contained in:
jussi
2023-11-20 21:54:50 +02:00
parent 05eaafb79e
commit 01883035b0
7 changed files with 562 additions and 3 deletions

110
API.md
View File

@@ -4168,7 +4168,7 @@ Get a random value between min and max (both included)
---
> sequence = RL.GetRandomValue( int count, int min, int max )
> sequence = RL.LoadRandomSequence( int count, int min, int max )
Load random values sequence, no values repeated
@@ -5259,6 +5259,114 @@ Draw a polygon outline of n sides with extended parameters
---
## Shapes - Splines drawing functions
---
> RL.DrawSplineLinear( Vector2{} points, float thick, Color color )
Draw spline: Linear, minimum 2 points
---
> RL.DrawSplineBasis( Vector2{} points, float thick, Color color )
Draw spline: B-Spline, minimum 4 points
---
> RL.DrawSplineCatmullRom( Vector2{} points, float thick, Color color )
Draw spline: Catmull-Rom, minimum 4 points
---
> RL.DrawSplineBezierQuadratic( Vector2{} points, float thick, Color color )
Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...]
---
> RL.DrawSplineBezierCubic( Vector2{} points, float thick, Color color )
Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...]
---
> RL.DrawSplineSegmentLinear( Vector2 p1, Vector2 p2, float thick, Color color )
Draw spline segment: Linear, 2 points
---
> RL.DrawSplineSegmentBasis( Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float thick, Color color )
Draw spline segment: B-Spline, 4 points
---
> RL.DrawSplineSegmentCatmullRom( Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float thick, Color color )
Draw spline segment: Catmull-Rom, 4 points
---
> RL.DrawSplineSegmentBezierQuadratic( Vector2 p1, Vector2 c2, Vector2 p3, float thick, Color color )
Draw spline segment: Quadratic Bezier, 2 points, 1 control point
---
> RL.DrawSplineSegmentBezierCubic( Vector2 p1, Vector2 c2, Vector2 c3, Vector2 p4, float thick, Color color )
Draw spline segment: Cubic Bezier, 2 points, 2 control points
---
## Shapes - Spline segment point evaluation functions, for a given t [0.0f .. 1.0f]
---
> point = RL.GetSplinePointLinear( Vector2 startPos, Vector2 endPos, float t )
Get (evaluate) spline point: Linear
- Success return Vector2
---
> point = RL.GetSplinePointBasis( Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float t )
Get (evaluate) spline point: B-Spline
- Success return Vector2
---
> point = RL.GetSplinePointCatmullRom( Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float t )
Get (evaluate) spline point: Catmull-Rom
- Success return Vector2
---
> point = RL.GetSplinePointBezierQuad( Vector2 p1, Vector2 c2, Vector2 p3, float t )
Get (evaluate) spline point: Quadratic Bezier
- Success return Vector2
---
> point = RL.GetSplinePointBezierCubic( Vector2 p1, Vector2 c2, Vector2 c3, Vector2 p4, float t )
Get (evaluate) spline point: Cubic Bezier
- Success return Vector2
---
## Shapes - Basic shapes collision detection functions
---

View File

@@ -1695,7 +1695,7 @@ function RL.GetRandomValue( min, max ) end
---@param min integer
---@param max integer
---@return any sequence
function RL.GetRandomValue( count, min, max ) end
function RL.LoadRandomSequence( count, min, max ) end
-- Core - Misc
@@ -2640,6 +2640,139 @@ function RL.DrawPolyLines( center, sides, radius, rotation, color ) end
---@return any RL.DrawPolyLinesEx
function RL.DrawPolyLinesEx( center, sides, radius, rotation, lineThick, color ) end
-- Shapes - Splines drawing functions
---Draw spline: Linear, minimum 2 points
---@param points table
---@param thick number
---@param color table
---@return any RL.DrawSplineLinear
function RL.DrawSplineLinear( points, thick, color ) end
---Draw spline: B-Spline, minimum 4 points
---@param points table
---@param thick number
---@param color table
---@return any RL.DrawSplineBasis
function RL.DrawSplineBasis( points, thick, color ) end
---Draw spline: Catmull-Rom, minimum 4 points
---@param points table
---@param thick number
---@param color table
---@return any RL.DrawSplineCatmullRom
function RL.DrawSplineCatmullRom( points, thick, color ) end
---Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...]
---@param points table
---@param thick number
---@param color table
---@return any RL.DrawSplineBezierQuadratic
function RL.DrawSplineBezierQuadratic( points, thick, color ) end
---Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...]
---@param points table
---@param thick number
---@param color table
---@return any RL.DrawSplineBezierCubic
function RL.DrawSplineBezierCubic( points, thick, color ) end
---Draw spline segment: Linear, 2 points
---@param p1 table
---@param p2 table
---@param thick number
---@param color table
---@return any RL.DrawSplineSegmentLinear
function RL.DrawSplineSegmentLinear( p1, p2, thick, color ) end
---Draw spline segment: B-Spline, 4 points
---@param p1 table
---@param p2 table
---@param p3 table
---@param p4 table
---@param thick number
---@param color table
---@return any RL.DrawSplineSegmentBasis
function RL.DrawSplineSegmentBasis( p1, p2, p3, p4, thick, color ) end
---Draw spline segment: Catmull-Rom, 4 points
---@param p1 table
---@param p2 table
---@param p3 table
---@param p4 table
---@param thick number
---@param color table
---@return any RL.DrawSplineSegmentCatmullRom
function RL.DrawSplineSegmentCatmullRom( p1, p2, p3, p4, thick, color ) end
---Draw spline segment: Quadratic Bezier, 2 points, 1 control point
---@param p1 table
---@param c2 table
---@param p3 table
---@param thick number
---@param color table
---@return any RL.DrawSplineSegmentBezierQuadratic
function RL.DrawSplineSegmentBezierQuadratic( p1, c2, p3, thick, color ) end
---Draw spline segment: Cubic Bezier, 2 points, 2 control points
---@param p1 table
---@param c2 table
---@param c3 table
---@param p4 table
---@param thick number
---@param color table
---@return any RL.DrawSplineSegmentBezierCubic
function RL.DrawSplineSegmentBezierCubic( p1, c2, c3, p4, thick, color ) end
-- Shapes - Spline segment point evaluation functions, for a given t [0.0f .. 1.0f]
---Get (evaluate) spline point: Linear
---- Success return Vector2
---@param startPos table
---@param endPos table
---@param t number
---@return any point
function RL.GetSplinePointLinear( startPos, endPos, t ) end
---Get (evaluate) spline point: B-Spline
---- Success return Vector2
---@param p1 table
---@param p2 table
---@param p3 table
---@param p4 table
---@param t number
---@return any point
function RL.GetSplinePointBasis( p1, p2, p3, p4, t ) end
---Get (evaluate) spline point: Catmull-Rom
---- Success return Vector2
---@param p1 table
---@param p2 table
---@param p3 table
---@param p4 table
---@param t number
---@return any point
function RL.GetSplinePointCatmullRom( p1, p2, p3, p4, t ) end
---Get (evaluate) spline point: Quadratic Bezier
---- Success return Vector2
---@param p1 table
---@param c2 table
---@param p3 table
---@param t number
---@return any point
function RL.GetSplinePointBezierQuad( p1, c2, p3, t ) end
---Get (evaluate) spline point: Cubic Bezier
---- Success return Vector2
---@param p1 table
---@param c2 table
---@param c3 table
---@param p4 table
---@param t number
---@return any point
function RL.GetSplinePointBezierCubic( p1, c2, c3, p4, t ) end
-- Shapes - Basic shapes collision detection functions
---Check collision between two rectangles

View File

@@ -7,6 +7,7 @@ KEY CHANGES:
- ADDED: More audio device management functions.
- ADDED: Random values generation functions.
- ADDED: More Window-related functions.
- ADDED: Spline functions.
DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.

View File

@@ -31,6 +31,23 @@ int lshapesDrawTriangleStrip( lua_State *L );
int lshapesDrawPoly( lua_State *L );
int lshapesDrawPolyLines( lua_State *L );
int lshapesDrawPolyLinesEx( lua_State *L );
/* Splines drawing functions. */
int lshapesDrawSplineLinear( lua_State *L );
int lshapesDrawSplineBasis( lua_State *L );
int lshapesDrawSplineCatmullRom( lua_State *L );
int lshapesDrawSplineBezierQuadratic( lua_State *L );
int lshapesDrawSplineBezierCubic( lua_State *L );
int lshapesDrawSplineSegmentLinear( lua_State *L );
int lshapesDrawSplineSegmentBasis( lua_State *L );
int lshapesDrawSplineSegmentCatmullRom( lua_State *L );
int lshapesDrawSplineSegmentBezierQuadratic( lua_State *L );
int lshapesDrawSplineSegmentBezierCubic( lua_State *L );
/* Basic Spline segment point evaluation functions, for a given t [0.0f .. 1.0f]. */
int lshapesGetSplinePointLinear( lua_State *L );
int lshapesGetSplinePointBasis( lua_State *L );
int lshapesGetSplinePointCatmullRom( lua_State *L );
int lshapesGetSplinePointBezierQuad( lua_State *L );
int lshapesGetSplinePointBezierCubic( lua_State *L );
/* Basic shapes collision detection functions. */
int lshapesCheckCollisionRecs( lua_State *L );
int lshapesCheckCollisionCircles( lua_State *L );

View File

@@ -1278,7 +1278,7 @@ int lcoreGetRandomValue( lua_State *L ) {
}
/*
> sequence = RL.GetRandomValue( int count, int min, int max )
> sequence = RL.LoadRandomSequence( int count, int min, int max )
Load random values sequence, no values repeated

View File

@@ -1771,6 +1771,23 @@ void luaRegister() {
assingGlobalFunction( "DrawPoly", lshapesDrawPoly );
assingGlobalFunction( "DrawPolyLines", lshapesDrawPolyLines );
assingGlobalFunction( "DrawPolyLinesEx", lshapesDrawPolyLinesEx );
/* Splines drawing functions. */
assingGlobalFunction( "DrawSplineLinear", lshapesDrawSplineLinear );
assingGlobalFunction( "DrawSplineBasis", lshapesDrawSplineBasis );
assingGlobalFunction( "DrawSplineCatmullRom", lshapesDrawSplineCatmullRom );
assingGlobalFunction( "DrawSplineBezierQuadratic", lshapesDrawSplineBezierQuadratic );
assingGlobalFunction( "DrawSplineBezierCubic", lshapesDrawSplineBezierCubic );
assingGlobalFunction( "DrawSplineSegmentLinear", lshapesDrawSplineSegmentLinear );
assingGlobalFunction( "DrawSplineSegmentBasis", lshapesDrawSplineSegmentBasis );
assingGlobalFunction( "DrawSplineSegmentCatmullRom", lshapesDrawSplineSegmentCatmullRom );
assingGlobalFunction( "DrawSplineSegmentBezierQuadratic", lshapesDrawSplineSegmentBezierQuadratic );
assingGlobalFunction( "DrawSplineSegmentBezierCubic", lshapesDrawSplineSegmentBezierCubic );
/* Basic Spline segment point evaluation functions, for a given t [0.0f .. 1.0f]. */
assingGlobalFunction( "GetSplinePointLinear", lshapesGetSplinePointLinear );
assingGlobalFunction( "GetSplinePointBasis", lshapesGetSplinePointBasis );
assingGlobalFunction( "GetSplinePointCatmullRom", lshapesGetSplinePointCatmullRom );
assingGlobalFunction( "GetSplinePointBezierQuad", lshapesGetSplinePointBezierQuad );
assingGlobalFunction( "GetSplinePointBezierCubic", lshapesGetSplinePointBezierCubic );
/* Basic shapes collision detection functions. */
assingGlobalFunction( "CheckCollisionRecs", lshapesCheckCollisionRecs );
assingGlobalFunction( "CheckCollisionCircles", lshapesCheckCollisionCircles );

View File

@@ -4,6 +4,17 @@
#include "lua_core.h"
#include "textures.h"
static inline void getVector2Array( lua_State *L, int index, Vector2 points[] ) {
int t = index, i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
points[i] = uluaGetVector2( L, lua_gettop( L ) );
i++;
lua_pop( L, 1 );
}
}
/*
## Shapes - Basic shapes drawing functions
*/
@@ -520,6 +531,278 @@ int lshapesDrawPolyLinesEx( lua_State *L ) {
return 0;
}
/*
## Shapes - Splines drawing functions
*/
/*
> RL.DrawSplineLinear( Vector2{} points, float thick, Color color )
Draw spline: Linear, minimum 2 points
*/
int lshapesDrawSplineLinear( lua_State *L ) {
int pointCount = uluaGetTableLen( L, 1 );
Vector2 points[ pointCount ];
float thick = luaL_checknumber( L, 2 );
Color color = uluaGetColor( L, 3 );
getVector2Array( L, 1, points );
DrawSplineLinear( points, pointCount, thick, color );
return 0;
}
/*
> RL.DrawSplineBasis( Vector2{} points, float thick, Color color )
Draw spline: B-Spline, minimum 4 points
*/
int lshapesDrawSplineBasis( lua_State *L ) {
int pointCount = uluaGetTableLen( L, 1 );
Vector2 points[ pointCount ];
float thick = luaL_checknumber( L, 2 );
Color color = uluaGetColor( L, 3 );
getVector2Array( L, 1, points );
DrawSplineBasis( points, pointCount, thick, color );
return 0;
}
/*
> RL.DrawSplineCatmullRom( Vector2{} points, float thick, Color color )
Draw spline: Catmull-Rom, minimum 4 points
*/
int lshapesDrawSplineCatmullRom( lua_State *L ) {
int pointCount = uluaGetTableLen( L, 1 );
Vector2 points[ pointCount ];
float thick = luaL_checknumber( L, 2 );
Color color = uluaGetColor( L, 3 );
getVector2Array( L, 1, points );
DrawSplineCatmullRom( points, pointCount, thick, color );
return 0;
}
/*
> RL.DrawSplineBezierQuadratic( Vector2{} points, float thick, Color color )
Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...]
*/
int lshapesDrawSplineBezierQuadratic( lua_State *L ) {
int pointCount = uluaGetTableLen( L, 1 );
Vector2 points[ pointCount ];
float thick = luaL_checknumber( L, 2 );
Color color = uluaGetColor( L, 3 );
getVector2Array( L, 1, points );
DrawSplineBezierQuadratic( points, pointCount, thick, color );
return 0;
}
/*
> RL.DrawSplineBezierCubic( Vector2{} points, float thick, Color color )
Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...]
*/
int lshapesDrawSplineBezierCubic( lua_State *L ) {
int pointCount = uluaGetTableLen( L, 1 );
Vector2 points[ pointCount ];
float thick = luaL_checknumber( L, 2 );
Color color = uluaGetColor( L, 3 );
getVector2Array( L, 1, points );
DrawSplineBezierCubic( points, pointCount, thick, color );
return 0;
}
/*
> RL.DrawSplineSegmentLinear( Vector2 p1, Vector2 p2, float thick, Color color )
Draw spline segment: Linear, 2 points
*/
int lshapesDrawSplineSegmentLinear( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 p2 = uluaGetVector2( L, 2 );
float thick = luaL_checknumber( L, 3 );
Color color = uluaGetColor( L, 4 );
DrawSplineSegmentLinear( p1, p2, thick, color );
return 0;
}
/*
> RL.DrawSplineSegmentBasis( Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float thick, Color color )
Draw spline segment: B-Spline, 4 points
*/
int lshapesDrawSplineSegmentBasis( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 p2 = uluaGetVector2( L, 2 );
Vector2 p3 = uluaGetVector2( L, 3 );
Vector2 p4 = uluaGetVector2( L, 4 );
float thick = luaL_checknumber( L, 5 );
Color color = uluaGetColor( L, 6 );
DrawSplineSegmentBasis( p1, p2, p3, p4, thick, color );
return 0;
}
/*
> RL.DrawSplineSegmentCatmullRom( Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float thick, Color color )
Draw spline segment: Catmull-Rom, 4 points
*/
int lshapesDrawSplineSegmentCatmullRom( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 p2 = uluaGetVector2( L, 2 );
Vector2 p3 = uluaGetVector2( L, 3 );
Vector2 p4 = uluaGetVector2( L, 4 );
float thick = luaL_checknumber( L, 5 );
Color color = uluaGetColor( L, 6 );
DrawSplineSegmentCatmullRom( p1, p2, p3, p4, thick, color );
return 0;
}
/*
> RL.DrawSplineSegmentBezierQuadratic( Vector2 p1, Vector2 c2, Vector2 p3, float thick, Color color )
Draw spline segment: Quadratic Bezier, 2 points, 1 control point
*/
int lshapesDrawSplineSegmentBezierQuadratic( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 c2 = uluaGetVector2( L, 2 );
Vector2 p3 = uluaGetVector2( L, 3 );
float thick = luaL_checknumber( L, 4 );
Color color = uluaGetColor( L, 5 );
DrawSplineSegmentBezierQuadratic( p1, c2, p3, thick, color );
return 0;
}
/*
> RL.DrawSplineSegmentBezierCubic( Vector2 p1, Vector2 c2, Vector2 c3, Vector2 p4, float thick, Color color )
Draw spline segment: Cubic Bezier, 2 points, 2 control points
*/
int lshapesDrawSplineSegmentBezierCubic( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 c2 = uluaGetVector2( L, 2 );
Vector2 c3 = uluaGetVector2( L, 3 );
Vector2 p4 = uluaGetVector2( L, 4 );
float thick = luaL_checknumber( L, 5 );
Color color = uluaGetColor( L, 6 );
DrawSplineSegmentBezierCubic( p1, c2, c3, p4, thick, color );
return 0;
}
/*
## Shapes - Spline segment point evaluation functions, for a given t [0.0f .. 1.0f]
*/
/*
> point = RL.GetSplinePointLinear( Vector2 startPos, Vector2 endPos, float t )
Get (evaluate) spline point: Linear
- Success return Vector2
*/
int lshapesGetSplinePointLinear( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 p2 = uluaGetVector2( L, 2 );
float t = luaL_checknumber( L, 3 );
uluaPushVector2( L, GetSplinePointLinear( p1, p2, t ) );
return 1;
}
/*
> point = RL.GetSplinePointBasis( Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float t )
Get (evaluate) spline point: B-Spline
- Success return Vector2
*/
int lshapesGetSplinePointBasis( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 p2 = uluaGetVector2( L, 2 );
Vector2 p3 = uluaGetVector2( L, 3 );
Vector2 p4 = uluaGetVector2( L, 4 );
float t = luaL_checknumber( L, 5 );
uluaPushVector2( L, GetSplinePointBasis( p1, p2, p3, p4, t ) );
return 1;
}
/*
> point = RL.GetSplinePointCatmullRom( Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float t )
Get (evaluate) spline point: Catmull-Rom
- Success return Vector2
*/
int lshapesGetSplinePointCatmullRom( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 p2 = uluaGetVector2( L, 2 );
Vector2 p3 = uluaGetVector2( L, 3 );
Vector2 p4 = uluaGetVector2( L, 4 );
float t = luaL_checknumber( L, 5 );
uluaPushVector2( L, GetSplinePointCatmullRom( p1, p2, p3, p4, t ) );
return 1;
}
/*
> point = RL.GetSplinePointBezierQuad( Vector2 p1, Vector2 c2, Vector2 p3, float t )
Get (evaluate) spline point: Quadratic Bezier
- Success return Vector2
*/
int lshapesGetSplinePointBezierQuad( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 c2 = uluaGetVector2( L, 2 );
Vector2 p3 = uluaGetVector2( L, 3 );
float t = luaL_checknumber( L, 4 );
uluaPushVector2( L, GetSplinePointBezierQuad( p1, c2, p3, t ) );
return 1;
}
/*
> point = RL.GetSplinePointBezierCubic( Vector2 p1, Vector2 c2, Vector2 c3, Vector2 p4, float t )
Get (evaluate) spline point: Cubic Bezier
- Success return Vector2
*/
int lshapesGetSplinePointBezierCubic( lua_State *L ) {
Vector2 p1 = uluaGetVector2( L, 1 );
Vector2 c2 = uluaGetVector2( L, 2 );
Vector2 c3 = uluaGetVector2( L, 3 );
Vector2 p4 = uluaGetVector2( L, 4 );
float t = luaL_checknumber( L, 5 );
uluaPushVector2( L, GetSplinePointBezierCubic( p1, c2, c3, p4, t ) );
return 1;
}
/*
## Shapes - Basic shapes collision detection functions
*/