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
*
42 (vector2d-values* (* s x
) (* s y
))))
44 (def-tuple-op vector2d-length
*
45 ((vec vector2d
(x y
)))
47 (sqrt (+ (* x x
) (* y y
)))))
49 (def-tuple-op vector2d-dot
*
50 ((veca vector2d
(xa ya
))
51 (vecb vector2d
(xb yb
)))
53 (sqrt (+ (* xa xb
) (* ya yb
)))))
56 (def-tuple-op vector2d-normal
*
57 ((vec vector2d
(x y
)))
59 (let ((mag (/ 1.0 (vector2d-length vec
))))
64 (def-tuple-op vector2d-vertex2d
*
65 ((vec vector2d
(x y
)))
67 (vertex3d-values* x y
1.0)))
69 (def-tuple-op vertex2d-vector2d
*
70 ((vert vertex2d
(x y w
)))
72 (vector2d-values* x y
)))
75 (def-tuple-op vector3d-scale
*
76 ((vec vector3d
(x y z
))
79 (vector3d-values* (* s x
) (* s y
) (* s z
))))
81 (def-tuple-op vector3d-length
*
82 ((vec vector3d
(x y z
)))
84 (sqrt (+ (* x x
) (* y y
) (* z z
)))))
86 (def-tuple-op vector3d-dot
*
87 ((veca vector3d
(xa ya za
))
88 (vecb vector3d
(xb yb zb
)))
90 (+ (* xa xb
) (* ya yb
) (* za zb
))))
92 (def-tuple-op vector3d-difference
*
93 ((veca vector3d
(xa ya za
))
94 (vecb vector3d
(xb yb zb
)))
101 (def-tuple-op vector3d-sum
*
102 ((veca vector3d
(xa ya za
))
103 (vecb vector3d
(xb yb zb
)))
110 (def-tuple-op vector3d-normal
*
111 ((vec vector3d
(x y z
)))
114 ((mag (vector3d-length* vec
)))
121 (def-tuple-op vector3d-vertex3d
*
122 ((vec vector3d
(x y z
)))
124 (vertex3d-values* x y z
1.0)))
126 (def-tuple-op vertex3d-vector3d
*
127 ((vert vertex3d
(x y z w
)))
129 (vector3d-values* x y z
)))
131 (def-tuple-op vector3d-cross
*
132 ((lhs vector3d
(lhs-x lhs-y lhs-z
))
133 (rhs vector3d
(rhs-x rhs-y rhs-z
)))
136 (- (* lhs-y rhs-z
) (* lhs-z rhs-y
))
137 (- (* lhs-z rhs-x
) (* lhs-x rhs-z
))
138 (- (* lhs-x rhs-y
) (* lhs-y rhs-x
)))))
141 (def-tuple-op vertex3d-distance
*
142 ((start vertex3d
(ox oy oz ow
))
143 (end vertex3d
(ex ey ez ew
)))
145 (vector3d-length* (vector3d-values* (- ex ox
) (- ey oy
) (- ez oz
)))))
147 (def-tuple-op delta-vector3d
*
148 ((start vertex3d
(ox oy oz ow
))
149 (end vertex3d
(ex ey ez ew
)))
151 (vector3d-values* (- ex ox
) (- ey oy
) (- ez oz
))))
155 ;; convert 2 3d vectors to angle axis
157 ;; construct 44 matrix from 3 / a2 3d vectors