From c96755203de5db668d4aba3d5aec90053c13296d Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 11 Oct 2019 17:10:23 -0400 Subject: math: matrix: Add procedures for X and Y axis rotations. --- chickadee/math/matrix.scm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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 -- cgit v1.2.3