summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjussi2024-07-17 00:06:43 +0300
committerjussi2024-07-17 00:06:43 +0300
commitc7b7975482bb33e7fb352c5759920748b6d3769b (patch)
tree6a318d35a2e18a2d903f11f3bc4eda8359620ef8 /src
parent9dceeb8c058267e04bf551db7a9659e3ba5bdab3 (diff)
downloadreilua-enhanced-c7b7975482bb33e7fb352c5759920748b6d3769b.tar.gz
reilua-enhanced-c7b7975482bb33e7fb352c5759920748b6d3769b.tar.bz2
reilua-enhanced-c7b7975482bb33e7fb352c5759920748b6d3769b.zip
DrawGridEx.
Diffstat (limited to 'src')
-rw-r--r--src/lua_core.c1
-rw-r--r--src/models.c52
2 files changed, 53 insertions, 0 deletions
diff --git a/src/lua_core.c b/src/lua_core.c
index 0955f77..2d5ddcc 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -1726,6 +1726,7 @@ void luaRegister() {
assingGlobalFunction( "DrawQuad3DTexture", lmodelDrawQuad3DTexture );
assingGlobalFunction( "DrawRay", lmodelsDrawRay );
assingGlobalFunction( "DrawGrid", lmodelsDrawGrid );
+ assingGlobalFunction( "DrawGridEx", lmodelsDrawGridEx );
/* Model management functions. */
assingGlobalFunction( "LoadModel", lmodelsLoadModel );
assingGlobalFunction( "LoadModelFromMesh", lmodelsLoadModelFromMesh );
diff --git a/src/models.c b/src/models.c
index 61b9c2b..652a6c0 100644
--- a/src/models.c
+++ b/src/models.c
@@ -497,6 +497,58 @@ int lmodelsDrawGrid( lua_State* L ) {
}
/*
+> RL.DrawGridEx( Vector2 slices, Vector2 spacing, Matrix transform, Color color, Vector2|nil divider, Color|nil dividerColor )
+
+Draw a grid with extended parameters. Optionally you can define divider with different color for every n slices
+*/
+int lmodelsDrawGridEx( lua_State* L ) {
+ Vector2 slices = uluaGetVector2( L, 1 );
+ Vector2 spacing = uluaGetVector2( L, 2 );
+ Matrix transform = uluaGetMatrix( L, 3 );
+ Color color = uluaGetColor( L, 4 );
+
+ Vector2 divider = { 0, 0 };
+ Color divColor = WHITE;
+
+ if ( !lua_isnil( L, 5 ) && !lua_isnone( L, 5 ) ) {
+ divider = uluaGetVector2( L, 5 );
+ }
+ if ( !lua_isnil( L, 6 ) && !lua_isnone( L, 6 ) ) {
+ divColor = uluaGetColor( L, 6 );
+ }
+
+ rlPushMatrix();
+ rlMultMatrixf( MatrixToFloat( transform ) );
+
+ rlBegin( RL_LINES );
+ for ( int x = 0; x < (int)slices.x + 1; x++ ) {
+ if ( 0 < x && x < slices.x && 0 < divider.x && x % (int)divider.x == 0 ) {
+ rlColor4ub( divColor.r, divColor.g, divColor.b, divColor.a );
+ }
+ else {
+ rlColor4ub( color.r, color.g, color.b, color.a );
+ }
+
+ rlVertex3f( spacing.x * x, 0, 0 );
+ rlVertex3f( spacing.x * x, 0, slices.y * spacing.y );
+ }
+ for ( int y = 0; y < (int)slices.y + 1; y++ ) {
+ if ( 0 < y && y < slices.y && 0 < divider.y && y % (int)divider.y == 0 ) {
+ rlColor4ub( divColor.r, divColor.g, divColor.b, divColor.a );
+ }
+ else {
+ rlColor4ub( color.r, color.g, color.b, color.a );
+ }
+ rlVertex3f( 0, 0, spacing.y * y );
+ rlVertex3f( slices.x * spacing.x, 0, spacing.y * y );
+ }
+ rlEnd();
+ rlPopMatrix();
+
+ return 0;
+}
+
+/*
## Models - Model management functions
*/