2 (in-package :cl-tuples
)
6 ;; axis aligned bounding boxes
9 :tuple-element-type fast-float
10 :initial-element
0.0f0
11 :elements
(minx maxx miny maxy minz maxz
))
13 (export-tuple-operations aabb
)
15 (def-tuple-op intersect-aabb
*
16 ((aabb0 aabb
(minx0 maxx0 miny0 maxy0 minz0 maxz0
))
17 (aabb1 aabb
(minx1 maxx1 miny1 maxy1 minz1 maxz1
)))
19 (let ((depth0 (- maxz0 minz0
))
20 (depth1 (- maxz1 minz1
))
21 (height0 (- maxy0 miny0
))
22 (height1 (- maxy1 miny1
))
23 (width0 (- maxx0 minx0
))
24 (width1 (- maxx1 minx1
))
25 (centrex0 (- maxx0
(* 0.5f0 width0
)))
26 (centrex1 (- maxx1
(/ 0.5f0 width1
)))
27 (centrey0 (- maxx0
(/ 0.5f0 height0
)))
28 (centrey1 (- maxx1
(/ 0.5f0 height1
)))
29 (centrez0 (- maxx0
(/ 0.5f0 depth0
)))
30 (centrez1 (- maxx1
(/ 0.5f0 depth1
))))
31 (and (<= (abs (- centrex0 centrex1
)) (+ (width0 width1
)))
32 (<= (abs (- centrey0 centrey1
)) (+ (height0 height1
)))
33 (<= (abs (- centrez0 centrez1
)) (+ (depth0 depth1
)))))))
36 (def-tuple-op transform-aabb
*
42 (box aabb
(minx0 maxx0 miny0 maxy0 minz0 maxz0
)))
45 (+ (* minx e00
) (* miny e01
) (* minz e02
) e03
)
46 (+ (* minx e10
) (* miny e11
) (* minz e12
) e13
)
47 (+ (* minx e20
) (* miny e21
) (* minz e22
) e23
)
48 (+ (* maxx e00
) (* maxy e01
) (* maxz e02
) e03
)
49 (+ (* maxx e10
) (* maxy e11
) (* maxz e12
) e13
)
50 (+ (* maxx e20
) (* maxy e21
) (* maxz e22
) e23
))))