diff options
| -rw-r--r-- | API.md | 18 | ||||
| -rw-r--r-- | ReiLua_API.lua | 24 | ||||
| -rw-r--r-- | changelog | 2 | ||||
| -rw-r--r-- | devnotes | 1 | ||||
| -rw-r--r-- | examples/free_camera3d/main.lua | 73 | ||||
| -rw-r--r-- | examples/resources/lib/camera3d.lua | 4 | ||||
| -rw-r--r-- | include/models.h | 2 | ||||
| -rw-r--r-- | src/lua_core.c | 2 | ||||
| -rw-r--r-- | src/models.c | 56 |
9 files changed, 181 insertions, 1 deletions
@@ -4081,6 +4081,24 @@ Draw a cylinder wires with base at startPos and top at endPos --- +> success = RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color ) + +Draw a capsule with the center of its sphere caps at startPos and endPos + +- Failure return false +- Success return true + +--- + +> success = RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color ) + +Draw capsule wireframe with the center of its sphere caps at startPos and endPos + +- Failure return false +- Success return true + +--- + > success = RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color ) Draw a plane XZ diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 76513a9..f2c4289 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -3129,6 +3129,30 @@ function RL.DrawCylinderWires( position, radiusTop, radiusBottom, height, slices ---@return any success function RL.DrawCylinderWiresEx( startPos, endPos, startRadius, endRadius, sides, color ) end +---Draw a capsule with the center of its sphere caps at startPos and endPos +---- Failure return false +---- Success return true +---@param startPos table +---@param endPos table +---@param radius number +---@param slices integer +---@param rings integer +---@param color table +---@return any success +function RL.DrawCapsule( startPos, endPos, radius, slices, rings, color ) end + +---Draw capsule wireframe with the center of its sphere caps at startPos and endPos +---- Failure return false +---- Success return true +---@param startPos table +---@param endPos table +---@param radius number +---@param slices integer +---@param rings integer +---@param color table +---@return any success +function RL.DrawCapsuleWires( startPos, endPos, radius, slices, rings, color ) end + ---Draw a plane XZ ---- Failure return false ---- Success return true @@ -57,6 +57,8 @@ Detailed changes: - ADDED: UpdateMusicStream - ADDED: SetMusicLooping - ADDED: GetMusicLooping + - ADDED: DrawCapsule and DrawCapsuleWires + - ADDED: Free Camera3D example ------------------------------------------------------------------------ Release: ReiLua version 0.4.0 Using Raylib 4.2 @@ -21,7 +21,6 @@ Backlog { * ImageDrawCircleLines * ImageBlurGaussian * Models - * DrawCapsule and DrawCapsuleWires * LoadMaterials * Needs Testing * UpdateTexture diff --git a/examples/free_camera3d/main.lua b/examples/free_camera3d/main.lua new file mode 100644 index 0000000..0945daf --- /dev/null +++ b/examples/free_camera3d/main.lua @@ -0,0 +1,73 @@ +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" + +Util = require( "utillib" ) +Vec2 = require( "vector2" ) +Vec3 = require( "vector3" ) +Cam3D = require( "camera3d" ) + +local monitor = 0 +local camera = {} +local targetVisible = false + +function RL.init() + local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) + local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) + local winSize = Vec2:new( 1028, 720 ) + + RL.SetWindowTitle( "Free Camera3D" ) + RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) + RL.SetWindowState( RL.FLAG_VSYNC_HINT ) + RL.SetWindowSize( winSize ) + RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) + + camera = Cam3D:new() + + camera:setPosition( { 0, 8, 16 } ) + camera:setTarget( { 0, 0, 0 } ) + camera:setUp( { 0, 1, 0 } ) + -- camera.mode = camera.MODES.ORBITAL + camera.mode = camera.MODES.FREE + -- camera.mode = camera.MODES.FIRST_PERSON +end + +function RL.process( delta ) + camera:process( delta ) + + if RL.IsKeyPressed( RL.KEY_SPACE ) then + if camera.mode == camera.MODES.FREE then + camera.mode = camera.MODES.FIRST_PERSON + else + camera.mode = camera.MODES.FREE + end + end + + if RL.IsKeyPressed( RL.KEY_T ) then + targetVisible = not targetVisible + end +end + +function RL.draw() + RL.ClearBackground( { 100, 150, 100 } ) + + camera:beginMode3D() + RL.DrawGrid( 16, 1 ) + RL.DrawCapsule( { 0, 0, 0 }, { 0, 2, 0 }, 1.0, 8, 6, RL.BLUE ) + RL.DrawCapsuleWires( { 0, -0.01, 0 }, { 0, 2.01, 0 }, 1.01, 8, 6, RL.RED ) + + if targetVisible then + camera:draw() + end + camera:endMode3D() + + local text = "Press space to toggle camera mode.\nCurrent mode: " + + if camera.mode == camera.MODES.FREE then + text = text.."FREE" + elseif camera.mode == camera.MODES.FIRST_PERSON then + text = text.."FIRST_PERSON" + end + + text = text.."\nPress T to toggle target visible.\nVisible: "..tostring( targetVisible ) + + RL.DrawText( 0, text, { 16, 16 }, 30, 4, RL.WHITE ) +end diff --git a/examples/resources/lib/camera3d.lua b/examples/resources/lib/camera3d.lua index 1e51844..cea6e8d 100644 --- a/examples/resources/lib/camera3d.lua +++ b/examples/resources/lib/camera3d.lua @@ -33,6 +33,10 @@ function Camera3D:new() object.camera = RL.CreateCamera3D() object.mode = object.MODES.CUSTOM + object:setPosition( { 0, 0, 0 } ) + object:setTarget( { 0, 0, 0 } ) + object:setUp( { 0, 1, 0 } ) + return object end diff --git a/include/models.h b/include/models.h index 69cf143..b36d4ce 100644 --- a/include/models.h +++ b/include/models.h @@ -18,6 +18,8 @@ int lmodelsDrawCylinder( lua_State *L ); int lmodelsDrawCylinderEx( lua_State *L ); int lmodelsDrawCylinderWires( lua_State *L ); int lmodelsDrawCylinderWiresEx( lua_State *L ); +int lmodelsDrawCapsule( lua_State *L ); +int lmodelsDrawCapsuleWires( lua_State *L ); int lmodelsDrawPlane( lua_State *L ); int lmodelDrawQuad3DTexture( lua_State *L ); int lmodelsDrawRay( lua_State *L ); diff --git a/src/lua_core.c b/src/lua_core.c index 6f593d2..8aeeafe 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1050,6 +1050,8 @@ void luaRegister() { assingGlobalFunction( "DrawCylinderEx", lmodelsDrawCylinderEx ); assingGlobalFunction( "DrawCylinderWires", lmodelsDrawCylinderWires ); assingGlobalFunction( "DrawCylinderWiresEx", lmodelsDrawCylinderWiresEx ); + assingGlobalFunction( "DrawCapsule", lmodelsDrawCapsule ); + assingGlobalFunction( "DrawCapsuleWires", lmodelsDrawCapsuleWires ); assingGlobalFunction( "DrawPlane", lmodelsDrawPlane ); assingGlobalFunction( "DrawQuad3DTexture", lmodelDrawQuad3DTexture ); assingGlobalFunction( "DrawRay", lmodelsDrawRay ); diff --git a/src/models.c b/src/models.c index 963bd56..6b0ff0a 100644 --- a/src/models.c +++ b/src/models.c @@ -524,6 +524,62 @@ int lmodelsDrawCylinderWiresEx( lua_State *L ) { } /* +> success = RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color ) + +Draw a capsule with the center of its sphere caps at startPos and endPos + +- Failure return false +- Success return true +*/ +int lmodelsDrawCapsule( lua_State *L ) { + if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) + || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawCapsule( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector3 startPos = uluaGetVector3Index( L, 1 ); + Vector3 endPos = uluaGetVector3Index( L, 2 ); + float radius = lua_tonumber( L, 3 ); + int slices = lua_tonumber( L, 4 ); + int rings = lua_tointeger( L, 5 ); + Color color = uluaGetColorIndex( L, 6 ); + + DrawCapsule( startPos, endPos, radius, slices, rings, color ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color ) + +Draw capsule wireframe with the center of its sphere caps at startPos and endPos + +- Failure return false +- Success return true +*/ +int lmodelsDrawCapsuleWires( lua_State *L ) { + if ( !lua_istable( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) + || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL.DrawCapsuleWires( Vector3 startPos, Vector3 endPos, float radius, int slices, int rings, Color color )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector3 startPos = uluaGetVector3Index( L, 1 ); + Vector3 endPos = uluaGetVector3Index( L, 2 ); + float radius = lua_tonumber( L, 3 ); + int slices = lua_tonumber( L, 4 ); + int rings = lua_tointeger( L, 5 ); + Color color = uluaGetColorIndex( L, 6 ); + + DrawCapsuleWires( startPos, endPos, radius, slices, rings, color ); + lua_pushboolean( L, true ); + + return 1; +} + +/* > success = RL.DrawPlane( Vector3 centerPos, Vector2 size, Color color ) Draw a plane XZ |
