improve 3d renderer
This commit is contained in:
parent
f19b06d705
commit
a9de20cdea
17 changed files with 572 additions and 489 deletions
|
|
@ -39,6 +39,8 @@
|
|||
(pxl8.transition_update transition dt)
|
||||
(when (pxl8.transition_is_complete transition)
|
||||
(when transition-pending
|
||||
(when (and (= active-demo :worldgen) (not= transition-pending :worldgen))
|
||||
(pxl8.set_relative_mouse_mode false))
|
||||
(set active-demo transition-pending)
|
||||
(set transition-pending nil)
|
||||
(when (= active-demo :fire) (set fire-init? false))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
(var angle-y 0)
|
||||
(var angle-z 0)
|
||||
(var auto-rotate? true)
|
||||
(var orthographic? true)
|
||||
(var orthographic? false)
|
||||
(var wireframe? true)
|
||||
(var time 0)
|
||||
(var zoom 5.0)
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
(set angle-y 0)
|
||||
(set angle-z 0)
|
||||
(set auto-rotate? true)
|
||||
(set orthographic? true)
|
||||
(set orthographic? false)
|
||||
(set wireframe? true)
|
||||
(set time 0)
|
||||
(set zoom 5.0)
|
||||
|
|
@ -169,12 +169,11 @@
|
|||
|
||||
(fn draw-cube [pos scale rotation-offset]
|
||||
(let [[x y z] pos
|
||||
model (-> (pxl8.mat4_identity)
|
||||
(pxl8.mat4_multiply (pxl8.mat4_scale scale scale scale))
|
||||
(pxl8.mat4_multiply (pxl8.mat4_rotate_x (+ angle-x rotation-offset)))
|
||||
(pxl8.mat4_multiply (pxl8.mat4_rotate_y (+ angle-y (* rotation-offset 1.3))))
|
||||
model (-> (pxl8.mat4_translate x y z)
|
||||
(pxl8.mat4_multiply (pxl8.mat4_rotate_z (+ angle-z (* rotation-offset 0.7))))
|
||||
(pxl8.mat4_multiply (pxl8.mat4_translate x y z)))]
|
||||
(pxl8.mat4_multiply (pxl8.mat4_rotate_y (+ angle-y (* rotation-offset 1.3))))
|
||||
(pxl8.mat4_multiply (pxl8.mat4_rotate_x (+ angle-x rotation-offset)))
|
||||
(pxl8.mat4_multiply (pxl8.mat4_scale scale scale scale)))]
|
||||
(pxl8.set_model model))
|
||||
|
||||
(let [vertices (make-cube-vertices)]
|
||||
|
|
|
|||
|
|
@ -3,21 +3,23 @@
|
|||
(local bob-amount 4.0)
|
||||
(local bob-speed 8.0)
|
||||
(var bob-time 0)
|
||||
(var cam-pitch 0)
|
||||
(var cam-x 1000)
|
||||
(var cam-y 64)
|
||||
(var cam-z 1000)
|
||||
(var cam-pitch 0)
|
||||
(var cam-yaw 0)
|
||||
(var cam-z 1000)
|
||||
(local cell-size 64)
|
||||
(local gravity -800)
|
||||
(local grid-size 32)
|
||||
(var grounded? true)
|
||||
(local ground-y 64)
|
||||
(local jump-force 175)
|
||||
(var land-squash 0)
|
||||
(local land-squash-amount -4)
|
||||
(local land-recovery-speed 20)
|
||||
(local land-squash-amount -4)
|
||||
(var land-squash 0)
|
||||
(local max-pitch 1.5)
|
||||
(var mouse-look? true)
|
||||
(local mouse-sensitivity 0.008)
|
||||
(local move-speed 200)
|
||||
(local turn-speed 2.0)
|
||||
(var velocity-y 0)
|
||||
|
|
@ -66,6 +68,11 @@
|
|||
(pxl8.error (.. "Failed to apply textures - result: " result))))))))
|
||||
|
||||
(fn update [dt]
|
||||
(pxl8.set_relative_mouse_mode mouse-look?)
|
||||
|
||||
(when (pxl8.key_pressed "escape")
|
||||
(set mouse-look? (not mouse-look?)))
|
||||
|
||||
(when (pxl8.world_is_loaded world)
|
||||
(let [forward-x (- (math.sin cam-yaw))
|
||||
forward-z (- (math.cos cam-yaw))
|
||||
|
|
@ -84,10 +91,10 @@
|
|||
(when (pxl8.key_down "s")
|
||||
(set move-forward (- move-forward 1)))
|
||||
|
||||
(when (pxl8.key_down "q")
|
||||
(when (pxl8.key_down "a")
|
||||
(set move-right (- move-right 1)))
|
||||
|
||||
(when (pxl8.key_down "e")
|
||||
(when (pxl8.key_down "d")
|
||||
(set move-right (+ move-right 1)))
|
||||
|
||||
(set moving (or (not= move-forward 0) (not= move-right 0)))
|
||||
|
|
@ -107,16 +114,24 @@
|
|||
(set cam-x new-x)
|
||||
(set cam-z new-z))
|
||||
|
||||
(when (or (pxl8.key_down "left") (pxl8.key_down "a"))
|
||||
(when mouse-look?
|
||||
(let [dx (pxl8.mouse_dx)
|
||||
dy (pxl8.mouse_dy)]
|
||||
(set cam-yaw (- cam-yaw (* dx mouse-sensitivity)))
|
||||
(set cam-pitch (math.max (- max-pitch)
|
||||
(math.min max-pitch
|
||||
(- cam-pitch (* dy mouse-sensitivity)))))))
|
||||
|
||||
(when (and (not mouse-look?) (pxl8.key_down "left"))
|
||||
(set cam-yaw (+ cam-yaw (* turn-speed dt))))
|
||||
|
||||
(when (or (pxl8.key_down "right") (pxl8.key_down "d"))
|
||||
(when (and (not mouse-look?) (pxl8.key_down "right"))
|
||||
(set cam-yaw (- cam-yaw (* turn-speed dt))))
|
||||
|
||||
(when (pxl8.key_down "up")
|
||||
(when (and (not mouse-look?) (pxl8.key_down "up"))
|
||||
(set cam-pitch (math.min max-pitch (+ cam-pitch (* turn-speed dt)))))
|
||||
|
||||
(when (pxl8.key_down "down")
|
||||
(when (and (not mouse-look?) (pxl8.key_down "down"))
|
||||
(set cam-pitch (math.max (- max-pitch) (- cam-pitch (* turn-speed dt)))))
|
||||
|
||||
(when (and (pxl8.key_pressed "space") grounded?)
|
||||
|
|
@ -170,10 +185,10 @@
|
|||
|
||||
(pxl8.world_render world [cam-x eye-y cam-z])
|
||||
|
||||
(pxl8.text (.. "Pos: " (string.format "%.0f" cam-x) ","
|
||||
(pxl8.text (.. "fps: " (string.format "%.1f" (pxl8.get_fps))) 5 5 12)
|
||||
(pxl8.text (.. "pos: " (string.format "%.0f" cam-x) ","
|
||||
(string.format "%.0f" cam-y) ","
|
||||
(string.format "%.0f" cam-z)) 10 25 12)
|
||||
(pxl8.text (.. "FPS: " (string.format "%.1f" (pxl8.get_fps))) 10 40 12))))
|
||||
(string.format "%.0f" cam-z)) 5 15 12))))
|
||||
|
||||
{:init init
|
||||
:update update
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue