diff options
-rw-r--r-- | chickadee/render/sprite.scm | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/chickadee/render/sprite.scm b/chickadee/render/sprite.scm index 2288edf..318a8a5 100644 --- a/chickadee/render/sprite.scm +++ b/chickadee/render/sprite.scm @@ -205,9 +205,9 @@ void main (void) { (define sprite-batch-add! (let ((tmp-matrix (make-null-matrix4)) (matrix (make-null-matrix4)) - (position (vec2 0 0)) - (world1 (vec2 0 0)) - (world2 (vec2 0 0)) + (position (vec2 0.0 0.0)) + (world1 (vec2 0.0 0.0)) + (world2 (vec2 0.0 0.0)) (offset-bv (make-u32vector 1))) (define (set-offset offset) (u32vector-set! offset-bv 0 offset)) @@ -235,6 +235,8 @@ void main (void) { (indices (vertex-buffer-data (sprite-batch-index-buffer batch))) (vertices (vertex-buffer-data (sprite-batch-position-buffer batch))) (texcoords (vertex-buffer-data (sprite-batch-texture-buffer batch))) + (rx (rect-x region)) + (ry (rect-y region)) (local-x1 0.0) (local-y1 0.0) (local-x2 (rect-width region)) @@ -243,23 +245,30 @@ void main (void) { (t1 (rect-bottom texture-region)) (s2 (rect-right texture-region)) (t2 (rect-top texture-region))) - (matrix4-identity! matrix) - (when rotation - (matrix4-rotate-z! tmp-matrix rotation) - (matrix4-mult! matrix matrix tmp-matrix)) - (when scale - (matrix4-scale! tmp-matrix scale) - (matrix4-mult! matrix matrix tmp-matrix)) - (set-vec2-x! position (rect-x region)) - (set-vec2-y! position (rect-y region)) - (matrix4-translate! tmp-matrix position) - (matrix4-mult! matrix matrix tmp-matrix) - (set-vec2-x! world1 local-x1) - (set-vec2-y! world1 local-y1) - (set-vec2-x! world2 local-x2) - (set-vec2-y! world2 local-y2) - (transform! matrix world1) - (transform! matrix world2) + (if (or rotation scale) + (begin + (matrix4-identity! matrix) + (when rotation + (matrix4-rotate-z! tmp-matrix rotation) + (matrix4-mult! matrix matrix tmp-matrix)) + (when scale + (matrix4-scale! tmp-matrix scale) + (matrix4-mult! matrix matrix tmp-matrix)) + (set-vec2-x! position rx) + (set-vec2-y! position ry) + (matrix4-translate! tmp-matrix position) + (matrix4-mult! matrix matrix tmp-matrix) + (set-vec2-x! world1 local-x1) + (set-vec2-y! world1 local-y1) + (set-vec2-x! world2 local-x2) + (set-vec2-y! world2 local-y2) + (transform! matrix world1) + (transform! matrix world2)) + (begin + (set-vec2-x! world1 (+ local-x1 rx)) + (set-vec2-y! world1 (+ local-y1 ry)) + (set-vec2-x! world2 (+ local-x2 rx)) + (set-vec2-y! world2 (+ local-y2 ry)))) (let ((world-x1 (vec2-x world1)) (world-y1 (vec2-y world1)) (world-x2 (vec2-x world2)) |