public static BoundingBox BoundingToBox(Bounding.Chain a) { if (a.Shallow) { return(BoundingToBox(a.Boundings[0])); } return(BoundingToBox(a.Boundings[a.Boundings.Length - 1])); }
/*static bool IntersectHelper(object a, object b, out object i) * { * i = null; * if (a is BoundingChain) return Intersect((BoundingChain)a, b, out i); * else if (b is BoundingChain) return Intersect((BoundingChain)b, a, out i); * * else if (a is BoundingBox) * { * if (a is BoundingBox && b is BoundingBox) return Intersect((BoundingBox)a, (BoundingBox)b, out i); * if (b is Ray) return Intersect((BoundingBox)a, (Ray)b, out i); * else if (b is Vector3) return Intersect((BoundingBox)a, (Vector3)b, out i); * else if (b is Vector2) return Intersect((BoundingBox)a, (Vector2)b, out i); * else if (b is Bounding.Cylinder) return Intersect((BoundingBox)a, (Bounding.Cylinder)b, out i); * } * else if (b is BoundingBox) * { * if (a is Ray) return Intersect((BoundingBox)b, (Ray)a, out i); * else if (a is Vector3) return Intersect((BoundingBox)b, (Vector3)a, out i); * else if (a is Vector2) return Intersect((BoundingBox)b, (Vector2)a, out i); * else if (a is Bounding.Cylinder) return Intersect((BoundingBox)b, (Bounding.Cylinder)a, out i); * } * * else if (a is BoundingSphere) * { * if (b is Vector3) return Intersect((BoundingSphere)a, (Vector3)b, out i); * else if (b is Ray) return Intersect((BoundingSphere)a, (Ray)b, out i); * } * else if (b is BoundingSphere) * { * if (a is Vector3) return Intersect((BoundingSphere)b, (Vector3)a, out i); * else if (a is Ray) return Intersect((BoundingSphere)b, (Ray)a, out i); * } * * else if (a is Bounding.Cylinder) * { * if (b is Vector3) return Intersect((Bounding.Cylinder)a, (Vector3)b, out i); * else if (b is Vector2) return Intersect((Bounding.Cylinder)a, (Vector2)b, out i); * else if (b is Bounding.Cylinder) return Intersect((Bounding.Cylinder)a, (Bounding.Cylinder)b, out i); * } * else if (b is Bounding.Cylinder) * { * if (a is Vector3) return Intersect((Bounding.Cylinder)b, (Vector3)a, out i); * else if (a is Vector2) return Intersect((Bounding.Cylinder)b, (Vector2)a, out i); * } * * else if (a is Bounding.Frustum) * { * if (b is Vector3) return Intersect((Bounding.Frustum)a, (Vector3)b, out i); * else if (b is Vector2) return Intersect((Bounding.Frustum)a, (Vector2)b, out i); * else if (b is BoundingBox) return Intersect((Bounding.Frustum)a, (BoundingBox)b, out i); * } * else if (b is Bounding.Frustum) * { * if (a is Vector3) return Intersect((Bounding.Frustum)b, (Vector3)a, out i); * else if (a is Vector2) return Intersect((Bounding.Frustum)b, (Vector2)a, out i); * else if (a is BoundingBox) return Intersect((Bounding.Frustum)b, (BoundingBox)a, out i); * } * * else if (a is Plane && b is Ray) return Intersect((Plane)a, (Ray)b, out i); * else if (b is Plane && a is Ray) return Intersect((Plane)b, (Ray)a, out i); * * * else if (a is Vector3 && b is Ray) return Intersect((Vector3)a, (Ray)b, out i); * else if (b is Vector3 && a is Ray) return Intersect((Vector3)b, (Ray)a, out i); * * else return intersectors.Dispatch(a, b)(a, b, out i); * * return false; * }*/ // ---------------------------------------------------------------------------------------------- // -- Chain ------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------- public static bool Intersect(Bounding.Chain a, object b, out object intersection) { intersection = null; foreach (object o in a.Boundings) { if (!Intersect(o, b, out intersection)) { return(false); } } return(true); }
public static Bounding.Chain Transform(Bounding.Chain bounding, Matrix transformation) { Bounding.Chain b = new Common.Bounding.Chain { Shallow = bounding.Shallow, Boundings = new object[bounding.Boundings.Length] }; for (int i = 0; i < b.Boundings.Length; i++) { b.Boundings[i] = Transform(bounding.Boundings[i], transformation); } return(b); }
public static bool ChainRayIntersect(Bounding.Chain a, Ray b, float maxDistance, out RayIntersection intersection) { intersection = null; foreach (object o in a.Boundings) { if (!Intersect(o, b, out intersection)) { return(false); } else if (intersection.Distance > maxDistance) { return(false); } } return(true); }
// ---------------------------------------------------------------------------------------------- // -- Chain ------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------- public static RSpatialRelation Relation(Bounding.Chain a, object b) { if (a.Shallow) { return(Relation(a.Boundings[0], b)); } RSpatialRelation rel = RSpatialRelation.Outside; foreach (object o in a.Boundings) { rel = Relation(o, b); if (rel == RSpatialRelation.Outside) { return(RSpatialRelation.Outside); } else if (rel == RSpatialRelation.AInsideB) { return(RSpatialRelation.AInsideB); } } return(rel); }
public static float Radius(Bounding.Chain bounding) { return(Radius(bounding.Boundings[0])); }
public static Vector3 Translation(Bounding.Chain bounding) { return(Translation(bounding.Boundings[bounding.Boundings.Length - 1])); }