2 (in-package :cl-tuples
)
8 (def-tuple-type vector2d
9 :tuple-element-type fast-float
10 :initial-element
0.0f0
13 (export-tuple-operations vector2d
)
15 (def-tuple-type vector3d
16 :tuple-element-type fast-float
17 :initial-element
0.0f0
20 (export-tuple-operations vector3d
)
24 (def-tuple-type vertex2d
25 :tuple-element-type fast-float
28 (export-tuple-operations vertex3d
)
30 (def-tuple-type vertex3d
31 :tuple-element-type fast-float
34 (export-tuple-operations vertex3d
)
38 (def-tuple-op vector2d-scale
*
44 (vector2d-values* s s
))))
46 (def-tuple-op vector2d-length
*
47 ((vec vector2d
(x y
)))
49 (sqrt (+ (* x x
) (* y y
)))))
51 (def-tuple-op vector2d-dot
*
52 ((veca vector2d
(xa ya
))
53 (vecb vector2d
(xb yb
)))
55 (sqrt (+ (* xa xb
) (* ya yb
)))))
58 (def-tuple-op vector2d-normal
*
59 ((vec vector2d
(x y
)))
61 (let ((mag (/ 1.0 (vector2d-length vec
))))
66 (def-tuple-op vector2d-vertex2d
*
67 ((vec vector2d
(x y
)))
69 (vertex3d-values* x y
1.0)))
71 (def-tuple-op vertex2d-vector2d
*
72 ((vert vertex2d
(x y w
)))
74 (vector2d-values* x y
)))
77 (def-tuple-op vector3d-scale
*
78 ((vec vector3d
(x y z
))
83 (vector3d-values* s s s
))))
85 (def-tuple-op vector3d-length
*
86 ((vec vector3d
(x y z
)))
88 (sqrt (+ (* x x
) (* y y
) (* z z
)))))
90 (def-tuple-op vector3d-dot
*
91 ((veca vector3d
(xa ya za
))
92 (vecb vector3d
(xb yb zb
)))
94 (+ (* xa xb
) (* ya yb
) (* za zb
))))
96 (def-tuple-op vector3d-difference
*
97 ((veca vector3d
(xa ya za
))
98 (vecb vector3d
(xb yb zb
)))
105 (def-tuple-op vector3d-sum
*
106 ((veca vector3d
(xa ya za
))
107 (vecb vector3d
(xb yb zb
)))
114 (def-tuple-op vector3d-normal
*
115 ((vec vector3d
(x y z
)))
118 ((mag (vector3d-length* vec
)))
125 (def-tuple-op vector3d-vertex3d
*
126 ((vec vector3d
(x y z
)))
128 (vertex3d-values* x y z
1.0)))
130 (def-tuple-op vertex3d-vector3d
*
131 ((vert vertex3d
(x y z w
)))
133 (vector3d-values* x y z
)))
135 (def-tuple-op vector3d-cross
*
136 ((lhs vector3d
(lhs-x lhs-y lhs-z
))
137 (rhs vector3d
(rhs-x rhs-y rhs-z
)))
140 (- (* lhs-y rhs-z
) (* lhs-z rhs-y
))
141 (- (* lhs-z rhs-x
) (* lhs-x rhs-z
))
142 (- (* lhs-x rhs-y
) (* lhs-y rhs-x
)))))
145 (def-tuple-op vertex3d-distance
*
146 ((start vertex3d
(ox oy oz ow
))
147 (end vertex3d
(ex ey ez ew
)))
149 (vector3d-length* (vector3d-values* (- ex ox
) (- ey oy
) (- ez oz
)))))
151 (def-tuple-op delta-vector3d
*
152 ((start vertex3d
(ox oy oz ow
))
153 (end vertex3d
(ex ey ez ew
)))
155 (vector3d-values* (- ex ox
) (- ey oy
) (- ez oz
))))
159 ;; convert 2 3d vectors to angle axis
161 ;; construct 44 matrix from 3 / a2 3d vectors