2 (in-package :cl-tuples
)
5 (def-tuple-type vector2d
6 :tuple-element-type single-float
9 (export-tuple-operations vector2d
)
11 (def-tuple-type vertex2d
12 :tuple-element-type single-float
15 (export-tuple-operations vertex3d
)
17 (def-tuple-type vector3d
18 :tuple-element-type single-float
21 (export-tuple-operations vector3d
)
23 (def-tuple-type vertex3d
24 :tuple-element-type single-float
27 (export-tuple-operations vertex3d
)
30 (defmacro vector2d-mag-square
(vector2d)
31 `(reduce-vector2d-tuple #'+ (map-vector2d-values #'* ,vector2d
,vector2d
)))
33 (defmacro vector2d-length
(vector2d)
34 `(sqrt (vector2d-mag-square ,vector2d
)))
36 (defmacro vector2d-dot
(vector2d-lhs vector2d-rhs
)
37 `(reduce-vector2d-tuple
38 #'+ (map-vector2d-tuples #'* ,vector2d-lhs
,vector2d-rhs
)))
40 (defmacro vector2d-normal
(vector2d)
42 ((mag (vector2d-length ,vector2d
)))
46 (values (/ x length
) (/ y length
)))))
48 (defmacro vector2d-vertex2d
(vector2d)
49 `(with-vector2d ,vector2d
53 (defmacro vertex2d-vector2d
(vertex2d)
54 `(with-vertex2d ,vertex2d
58 ;; make 33 matrix from 2 2d vectors
61 (defmacro vector3d-mag-square
(vector3d)
62 `(reduce-vector3d-tuple
64 (map-vector3d-tuples #'* ,vector3d
,vector3d
)))
66 (defmacro vector3d-length
(vector3d)
67 `(sqrt (vector3d-mag-square ,vector3d
)))
70 (defmacro vector3d-dot
(vector3d-lhs vector3d-rhs
)
71 `(reduce-vector3d-tuple
72 #'+ (map-vector3d-tuples #'* ,vector3d-lhs
,vector3d-rhs
)))
74 (defmacro vector3d-difference
(vector3d-lhs vector3d-rhs
)
75 `(map-vector3d-tuples #'-
,vector3d-lhs
,vector3d-rhs
))
77 (defmacro vector3d-sum
(vector3d-lhs vector3d-rhs
)
78 `(map-vector3d-tuples #'+ ,vector3d-lhs
,vector3d-rhs
))
80 (defmacro vector3d-normal
(vector3d)
86 ((,mag
(vector3d-length ,vector3d
)))
90 (values (/ ,x
,mag
) (/ ,y
,mag
) (/ ,z
,mag
))))))
92 (defmacro vector3d-vertex3d
(vector3d)
96 `(with-vector3d ,vector3d
98 (values ,x
,y
,z
1.0))))
100 (defmacro vertex3d-vector3d
(vertex3d)
105 `(with-vertex3d ,vertex3d
110 (defmacro vector3d-cross
(vector3d-lhs vector3d-rhs
)
111 (let ((lhs-x (gensym))
119 (,lhs-x
,lhs-y
,lhs-z
)
122 (,rhs-x
,rhs-y
,rhs-z
)
123 (values (- (* ,lhs-y
,rhs-z
) (* ,lhs-z
,rhs-y
))
124 (- (* ,lhs-z
,rhs-x
) (* ,lhs-x
,rhs-z
))
125 (- (* ,lhs-z
,rhs-y
) (* ,lhs-y
,rhs-x
)))))))
127 (def-tuple-op vertex3d-distance
128 ((start vertex3d
(ox oy oz ow
))
129 (end vertex3d
(ex ey ez ew
)))
130 (vector3d-length (values (- ex ox
) (- ey oy
) (- ez oz
))))
132 (def-tuple-op delta-vector3d
133 ((start vertex3d
(ox oy oz ow
))
134 (end vertex3d
(ex ey ez ew
)))
135 (vector3d-tuple (- ex ox
) (- ey oy
) (- ez oz
)))
137 (the (unsigned-int) )
140 ;; convert 2 3d vectors to angle axis
142 ;; construct 44 matrix from 3 / a2 3d vectors