summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sly/quaternion.scm21
-rw-r--r--sly/transform.scm20
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 (<quaternion> 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 <quaternion>
(%make-quaternion w x y z)
@@ -112,20 +110,3 @@ Q2 and blending factor DELTA."
(match-lambda
(($ <vector4> x y z w)
(make-quaternion x y z w))))
-
-(define rotate
- (match-lambda
- (($ <quaternion> 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
+ (($ <quaternion> 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