/// <summary> /// Get the distance from the starting position of the ray in the box's space. /// If there is no scale transformation between the box and the ray, the distance should be the same /// as the distance in world space. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> protected static float? GetIntersectionDistance(BoxNode a, Ray b) { Ray bTransformed = b.TransformRay(a.ReferenceNode); Pair<bool, float> result = bTransformed.Intersects(a.ToMogreAxisAlignedBox()); if (result.first) return result.second; return null; }
protected static bool Intersects(BoxNode a, SphereNode b) { Vector3 bTransformedCenter; float bTransformedSquaredRadius; TransformSphere(b, a.ReferenceNode, out bTransformedCenter, out bTransformedSquaredRadius); Vector3 closest = bTransformedCenter.Clamp(a.Min, a.Max); return closest.SquaredDistance(bTransformedCenter) < bTransformedSquaredRadius; }
public bool Intersects(BoxNode box) { return PrimitiveNode.Intersects(box, this); }