Commit 2782de89 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Fast ray trace work in x-dir.

parent 4d2225f9
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
(sdl2 surface) (sdl2 surface)
(sdl2 events) (sdl2 events)
(rnrs base)
(ice-9 threads) (ice-9 threads)
(ice-9 atomic) (ice-9 atomic)
...@@ -34,7 +35,7 @@ ...@@ -34,7 +35,7 @@
(define texture-map (make-hash-table)) (define texture-map (make-hash-table))
(define player (make-player 5 13 0)) (define player (make-player 5 8 pi))
(define ray-count 64) (define ray-count 64)
...@@ -143,10 +144,15 @@ ...@@ -143,10 +144,15 @@
#:hitf (v3 x y)))] #:hitf (v3 x y)))]
[else [else
;; follow ray ;; follow ray
(cond [(< (abs (decimals x)) 0.01) (cond [(< (mod (* (sgn (cos a))
(decimals x))
1)
0.01)
;; hit wall from left or right ;; hit wall from left or right
(let ((p (- (round (pow x y)) (pow x y)))) (let ((p (mod (* (sgn (sin a))
(pow x y))
1)))
(cond (cond
[(= a 0) (loop (+ x (sgn (cos a))) y)] [(= a 0) (loop (+ x (sgn (cos a))) y)]
;; enter x, leave x ;; enter x, leave x
...@@ -154,32 +160,24 @@ ...@@ -154,32 +160,24 @@
(cond [(= p 0) (cond [(= p 0)
(loop (+ x (* 0.01 (cos a))) (loop (+ x (* 0.01 (cos a)))
(+ y (* 0.01 (sin a))))] (+ y (* 0.01 (sin a))))]
[(<= p (tan a)) [(< (abs (+ (* p (sgn (sin a)))
(* (tan a) (sgn (sin a)))))
1)
(loop (+ x (sgn (cos a))) (loop (+ x (sgn (cos a)))
(+ y (tan a)))] (+ y (* (tan a) (sgn (cos a)))))]
[else [else ; enter x, leave y
(loop (+ x (* 0.01 (cos a)))
(+ y (* 0.01 (sin a))))
#;
(let ((dy (* (sgn (sin a)) (let ((dy (* (sgn (sin a))
(if (= 1 (sgn (sin a))) (mod (* -1 (pow x y) (sgn (sin a)))
(- 1 (pow x y)) 1))))
(pow x y)))))
(loop (+ x (* dy (cot a))) (loop (+ x (* dy (cot a)))
(+ y dy)))])] (+ y dy)))])]
;; enter x, leave y [else ; enter x, leave y
[else (let ((dy (* (sgn (sin a))
(loop (+ x (* 0.01 (cos a))) (mod (* -1 (pow x y) (sgn (sin a)))
(+ y (* 0.01 (sin a)))) 1))))
#; (loop (+ x (* dy (cot a)))
(if (= p 0) (+ y dy)))]))]
(loop (+ x (* 0.01 (cos a)))
(+ y (* 0.01 (sin a))))
(let ((dy (* (- 1 p) (sgn (sin a)))))
(loop (+ x (* dy (cot a)))
(+ y dy) ))
)]))]
[(< (abs (decimals y)) 0.01) [(< (abs (decimals y)) 0.01)
;; hit wall from top or bottom ;; hit wall from top or bottom
...@@ -303,8 +301,8 @@ ...@@ -303,8 +301,8 @@
(draw-first-person-perspective) (draw-first-person-perspective)
(render-copy rend texture (render-copy rend texture
#:dstrect (list 0 (- 480 100) #:dstrect (list 0 (- 480 400)
100 100)) 400 400))
(delete-texture! texture)) (delete-texture! texture))
......
...@@ -15,6 +15,25 @@ ...@@ -15,6 +15,25 @@
((#\%) 'entrance)))) ((#\%) 'entrance))))
arr)) arr))
(define game-map
(parse-map
'(
" # #######****#**#**#"
"###%####:::::::::::::::::"
"::* *::::::::::::::::::"
"::* *::::::::::::::::::"
"::# #::::::::::::::::::"
"::* *::::::::::::::::::"
"::* *::::::::::::::::::"
"::# #::::::::::::::::::"
"::* *::::::::::::::::::"
"::* *::::::::::::::::::"
"::# #::::::::::::::::::"
"::* *::::::::::::::::::"
"::* *::::::::::::::::::"
" # ###**#*#**#**#**#**#"
" ## #####################")))
#;
(define game-map (define game-map
(parse-map (parse-map
'( '(
......
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