Commit 12d55f96 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Bettere camera.

parent 8177f4c8
......@@ -85,6 +85,11 @@
(* a (y v))
(* a (z v))))
(define (vector-length v)
(sqrt (+ (* (x v) (x v))
(* (y v) (y v))
(* (z v) (z v)))))
(define-class <player> ()
(pos #:accessor p #:init-form (v3 1 1))
(angle #:accessor a #:init-value 0)
......@@ -182,6 +187,24 @@
)
(define (ray-trace player ray-count)
(let ((x (x (p player)))
(y (y (p player))))
(map
(lambda (a)
(let loop ((dx 0)
(dy 0))
(let ((nx (+ x dx))
(ny (+ y dy)))
(let ((ix (int nx))
(iy (int ny)))
(if (or (not (and (<= 0 nx board-width)
(<= 0 ny board-height)))
(eq? 'wall (array-ref game-map iy ix)))
(v3 dx dy)
(loop (+ dx (* 0.1 (cos a))) (+ dy (* 0.1 (sin a)))))))))
(iota ray-count (- (a player) (/ (fov player) 2))
(/ (fov player) ray-count)))))
(define fps-time (get-t))
......@@ -214,6 +237,7 @@
(iota board-width))
(set-draw-color #xFF 0 0)
(fill-rect
......@@ -221,24 +245,12 @@
(- (y (p player)) 0.1)
0.2 0.2)
(let ((x (x (p player)))
(y (y (p player))))
(for-each
(lambda (a)
(apply draw-line x y
(let loop ((dx 0)
(dy 0))
(let ((nx (+ x dx))
(ny (+ y dy)))
(let ((ix (int nx))
(iy (int ny)))
(if (or (not (and (<= 0 nx board-width)
(<= 0 ny board-height)))
(eq? 'wall (array-ref game-map iy ix)))
(list nx ny)
(loop (+ dx (* 0.1 (cos a))) (+ dy (* 0.1 (sin a))))))))))
(iota ray-count (- (a player) (/ (fov player) 2))
(/ (fov player) ray-count))))
(let ((pp (p player)))
(for-each (lambda (p)
(let ((v (+ pp p)))
(draw-line (x pp) (y pp)
(x v) (y v))))
(ray-trace player ray-count)))
(set-draw-color 0 #xFF 0)
......@@ -251,6 +263,32 @@
;; (present)
)
(define (draw-first-person-perspective)
(set-draw-color #xEE #xEE #xEE)
(clear)
(set-draw-color #x33 #x33 #x33)
(render-fill-rect (current-renderer)
(make-rect 0 240 640 240))
(set-draw-color 0 #xEE #xEE)
(for-each (lambda (i p)
(let ((segment-height (- 480 (* 70 (vector-length p)))))
(set-draw-color 0
(int (min #xFF (- #x100 (* #x100 (/ (vector-length p) 7)))))
(int (min #xFF (- #x100 (* #x100 (/ (vector-length p) 7))))))
(render-fill-rect
(current-renderer)
(make-rect (int (* i (/ 640 ray-count)))
(int (/ (- 480 segment-height) 2))
(int (1+ (/ 640 ray-count)))
(int segment-height)))))
(iota ray-count)
(ray-trace player ray-count))
)
(define texture #f)
(define (draw window rend)
......@@ -271,7 +309,10 @@
)
(set-render-target! rend #f)
(render-copy rend texture #:dstrect (list 0 0 (* 16 (current-tile-size)) (* 10 (current-tile-size))))
(draw-first-person-perspective)
;; (render-copy rend texture #:dstrect (list 0 0 (* 16 (current-tile-size)) (* 10 (current-tile-size))))
(render-copy rend texture #:dstrect (list 0 0 (* 2 (current-tile-size)) (* 2 (current-tile-size))))
(delete-texture! texture)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment