From dda297a7dfb9a39eedcd668ffdb395e7e90abd34 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 23 Oct 2014 18:46:17 -0400 Subject: Move rotate procedure to transform module. * sly/quaternion.scm (rotate): Remove. * sly/transform.scm (rotate): New procedure. --- sly/quaternion.scm | 21 +-------------------- sly/transform.scm | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/sly/quaternion.scm b/sly/quaternion.scm index fe5cce9..48ebba4 100644 --- a/sly/quaternion.scm +++ b/sly/quaternion.scm @@ -26,7 +26,6 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:use-module (sly math) - #:use-module (sly transform) #:use-module (sly math vector) #:export ( make-quaternion quaternion quaternion? @@ -34,8 +33,7 @@ identity-quaternion null-quaternion quaternion* quaternion-slerp quaternion-magnitude quaternion-normalize - vector->quaternion quaternion->vector - rotate)) + vector->quaternion quaternion->vector)) (define-record-type (%make-quaternion w x y z) @@ -112,20 +110,3 @@ Q2 and blending factor DELTA." (match-lambda (($ x y z w) (make-quaternion x y z w)))) - -(define rotate - (match-lambda - (($ w x y z) - (make-transform - (- 1 (* 2 (square y)) (* 2 (square z))) - (- (* 2 x y) (* 2 w z)) - (+ (* 2 x z) (* 2 w y)) - 0 - (+ (* 2 x y) (* 2 w z)) - (- 1 (* 2 (square x)) (* 2 (square z))) - (- (* 2 y z) (* 2 w x)) - 0 - (- (* 2 x z) (* 2 w y)) - (+ (* 2 y z) (* 2 w x)) - (- 1 (* 2 (square x)) (* 2 (square y))) - 0 0 0 0 1)))) diff --git a/sly/transform.scm b/sly/transform.scm index 95324ed..205ecbe 100644 --- a/sly/transform.scm +++ b/sly/transform.scm @@ -28,11 +28,12 @@ #:use-module (srfi srfi-42) #:use-module (sly math) #:use-module (sly math vector) + #:use-module (sly quaternion) #:export (make-transform null-transform identity-transform transform? transform-matrix transpose transform-vector2 transform+ transform* - scale translate rotate-x rotate-y rotate-z + scale translate rotate-x rotate-y rotate-z rotate orthographic-projection perspective-projection look-at)) @@ -184,6 +185,23 @@ identity-transform if called without any arguments." 0 0 1 0 0 0 0 1)) +(define rotate + (match-lambda + (($ w x y z) + (make-transform + (- 1 (* 2 (square y)) (* 2 (square z))) + (- (* 2 x y) (* 2 w z)) + (+ (* 2 x z) (* 2 w y)) + 0 + (+ (* 2 x y) (* 2 w z)) + (- 1 (* 2 (square x)) (* 2 (square z))) + (- (* 2 y z) (* 2 w x)) + 0 + (- (* 2 x z) (* 2 w y)) + (+ (* 2 y z) (* 2 w x)) + (- 1 (* 2 (square x)) (* 2 (square y))) + 0 0 0 0 1)))) + (define (orthographic-projection left right top bottom near far) "Return a new transform that represents an orthographic projection for the vertical clipping plane LEFT and RIGHT, the horizontal -- cgit v1.2.3