diff options
| author | jussi | 2023-04-25 19:28:54 +0300 |
|---|---|---|
| committer | jussi | 2023-04-25 19:28:54 +0300 |
| commit | 8b6337446dd79faf226ea9df40d4d06d81c38436 (patch) | |
| tree | 14e55e4c50139c932c3d959583532675fe7be19a /examples/free_camera3d/main.lua | |
| parent | a9ce78128d919e9798d7d2ec043879a4c685a9d1 (diff) | |
| download | reilua-enhanced-8b6337446dd79faf226ea9df40d4d06d81c38436.tar.gz reilua-enhanced-8b6337446dd79faf226ea9df40d4d06d81c38436.tar.bz2 reilua-enhanced-8b6337446dd79faf226ea9df40d4d06d81c38436.zip | |
DrawCapsule and DrawCapsuleWires. Free Camera3D example.
Diffstat (limited to 'examples/free_camera3d/main.lua')
| -rw-r--r-- | examples/free_camera3d/main.lua | 73 |
1 files changed, 73 insertions, 0 deletions
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 |
