; a simple scene

(define clock (get-clock))

(define object-phong
  (make-phong
    0.25 ; ambient
    0.2 ; diffuse
    0.3 ; specular
    15)) ; specular-N

(define ground-phong
  (make-phong
    0.75 ; ambient
    0.3 ; diffuse
    0.0 ; specular
    0)) ; specular-N

(define red
  (make-shader
    (make-color (make-point 0.9999 0.0 0.0))
    object-phong
    0.75 ; reflection
    #f)) ; shadows
(define purple
  (make-shader
    (make-color (make-point 0.4 0.0 0.9999))
    object-phong
    0.75 ; reflection
    #f)) ; shadows
(define orange
  (make-shader
    (make-color (make-point 0.9999 0.4 0.0))
    object-phong
    0.75 ; reflection
    #f)) ; shadows
(define turquoise
  (make-shader
    (make-color (make-point 0.0 0.9999 0.6666))
    object-phong
    0.75 ; reflection
    #f)) ; shadows

(define sky-blue (make-point 0.5 0.55 0.9999))
(define white (make-point 0.9999 0.9999 0.9999))
(define yellow (make-point 0.9999 0.9999 0.0))
(define green (make-point 0.0 0.9999 0.0))

(define checker-shader
  (make-shader
    (make-checker-color 1.0 yellow green)
    ground-phong
    0.0 ; reflection
    #f)) ; shadows

(define (make-checkered-grid)
  (make-square
    (make-point -15.0 0.0001 -15.0)
    (make-point -15.0 0.0001  15.0)
    (make-point  15.0 0.0001  15.0)
    (make-point  15.0 0.0001 -15.0)
    checker-shader))

(define (make-icosahedron location shader)
  (let*
    ((t (/ (+ 1.0 (sqrt 5.0)) 2.0))
     (t2 (/ 1.0 (sqrt (+ 1.0 (* t t)))))
     (a (* (+ 0.65 clock) 2.0 pi)))
    (let
      ((v0 (vec-add location
         (rotate-y (vec-scale t2 (make-point t 1.0 0.0)) a)))
       (v1 (vec-add location
         (rotate-y (vec-scale t2 (make-point (- t) 1.0 0.0)) a)))
       (v2 (vec-add location
         (rotate-y (vec-scale t2 (make-point t -1.0 0.0)) a)))
       (v3 (vec-add location
         (rotate-y (vec-scale t2 (make-point (- t) -1.0 0.0)) a)))
       (v4 (vec-add location
         (rotate-y (vec-scale t2 (make-point 1.0 0.0 t)) a)))
       (v5 (vec-add location
         (rotate-y (vec-scale t2 (make-point 1.0 0.0 (- t))) a)))
       (v6 (vec-add location
         (rotate-y (vec-scale t2 (make-point -1.0 0.0 t)) a)))
       (v7 (vec-add location
         (rotate-y (vec-scale t2 (make-point -1.0 0.0 (- t))) a)))
       (v8 (vec-add location
         (rotate-y (vec-scale t2 (make-point 0.0 t 1.0)) a)))
       (v9 (vec-add location
         (rotate-y (vec-scale t2 (make-point 0.0 (- t) 1.0)) a)))
       (v10 (vec-add location
         (rotate-y (vec-scale t2 (make-point 0.0 t -1.0)) a)))
       (v11 (vec-add location
         (rotate-y (vec-scale t2 (make-point 0.0 (- t) -1.0)) a))))
      (make-triangle v4 v8 v0 shader) 
      (make-triangle v10 v5 v0 shader) 
      (make-triangle v9 v4 v2 shader) 
      (make-triangle v5 v11 v2 shader) 
      (make-triangle v8 v6 v1 shader) 
      (make-triangle v7 v10 v1 shader) 
      (make-triangle v6 v9 v3 shader) 
      (make-triangle v11 v7 v3 shader) 
      (make-triangle v8 v10 v0 shader) 
      (make-triangle v10 v8 v1 shader) 
      (make-triangle v11 v9 v2 shader) 
      (make-triangle v11 v9 v3 shader) 
      (make-triangle v0 v2 v4 shader) 
      (make-triangle v2 v0 v5 shader) 
      (make-triangle v3 v1 v6 shader) 
      (make-triangle v1 v3 v7 shader) 
      (make-triangle v4 v6 v8 shader) 
      (make-triangle v6 v4 v9 shader) 
      (make-triangle v7 v5 v10 shader) 
      (make-triangle v5 v7 v11 shader)))) 

(background sky-blue) ; sky

(make-checkered-grid) ; ground

(let
  ((up (make-point 0.0 1.0 0.0))
   (look-at (make-point 0.0 0.0 0.0))
;  (location (make-point 0.0 1.0 -12.0))) ; non 3D
;  (location (make-point -0.25 1.0 -12.0))) ; 3D - right side
   (location (make-point 0.25 1.0 -12.0))) ; 3D - left side
  (make-camera
    0 ; normal perspective
;   1 ; fisheye perspective
    up
    location
    look-at
    45.0)) ; angle

(make-light
  (make-point 1000.0 1000.0 -1000.0) ; location
  white)

(make-fog
  sky-blue ; color
  25.0) ; distance

(make-sphere
  (make-point -2.0 0.8 -4.5) ; center
  0.8 ; radius
  red)

(make-cylinder
  (make-point 0.5 1.7 -2.6) ; top cap
  (make-point 0.0 -1.0 -2.0) ; bottom cap
  0.5 ; radius
  purple)

(make-cylinder
  (make-point -0.5 0.25 -7.0) ; top cap
  (make-point 0.5 0.25 -9.5) ; bottom cap
  0.25 ; radius
  turquoise)

(make-icosahedron (make-point 2.0 0.6 -4.2) orange)
