From eba4fd5d5e7d8867d82bc187b95361fd2ee18bcf Mon Sep 17 00:00:00 2001 From: Dan Frumin Date: Sat, 28 Dec 2019 15:56:39 +0100 Subject: [PATCH] basic camera movement --- outrun.rkt | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/outrun.rkt b/outrun.rkt index 84dd984..ed548cf 100644 --- a/outrun.rkt +++ b/outrun.rkt @@ -5,11 +5,11 @@ "noise.rkt") (struct scene-state - (done? dx dy dsun) + (done? dx dy dz dsun) #:transparent) (define init-scene-state - (scene-state #f 0 0 0)) + (scene-state #f 0 0 0 0)) (current-material (material #:ambient 0.1 #:diffuse 0.6 @@ -61,13 +61,20 @@ (angles->dir -30 (* 10 dsun)) (emitted "white" 1/2))) +;; Calculate camera position based on the state +(define (camera-position s) + (pos 0 (+ 4 (scene-state-dy s)) (- (scene-state-dz s) 4))) +;; Calculate camera direction based on the state +(define (camera-direction s) + (angles->dir -90 55)) + (define (on-draw s n t) (combine (basis 'camera - (point-at (pos 0 4 -6) origin)) + (point-at (camera-position s) + (camera-direction s))) (make-sunlight (scene-state-dsun s)) (mesh t) - ;; (move-y (rotate-x scene (/ t 20)) 2) - )) + (move-y (scene t) 2))) (define (on-key s n t k) (case k @@ -76,6 +83,14 @@ [dsun (add1 (scene-state-dsun s))])] [("left") (struct-copy scene-state s [dsun (sub1 (scene-state-dsun s))])] + [("up") (struct-copy scene-state s + [dy (+ (scene-state-dy s) 0.1)])] + [("down") (struct-copy scene-state s + [dy (- (scene-state-dy s) 0.1)])] + [("w") (struct-copy scene-state s + [dz (+ (scene-state-dz s) 0.1)])] + [("s") (struct-copy scene-state s + [dz (- (scene-state-dz s) 0.1)])] [else s])) (define (stop-state? s n t) (scene-state-done? s))