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 (def-tuple-op vector3d-length
62 ((vec vector3d
(x y z
)))
64 (sqrt (+ (* x x
) (* y y
) (* z z
)))))
66 (def-tuple-op vector3d-dot
67 ((veca vector3d
(xa ya za
))
68 (vecb vector3d
(xb yb zb
)))
70 (+ (* xa xb
) (* ya yb
) (* za zb
))))
72 (def-tuple-op vector3d-difference
73 ((veca vector3d
(xa ya za
))
74 (vecb vector3d
(xb yb zb
)))
81 (def-tuple-op vector3d-sum
82 ((veca vector3d
(xa ya za
))
83 (vecb vector3d
(xb yb zb
)))
90 (def-tuple-op vector3d-normal
91 ((vec vector3d
(x y z
)))
94 ((mag (sqrt (+ (* x x
) (* y y
) (* z z
)))))
101 (def-tuple-op vector3d-vertex3d
102 ((vector3d vec
(x y z
)))
104 (vertex3d-tuple x y z
1.0)))
106 (def-tuple-op vertex3d-vector3d
107 ((vert vertex3d
(x y z w
)))
109 (vector3d-tuple x y z
)))
112 (def-tuple-op vector3d-cross
113 ((lhs vector3d
(lhs-x lhs-y lhs-z
))
114 (rhs vector3d
(rhs-x rhs-y rhs-z
)))
117 (- (* lhs-y rhs-z
) (* lhs-z rhs-y
))
118 (- (* lhs-z rhs-x
) (* lhs-x rhs-z
))
119 (- (* lhs-x rhs-y
) (* lhs-y rhs-x
)))))
122 (def-tuple-op vertex3d-distance
123 ((start vertex3d
(ox oy oz ow
))
124 (end vertex3d
(ex ey ez ew
)))
125 (:return single-float
126 (vector3d-length (values (- ex ox
) (- ey oy
) (- ez oz
)))))
128 (def-tuple-op delta-vector3d
129 ((start vertex3d
(ox oy oz ow
))
130 (end vertex3d
(ex ey ez ew
)))
132 (vector3d-tuple (- ex ox
) (- ey oy
) (- ez oz
))))
136 ;; convert 2 3d vectors to angle axis
138 ;; construct 44 matrix from 3 / a2 3d vectors