summaryrefslogtreecommitdiff
path: root/sly/math/transform.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2016-02-27 20:45:09 -0500
committerDavid Thompson <dthompson2@worcester.edu>2016-02-27 20:45:09 -0500
commit873d00e01e7d714fd3cbbb86d3da88380c179145 (patch)
tree3f6d34fa1cdf08ec17475126451f93fd86847ecf /sly/math/transform.scm
parenta319acd01ac950d479d43d77c07d44a9af3012cd (diff)
math: Rewrite vector math library to use packed f64 bytevectors.
The big consequence of this change to the rest of the codebase is that we can no longer use record destructuring when pattern matching, so I had to rewrite every place where pattern matching was used. It was probably a bad idea to expose the record type descriptors publicly in the first place. * sly/math/vector.scm: Reimplement everything in terms of an f64 packed bytevector record type. Do not expose record type descriptors. * sly/game.scm (run-game-loop): Convert viewport width/height to exact numbers. * sly/window.scm (open-window): Likewise. * sly/input/mouse.scm (mouse-position): Rewrite pattern matching. * sly/math/quaternion (make-quaternion, vector->quaternion): Likewise. * sly/math/rect.scm (rect-clamp): Likewise. * sly/math/transform.scm (translate!, translate, scale): Likewise. * sly/render/mesh.scm (vertices-bytevector): Likewise. * examples/mines/mines.scm: Likewise.
Diffstat (limited to 'sly/math/transform.scm')
-rw-r--r--sly/math/transform.scm75
1 files changed, 45 insertions, 30 deletions
diff --git a/sly/math/transform.scm b/sly/math/transform.scm
index 38fd464..234f6b1 100644
--- a/sly/math/transform.scm
+++ b/sly/math/transform.scm
@@ -275,29 +275,39 @@ called without any arguments."
(define (translate! t . args)
(match args
- (($ <vector2> x y)
- (make-transform 1 0 0 0
- 0 1 0 0
- 0 0 1 0
- x y 0 1))
- (($ <vector3> x y z)
- (make-transform 1 0 0 0
- 0 1 0 0
- 0 0 1 0
- x y z 1))))
+ ((? transform? v)
+ (let ((x (vector2-x v))
+ (y (vector2-y v)))
+ (make-transform 1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ x y 0 1)))
+ ((? vector3? v)
+ (let ((x (vector3-x v))
+ (y (vector3-y v))
+ (z (vector3-z v)))
+ (make-transform 1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ x y z 1)))))
(define translate
(match-lambda
- (($ <vector2> x y)
- (make-transform 1 0 0 0
- 0 1 0 0
- 0 0 1 0
- x y 0 1))
- (($ <vector3> x y z)
- (make-transform 1 0 0 0
- 0 1 0 0
- 0 0 1 0
- x y z 1))
+ ((? vector2? v)
+ (let ((x (vector2-x v))
+ (y (vector2-y v)))
+ (make-transform 1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ x y 0 1)))
+ ((? vector3? v)
+ (let ((x (vector3-x v))
+ (y (vector3-y v))
+ (z (vector3-z v)))
+ (make-transform 1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ x y z 1)))
(v (error "Invalid translation vector: " v))))
(define scale
@@ -307,16 +317,21 @@ called without any arguments."
0 v 0 0
0 0 v 0
0 0 0 1))
- (($ <vector2> x y)
- (make-transform x 0 0 0
- 0 y 0 0
- 0 0 1 0
- 0 0 0 1))
- (($ <vector3> x y z)
- (make-transform x 0 0 0
- 0 y 0 0
- 0 0 z 0
- 0 0 0 1))
+ ((? vector2? v)
+ (let ((x (vector2-x v))
+ (y (vector2-y v)))
+ (make-transform x 0 0 0
+ 0 y 0 0
+ 0 0 1 0
+ 0 0 0 1)))
+ ((? vector3? v)
+ (let ((x (vector3-x v))
+ (y (vector3-y v))
+ (z (vector3-z v)))
+ (make-transform x 0 0 0
+ 0 y 0 0
+ 0 0 z 0
+ 0 0 0 1)))
(v (error "Invalid scaling vector: " v))))
(define (rotate-x angle)