diff options
Diffstat (limited to 'chickadee/math/matrix.scm')
-rw-r--r-- | chickadee/math/matrix.scm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/chickadee/math/matrix.scm b/chickadee/math/matrix.scm index c86b20c..1d59674 100644 --- a/chickadee/math/matrix.scm +++ b/chickadee/math/matrix.scm @@ -24,6 +24,7 @@ #:use-module (srfi srfi-4) #:use-module (system foreign) #:use-module (chickadee math) + #:use-module (chickadee math quaternion) #:use-module (chickadee math vector) #:export (make-matrix4 make-null-matrix4 @@ -38,6 +39,8 @@ matrix4-translate matrix4-scale! matrix4-scale + matrix4-rotate! + matrix4-rotate matrix4-rotate-z! matrix4-rotate-z transform!)) @@ -317,6 +320,35 @@ clipping plane NEAR and FAR." (matrix4-scale! matrix s) matrix)) +(define (matrix4-rotate! matrix q) + "Return a new rotation matrix for the quaternion Q." + (let ((x (quaternion-x q)) + (y (quaternion-y q)) + (z (quaternion-z q)) + (w (quaternion-w q))) + (init-matrix4 matrix + (- 1.0 (* 2.0 (* y y)) (* 2.0 (* z z))) + (- (* 2.0 x y) (* 2.0 w z)) + (+ (* 2.0 x z) (* 2.0 w y)) + 0 + (+ (* 2.0 x y) (* 2.0 w z)) + (- 1.0 (* 2.0 (* x x)) (* 2.0 (* z z))) + (- (* 2.0 y z) (* 2.0 w x)) + 0 + (- (* 2.0 x z) (* 2.0 w y)) + (+ (* 2.0 y z) (* 2.0 w x)) + (- 1.0 (* 2.0 (* x x)) (* 2.0 (* y y))) + 0.0 + 0.0 + 0.0 + 0.0 + 1.0))) + +(define (matrix4-rotate q) + (let ((matrix (make-null-matrix4))) + (matrix4-rotate! matrix q) + matrix)) + (define (matrix4-rotate-z! matrix angle) (init-matrix4 matrix (cos angle) (- (sin angle)) 0.0 0.0 |