summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee/render/scene.scm39
1 files changed, 17 insertions, 22 deletions
diff --git a/chickadee/render/scene.scm b/chickadee/render/scene.scm
index 8aa6f1f..434f301 100644
--- a/chickadee/render/scene.scm
+++ b/chickadee/render/scene.scm
@@ -143,11 +143,12 @@
(force shader))))
(define-record-type <primitive>
- (%make-primitive vertex-array material targets)
+ (%make-primitive vertex-array material targets matrix)
primitive?
(vertex-array primitive-vertex-array)
(material primitive-material)
- (targets primitive-targets))
+ (targets primitive-targets)
+ (matrix primitive-matrix))
(define (display-primitive primitive port)
(format port "#<primitive material: ~s targets: ~s>"
@@ -160,7 +161,7 @@
vertex-array
(material default-material)
targets)
- (%make-primitive vertex-array material targets))
+ (%make-primitive vertex-array material targets (make-identity-matrix4)))
(define-record-type <mesh>
(%make-mesh name primitives weights)
@@ -181,14 +182,15 @@
(%make-mesh name primitives weights))
(define-record-type <scene-node>
- (%make-scene-node name children camera skin matrix mesh
- rotation scale translation weights)
+ (%make-scene-node name children camera skin matrix world-matrix
+ mesh rotation scale translation weights)
node?
(name scene-node-name)
(children scene-node-children)
(camera scene-node-camera)
(skin scene-node-skin)
(matrix scene-node-matrix)
+ (world-matrix scene-node-world-matrix)
(mesh scene-node-mesh)
(rotation scene-node-rotation)
(scale scene-node-scale)
@@ -211,8 +213,8 @@
(scale (vec3 1.0 1.0 1.0))
(translation (vec3 0.0 0.0 0.0))
weights)
- (%make-scene-node name children camera skin matrix mesh
- rotation scale translation weights))
+ (%make-scene-node name children camera skin matrix (make-identity-matrix4)
+ mesh rotation scale translation weights))
(define-record-type <scene>
(%make-scene name nodes)
@@ -223,21 +225,14 @@
(define* (make-scene #:key (name "anonymous") (nodes '()))
(%make-scene name nodes))
-(define modelview
- (make-matrix4 1.0 0.0 0.0 0.0
- 0.0 1.0 0.0 0.0
- 0.0 0.0 1.0 0.0
- 0.0 0.0 1.0 1.0)
- ;;(make-identity-matrix4)
- )
-
(define (draw-primitive primitive matrix)
;; TODO: Use material.
;; TODO: Actually use physically based rendering.
- (gpu-apply (pbr-shader)
- (primitive-vertex-array primitive)
- #:mvp (matrix4* modelview (current-projection))
- ))
+ (let ((mvp (primitive-matrix primitive)))
+ (matrix4-mult! mvp matrix (current-projection))
+ (gpu-apply (pbr-shader)
+ (primitive-vertex-array primitive)
+ #:mvp mvp)))
(define (draw-mesh mesh matrix)
(for-each (lambda (primitive)
@@ -245,8 +240,8 @@
(mesh-primitives mesh)))
(define (draw-scene-node node matrix)
- ;; TODO: Apply transformation matrix.
- (let ((world-matrix (matrix4* matrix (scene-node-matrix node))))
+ (let ((world-matrix (scene-node-world-matrix node)))
+ (matrix4-mult! world-matrix matrix (scene-node-matrix node))
(when (scene-node-mesh node)
(draw-mesh (scene-node-mesh node) world-matrix))
(for-each (lambda (node)
@@ -255,5 +250,5 @@
(define (draw-scene scene)
(for-each (lambda (scene)
- (draw-scene-node scene (make-identity-matrix4)))
+ (draw-scene-node scene (scene-node-world-matrix scene)))
(scene-nodes scene)))