1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
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( RL.defaultFont, text, { 16, 16 }, 30, 4, RL.WHITE )
RL.DrawText( RL.GetFontDefault(), text, { 16, 16 }, 30, 4, RL.WHITE )
end
|