summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2019-10-11 17:10:23 -0400
committerDavid Thompson <dthompson2@worcester.edu>2019-10-11 17:10:23 -0400
commitc96755203de5db668d4aba3d5aec90053c13296d (patch)
treed6aa5b9cddf3e458e8bafc9fc0e1e032b36bb3a2
parentf85d5ba0a00e25bf063b8f9c993c815490bc483a (diff)
math: matrix: Add procedures for X and Y axis rotations.
-rw-r--r--chickadee/math/matrix.scm30
1 files changed, 30 insertions, 0 deletions
diff --git a/chickadee/math/matrix.scm b/chickadee/math/matrix.scm
index 3e73f0c..27b2fc7 100644
--- a/chickadee/math/matrix.scm
+++ b/chickadee/math/matrix.scm
@@ -42,6 +42,10 @@
matrix4-scale
matrix4-rotate!
matrix4-rotate
+ matrix4-rotate-x!
+ matrix4-rotate-x
+ matrix4-rotate-y!
+ matrix4-rotate-y
matrix4-rotate-z!
matrix4-rotate-z
matrix4-2d-transform!
@@ -367,6 +371,32 @@ clipping plane NEAR and FAR."
(matrix4-rotate! matrix q)
matrix))
+(define (matrix4-rotate-x! matrix angle)
+ (init-matrix4 matrix
+ 1.0 0.0 0.0 0.0
+ 0.0 (cos angle) (- (sin angle)) 0.0
+ 0.0 (sin angle) (cos angle) 0.0
+ 0.0 0.0 0.0 1.0))
+
+(define (matrix4-rotate-x angle)
+ "Return a new matrix that rotates about the X axis by ANGLE radians."
+ (let ((matrix (make-null-matrix4)))
+ (matrix4-rotate-x! matrix angle)
+ matrix))
+
+(define (matrix4-rotate-y! matrix angle)
+ (init-matrix4 matrix
+ (cos angle) 0.0 (- (sin angle)) 0.0
+ 0.0 1.0 0.0 0.0
+ (sin angle) 0.0 (cos angle) 0.0
+ 0.0 0.0 0.0 1.0))
+
+(define (matrix4-rotate-y angle)
+ "Return a new matrix that rotates about the Y axis by ANGLE radians."
+ (let ((matrix (make-null-matrix4)))
+ (matrix4-rotate-y! matrix angle)
+ matrix))
+
(define (matrix4-rotate-z! matrix angle)
(init-matrix4 matrix
(cos angle) (- (sin angle)) 0.0 0.0