//! //! Shape composed from the union of primitives. //! use na::Translate; use na; use bounding_volume::{self, AABB, BoundingVolume}; use partitioning::BVT; use math::{Point, Isometry}; use shape::ShapeHandle; /// A compound shape with an aabb bounding volume. /// /// A compound shape is a shape composed of the union of several simpler shape. This is /// the main way of creating a concave shape from convex parts. Each parts can have its own /// delta transformation to shift or rotate it with regard to the other shapes. pub struct Compound { shapes: Vec<(M, ShapeHandle)>, bvt: BVT>, bvs: Vec> } impl Clone for Compound { fn clone(&self) -> Compound { Compound { shapes: self.shapes.clone(), bvt: self.bvt.clone(), bvs: self.bvs.clone() } } } impl Compound where P: Point, P::Vect: Translate

, M: Isometry { /// Builds a new compound shape. pub fn new(shapes: Vec<(M, ShapeHandle)>) -> Compound { let mut bvs = Vec::new(); let mut leaves = Vec::new(); for (i, &(ref delta, ref shape)) in shapes.iter().enumerate() { // loosen for better persistancy let bv = bounding_volume::aabb(shape.as_ref(), delta).loosened(na::cast(0.04f64)); bvs.push(bv.clone()); leaves.push((i, bv)); } let bvt = BVT::new_balanced(leaves); Compound { shapes: shapes, bvt: bvt, bvs: bvs } } } impl Compound { /// The shapes of this compound shape. #[inline] pub fn shapes(&self) -> &[(M, ShapeHandle)] { &self.shapes[..] } /// The optimization structure used by this compound shape. #[inline] pub fn bvt(&self) -> &BVT> { &self.bvt } /// The shapes bounding volumes. #[inline] pub fn bounding_volumes(&self) -> &[AABB

] { &self.bvs[..] } /// The AABB of the i-th shape compositing this compound. #[inline] pub fn aabb_at(&self, i: usize) -> &AABB

{ &self.bvs[i] } }