54 lines
1.5 KiB
Text
54 lines
1.5 KiB
Text
|
|
(local pxl8 (require :pxl8))
|
||
|
|
|
||
|
|
(var camera-angle 0)
|
||
|
|
(local camera-height 0)
|
||
|
|
(local camera-distance 300)
|
||
|
|
(var fps 0)
|
||
|
|
(var world nil)
|
||
|
|
|
||
|
|
(fn init []
|
||
|
|
(set world (pxl8.world_new))
|
||
|
|
(let [result (pxl8.world_load world "res/maps/test.bsp")]
|
||
|
|
(if (< result 0)
|
||
|
|
(pxl8.error (.. "Failed to load test.bsp - result: " result))
|
||
|
|
(pxl8.info "Loaded world successfully!"))))
|
||
|
|
|
||
|
|
(fn update [dt]
|
||
|
|
(when (> dt 0)
|
||
|
|
(set fps (math.floor (/ 1.0 dt))))
|
||
|
|
(when (pxl8.world_is_loaded world)
|
||
|
|
(set camera-angle (+ camera-angle (* dt 0.5)))))
|
||
|
|
|
||
|
|
(fn frame []
|
||
|
|
(pxl8.clr 0)
|
||
|
|
(pxl8.text (.. "FPS: " fps) 10 40 14)
|
||
|
|
|
||
|
|
(if (pxl8.world_is_loaded world)
|
||
|
|
(let [cam-x (* camera-distance (math.cos camera-angle))
|
||
|
|
cam-z (* camera-distance (math.sin camera-angle))]
|
||
|
|
|
||
|
|
(pxl8.text (.. "Camera: " (string.format "%.0f" cam-x) ","
|
||
|
|
(string.format "%.0f" camera-height) ","
|
||
|
|
(string.format "%.0f" cam-z)) 10 55 12)
|
||
|
|
|
||
|
|
(pxl8.clear_zbuffer)
|
||
|
|
(pxl8.set_backface_culling true)
|
||
|
|
(pxl8.set_wireframe true)
|
||
|
|
|
||
|
|
(let [aspect (/ (pxl8.get_width) (pxl8.get_height))
|
||
|
|
fov 1.047]
|
||
|
|
(pxl8.set_projection (pxl8.mat4_perspective fov aspect 1.0 4096.0)))
|
||
|
|
|
||
|
|
(pxl8.set_view (pxl8.mat4_lookat
|
||
|
|
[cam-x camera-height cam-z]
|
||
|
|
[0 0 0]
|
||
|
|
[0 1 0]))
|
||
|
|
|
||
|
|
(pxl8.set_model (pxl8.mat4_identity))
|
||
|
|
|
||
|
|
(pxl8.world_render world [cam-x camera-height cam-z]))))
|
||
|
|
|
||
|
|
{:init init
|
||
|
|
:update update
|
||
|
|
:frame frame}
|