Skip to content

Commit

Permalink
Change SINGLE- to FAST-PI. Fixes for README.
Browse files Browse the repository at this point in the history
Also export FAST-PI.  The README now mentions how to enable the reader
syntax (which was previously on by default).  The functionality to
transform vectors is explained, vertexes are missing though.
  • Loading branch information
Ferada committed Feb 9, 2013
1 parent ab8fed6 commit cdf91d5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,25 @@ without ever creating a vector object.

The reader syntax may be used to the same effect:

> (enable-tuples-syntax)
> #{1.0 1.0}
1.0
1.0
> (vector2d-length* #{1.0 1.0})
1.4142135

(Since the reader syntax and `VECTOR2D-VALUES` expand directly into a
`VALUES` call, nothing prevents you from using that as well.)

Based on this design more operations are implemented. See the API and
the tests for details on vectors, vertexes, matrixes and quaternions.

Defining new operators is done via `DEF-TUPLE-OP`, e.g.:

(def-tuple-op scaling-matrix44*
((sx cl-tuples::fast-float)
(sy cl-tuples::fast-float)
(sz cl-tuples::fast-float))
((sx fast-float)
(sy fast-float)
(sz fast-float))
(:return matrix44
(matrix44-values*
sx 0.0f0 0.0f0 0.0f0
Expand Down Expand Up @@ -110,17 +114,45 @@ Quaternion addition and multiplication are supported.
(quaternion-values* 1f0 1f0 0f0 1f0)))
#(4.0 1.0 0.0 1.0)
> (make-quaternion*
(quaternion-dot* (quaternion-values* 3f0 0f0 0f0 0f0)
(quaternion-values* 1f0 1f0 0f0 1f0)))
(quaternion-product* (quaternion-values* 3f0 0f0 0f0 0f0)
(quaternion-values* 1f0 1f0 0f0 1f0)))
#(3.0 0.0 3.0 -3.0)

Unit quaternions may be used to represent rotations. Functions are
provided for working with quaternions for this purpose.

> (values fast-pi (type-of fast-pi))
3.1415927
SINGLE-FLOAT
> (make-quaternion*
(angle-axis-quaternion*
(angle-axis-values* 0f0 0f0 1f0 (coerce (/ pi 2f0) 'single-float))))
(angle-axis-values* 0f0 0f0 1f0 (/ single-pi 2f0))))
#(0.0 0.0 0.70710677 0.70710677)

(`ROTATE-VECTOR-WITH-QUATERNION` and `ROTATE-VECTOR-BY-AXIS-ANGLE`
missing though.)
Vectors can then be transformed using these quaternions.

> (quaternion-transform-vector3d*
(vector3d-values* 0.0 1.0 0.0)
(angle-axis-quaternion*
(angle-axis-values* 0.0 0.0 1.0 (/ fast-pi 2))))
-0.99999994
0.0
0.0

At the moment you have still to convert an angle-axis representation to
either a matrix or a quaternion by yourself to rotate a vector by it.

> (quaternion-transform-vector3d*
(vector3d-values* 0.0 1.0 0.0)
(angle-axis-quaternion*
(angle-axis-values* 0.0 0.0 1.0 fast-pi)))
8.742278e-8
-1.0
0.0
> (transform-vector3d*
(angle-axis-matrix33*
(angle-axis-values* 0.0 0.0 1.0 fast-pi))
(vector3d-values* 0.0 1.0 0.0))
8.742278e-8
-1.0
0.0
1 change: 1 addition & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
def-tuple-op

fast-float
fast-pi

vector2d-dot*
vector2d-mag-square*
Expand Down
4 changes: 2 additions & 2 deletions quaternion.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
(let* ((trace (matrix33-trace* m))
(angle (acos (/ (1- trace) 2))))
(declare (type (single-float -1.0 3.0) trace)
(type (single-float 0.0 #.single-pi)))
(type (single-float 0.0 #.fast-pi)))
(cond
((= angle 0.0)
(angle-axis-key-values))
((< 0.0 angle single-pi)
((< 0.0 angle fast-pi)
(vector3d-angle-axis*
(vector3d-normal*
(vector3d-values*
Expand Down
4 changes: 2 additions & 2 deletions utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
(deftype fast-float ()
`(single-float (#.(- (expt 2f0 64))) (#.(expt 2f0 64))))

(defconstant single-pi
#.(coerce pi 'single-float))
(defconstant fast-pi
#.(coerce pi 'fast-float))

;; define helper functions we will use

Expand Down

0 comments on commit cdf91d5

Please sign in to comment.