wavey-wind/anim.scm

126 lines
3.1 KiB
Scheme

(use-modules (chickadee)
(chickadee graphics color)
(chickadee graphics text)
(chickadee graphics pbr)
(chickadee graphics mesh)
(chickadee graphics model)
(chickadee graphics light)
(chickadee graphics skybox)
(chickadee math vector)
(system repl coop-server))
(define repl (spawn-coop-repl-server))
(define (poglej)
(look-at! view-matrix
position
(vec3+ position (vec3 0.0 0.0 1.0))
(vec3 0.0 1.0 0.0)))
(define (update dt)
;; REPL!
(poll-coop-repl-server repl)
;; Stevec gor
(set! stevec (+ stevec 1))
(display (string-append (number->string stevec) "\n"))
(obj-anim dt))
(define rotX 0)
(define rotY 0)
(define rotZ 0)
(define (obj-anim dt)
(set! rotX (+ rotX (/ dt 2)))
(set! rotY (+ rotY (/ dt 1)))
(set! rotZ (+ rotZ (/ dt 1.5)))
(matrix4-copy! (matrix4* (matrix4-scale stevec)
(matrix4-rotate-x rotX)
(matrix4-rotate-y rotY)
(matrix4-rotate-z rotZ))
model-matrix)
;(matrix4-scale! model-matrix stevec)
;(matrix4-mult! model-matrix model-matrix (matrix4-scale stevec))
;(matrix4-rotate-x! model-matrix rotX)
;(matrix4-rotate-y! model-matrix rotY)
;(matrix4-rotate-z! model-matrix rotZ))
)
(define (key-press key modifiers repeat?)
(cond
((eq? key 'q)
(abort-game))
((eq? key 'r)
(reset-stevec))))
(define stevec #f)
(define (reset-stevec)
(set! stevec 1))
(define camera-position (vec3 0.0 0.0 3.0))
(define projection (perspective-projection (/ pi 3.0) (/ 4.0 3.0) 0.1 10.0))
(define view-matrix (make-identity-matrix4))
(define model-matrix (make-identity-matrix4))
(define position (vec3 0.0 0.0 -4.0))
(define (ustvari-tla)
(make-plane 500 500 (make-pbr-material #:base-color-factor (vec3 1.0 0.5 0))))
(define (ustvari-objekt)
(let ((velikost (/ stevec 2000.0))
(barva (vec3 0.2 0.8 0.4)))
(make-cube velikost
(make-pbr-material #:base-color-factor barva))
;(make-plane velikost
; velikost
; (make-pbr-material))
))
(define obj #f)
(define (ustvari-nebo)
(let ((face (list
(u32vector #x12345678
#x87654321
#x12345678
#x87654321)
4
4)))
(make-skybox
(make-cube-map (make-list 6 face)))))
(define (draw alpha)
(with-projection
projection
(draw-mesh obj
#:model-matrix model-matrix
#:view-matrix view-matrix
#:camera-position position
#:lights (list (ustvari-luc))
#:skybox (ustvari-nebo))))
;; :( ne dela?
(define (ustvari-luc)
(make-directional-light
#:direction (vec3 1 1 1)
#:color white
#:intensity 10))
(define (load)
;; Moramo pogledat model
(poglej)
(reset-stevec)
(ustvari-luc)
(set! obj (ustvari-objekt)))
(run-game
#:draw draw
#:update update
#:key-press key-press
#:load load)