1 (in-package :cl-tuples
)
7 (def-tuple-type vector2d
8 :tuple-element-type fast-float
12 (export-tuple-operations vector2d
)
14 (def-tuple-type vector3d
15 :tuple-element-type fast-float
16 :initial-element
0.0f0
19 (export-tuple-operations vector3d
)
22 (def-tuple-type vertex2d
23 :tuple-element-type fast-float
26 (export-tuple-operations vertex3d
)
28 (def-tuple-type vertex3d
29 :tuple-element-type fast-float
32 (export-tuple-operations vertex3d
)
36 (def-tuple-op vector2d-scale
*
42 (vector2d-key-values :initial-element s
))))
44 (def-tuple-op vector2d-dot
*
49 (+) (vector2d-map* (*) veca vecb
))))
51 (def-tuple-op vector2d-length-square
*
52 ((vec vector2d
(x y
)))
54 (vector2d-dot* vec vec
)))
56 (def-tuple-op vector2d-length
*
57 ((vec vector2d
(x y
)))
59 (sqrt (vector2d-length-square* vec
))))
61 (def-tuple-op vector2d-normal
*
62 ((vec vector2d
(x y
)))
66 (/ (vector2d-length* vec
)))))
68 (def-tuple-op vector2d-vertex2d
*
69 ((vec vector2d
(x y
)))
71 (vertex3d-values* x y
1.0)))
73 (def-tuple-op vertex2d-vector2d
*
74 ((vert vertex2d
(x y w
)))
76 (vector2d-values* x y
)))
78 (def-tuple-op vector3d-scale
*
83 (vector3d-key-values :initial-element s
)
86 (def-tuple-op vector3d-dot
*
87 ((veca vector3d
(xa ya za
))
88 (vecb vector3d
(xb yb zb
)))
91 (+) (vector3d-map* (*) veca vecb
))))
93 (def-tuple-op vector3d-length
*
96 (sqrt (vector3d-dot* vec vec
))))
98 (def-tuple-op vector3d-difference
*
102 (vector3d-map* (-) veca vecb
)))
104 (def-tuple-op vector3d-sum
*
108 (vector3d-map* (+) veca vecb
)))
110 (def-tuple-op vector3d-normal
*
115 (/ (vector3d-length* vec
)))))
117 (def-tuple-op vector3d-vertex3d
*
118 ((vec vector3d
(x y z
)))
120 (vertex3d-values* x y z
1.0)))
122 (def-tuple-op vertex3d-vector3d
*
123 ((vert vertex3d
(x y z w
)))
125 (vector3d-values* x y z
)))
127 (def-tuple-op vector3d-cross
*
128 ((lhs vector3d
(lhs-x lhs-y lhs-z
))
129 (rhs vector3d
(rhs-x rhs-y rhs-z
)))
132 (- (* lhs-y rhs-z
) (* lhs-z rhs-y
))
133 (- (* lhs-z rhs-x
) (* lhs-x rhs-z
))
134 (- (* lhs-x rhs-y
) (* lhs-y rhs-x
)))))
136 (def-tuple-op vertex3d-distance
*
141 (vector3d-difference*
142 (vertex3d-vector3d* end
)
143 (vertex3d-vector3d* start
)))))
145 (def-tuple-op delta-vector3d
*
149 (vector3d-difference* end start
)))
153 ;; convert 2 3d vectors to angle axis
155 ;; construct 44 matrix from 3 / a2 3d vectors