summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-08-27 18:22:06 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-08-27 18:22:06 -0400
commit5841889f53465b4096830f3778b209063e1fe8bc (patch)
tree724087d4dbfeb08349401d7ff19e0f099a550667 /2d
parente719d1e988617f623fac29c1bd347785833c5f71 (diff)
Replace old vector module with new vector2 module.
Diffstat (limited to '2d')
-rw-r--r--2d/font.scm2
-rw-r--r--2d/sprite.scm14
-rw-r--r--2d/vector.scm90
3 files changed, 9 insertions, 97 deletions
diff --git a/2d/font.scm b/2d/font.scm
index 8bf66a3..45b59d0 100644
--- a/2d/font.scm
+++ b/2d/font.scm
@@ -27,7 +27,7 @@
#:use-module (system foreign)
#:use-module (2d wrappers ftgl)
#:use-module (2d color)
- #:use-module (2d vector))
+ #:use-module (2d vector2))
;;;
;;; Font
diff --git a/2d/sprite.scm b/2d/sprite.scm
index b652f4d..ac57adb 100644
--- a/2d/sprite.scm
+++ b/2d/sprite.scm
@@ -33,8 +33,8 @@
#:use-module (2d helpers)
#:use-module (2d math)
#:use-module (2d texture)
- #:use-module (2d wrappers gl)
- #:use-module (2d vector))
+ #:use-module (2d vector2)
+ #:use-module (2d wrappers gl))
;;;
;;; Sprite Vertices
@@ -156,7 +156,8 @@
(dirty sprite-dirty? set-sprite-dirty!)
(animation-state sprite-animation-state set-sprite-animation-state!))
-(define* (make-sprite drawable #:optional #:key (position #(0 0)) (scale #(1 1))
+(define* (make-sprite drawable #:optional #:key
+ (position (vector2 0 0)) (scale (vector2 1 1))
(rotation 0) (color white) (anchor 'center))
"Makes a new sprite object."
(let ((vertices (make-packed-array sprite-vertex 4))
@@ -179,7 +180,8 @@ operation that requires a refresh of the vertex array should use this macro."
(dirty-sprite-setter set-sprite-color! %set-sprite-color!)
(dirty-sprite-setter set-sprite-anchor! %set-sprite-anchor!)
-(define* (load-sprite filename #:optional #:key (position #(0 0)) (scale #(1 1))
+(define* (load-sprite filename #:optional #:key
+ (position (vector2 0 0)) (scale (vector2 1 1))
(rotation 0) (color white) (anchor 'center))
"Loads a sprite from file."
(make-sprite (load-texture filename) #:position position #:scale scale
@@ -203,8 +205,8 @@ sprite."
(texture (sprite-texture sprite)))
(cond
((eq? anchor 'center)
- (vector (/ (texture-width texture) 2)
- (/ (texture-height texture) 2)))
+ (vector2 (/ (texture-width texture) 2)
+ (/ (texture-height texture) 2)))
(else anchor))))
(define (update-sprite-vertices! sprite)
diff --git a/2d/vector.scm b/2d/vector.scm
deleted file mode 100644
index c6817ec..0000000
--- a/2d/vector.scm
+++ /dev/null
@@ -1,90 +0,0 @@
-;;; guile-2d
-;;; Copyright (C) 2013 David Thompson <dthompson2@worcester.edu>
-;;;
-;;; Guile-2d is free software: you can redistribute it and/or modify it
-;;; under the terms of the GNU Lesser General Public License as
-;;; published by the Free Software Foundation, either version 3 of the
-;;; License, or (at your option) any later version.
-;;;
-;;; Guile-2d is distributed in the hope that it will be useful, but
-;;; WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-;;; Lesser General Public License for more details.
-;;;
-;;; You should have received a copy of the GNU Lesser General Public
-;;; License along with this program. If not, see
-;;; <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-;;
-;; Vector math operations.
-;;
-;;; Code:
-
-(define-module (2d vector)
- #:use-module (rnrs base)
- #:export (vx
- vy
- vz
- v+
- v*
- scale
- mag
- normalize
- vector-reduce
- vector-from-polar))
-
-(define (vx vector)
- "Returns the first element of a vector."
- (vector-ref vector 0))
-
-(define (vy vector)
- "Returns the second element of a vector."
- (vector-ref vector 1))
-
-(define (vz vector)
- "Returns the third element of a vector."
- (vector-ref vector 2))
-
-(define (v+ . vectors)
- "Adds vectors."
- (apply vector-map + vectors))
-
-(define (v* . vectors)
- "Multiplies vectors."
- (apply vector-map * vectors))
-
-(define (scale vector scalar)
- "Multiplies a vector by a scalar."
- (vector-map (lambda (e) (* scalar e)) vector))
-
-(define (mag vector)
- "Returns the magnitude of a vector."
- (sqrt (vector-reduce + 0 (vector-map (lambda (e) (* e e)) vector))))
-
-(define (normalize vector)
- "Normalizes a vector."
- (let ((m (mag vector)))
- (vector-map (lambda (e) (/ e m)) vector)))
-
-(define (vector-reduce proc default vector)
- "Performs a reduce operation on a vector."
- (cond ((= (vector-length vector) 0)
- default)
- ((= (vector-length vector) 1)
- (vector-ref vector 0))
- (else
- (let loop ((i 2)
- (prev (proc (vector-ref vector 0)
- (vector-ref vector 1))))
- (if (= (vector-length vector) i)
- prev
- (loop (1+ i) (proc prev (vector-ref vector i))))))))
-
-(define (vector-from-polar r theta)
- "Converts polar coordinates into a cartesian vector."
- (vector (* r (cos theta))
- (* r (sin theta))))
-
-(re-export (vector-map . vector-map)
- (vector-for-each . vector-for-each))