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

Fast ray trace work in x-dir.

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