summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/free_camera3d/main.lua73
-rw-r--r--examples/resources/lib/camera3d.lua4
2 files changed, 77 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
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