public ContainmentType Contains(BoundingOrientedBox box) { if (!box.Intersects(this)) { return(ContainmentType.Disjoint); } XMVector v_center = this.center; XMVector v_radius = XMVector.Replicate(this.radius); XMVector radiusSq = v_radius * v_radius; XMVector boxCenter = box.Center; XMVector boxExtents = box.Extents; XMVector boxOrientation = box.Orientation; Debug.Assert(Internal.XMQuaternionIsUnit(boxOrientation), "Reviewed"); XMVector insideAll = XMVector.TrueInt; for (int i = 0; i < BoundingOrientedBox.CornerCount; i++) { XMVector c = XMVector3.Rotate(boxExtents * CollisionGlobalConstants.BoxOffsets[i], boxOrientation) + boxCenter; XMVector d = XMVector3.LengthSquare(XMVector.Subtract(v_center, c)); insideAll = XMVector.AndInt(insideAll, XMVector.LessOrEqual(d, radiusSq)); } return(XMVector3.EqualInt(insideAll, XMVector.TrueInt) ? ContainmentType.Contains : ContainmentType.Intersects); }
public ContainmentType Contains(BoundingOrientedBox box) { if (!box.Intersects(this)) { return(ContainmentType.Disjoint); } XMVector boxCenter = this.center; XMVector boxExtents = this.extents; // Subtract off the AABB center to remove a subtract below XMVector o_center = box.Center - boxCenter; XMVector o_extents = box.Extents; XMVector o_orientation = box.Orientation; Debug.Assert(Internal.XMQuaternionIsUnit(o_orientation), "Reviewed"); XMVector inside = XMVector.TrueInt; for (int i = 0; i < BoundingOrientedBox.CornerCount; i++) { XMVector c = XMVector3.Rotate(o_extents * CollisionGlobalConstants.BoxOffsets[i], o_orientation) + o_center; XMVector d = c.Abs(); inside = XMVector.AndInt(inside, XMVector.LessOrEqual(d, boxExtents)); } return(XMVector3.EqualInt(inside, XMVector.TrueInt) ? ContainmentType.Contains : ContainmentType.Intersects); }
public ContainmentType Contains(BoundingBox box) { if (!box.Intersects(this)) { return(ContainmentType.Disjoint); } XMVector v_center = this.center; XMVector v_radius = XMVector.Replicate(this.radius); XMVector radiusSq = v_radius * v_radius; XMVector boxCenter = box.Center; XMVector boxExtents = box.Extents; XMVector insideAll = XMVector.TrueInt; XMVector offset = boxCenter - v_center; for (int i = 0; i < BoundingBox.CornerCount; i++) { XMVector c = XMVector.MultiplyAdd(boxExtents, CollisionGlobalConstants.BoxOffsets[i], offset); XMVector d = XMVector3.LengthSquare(c); insideAll = XMVector.AndInt(insideAll, XMVector.LessOrEqual(d, radiusSq)); } return(XMVector3.EqualInt(insideAll, XMVector.TrueInt) ? ContainmentType.Contains : ContainmentType.Intersects); }
public ContainmentType Contains(BoundingFrustum fr) { if (!fr.Intersects(this)) { return(ContainmentType.Disjoint); } XMVector v_center = this.center; XMVector v_radius = XMVector.Replicate(this.radius); XMVector radiusSq = v_radius * v_radius; XMVector v_origin = fr.Origin; XMVector v_orientation = fr.Orientation; Debug.Assert(Internal.XMQuaternionIsUnit(v_orientation), "Reviewed"); // Build the corners of the frustum. XMVector v_rightTop = new XMVector(fr.RightSlope, fr.TopSlope, 1.0f, 0.0f); XMVector v_rightBottom = new XMVector(fr.RightSlope, fr.BottomSlope, 1.0f, 0.0f); XMVector v_leftTop = new XMVector(fr.LeftSlope, fr.TopSlope, 1.0f, 0.0f); XMVector v_leftBottom = new XMVector(fr.LeftSlope, fr.BottomSlope, 1.0f, 0.0f); XMVector v_near = XMVector.Replicate(fr.Near); XMVector v_far = XMVector.Replicate(fr.Far); XMVector[] corners = new XMVector[BoundingFrustum.CornerCount]; corners[0] = v_rightTop * v_near; corners[1] = v_rightBottom * v_near; corners[2] = v_leftTop * v_near; corners[3] = v_leftBottom * v_near; corners[4] = v_rightTop * v_far; corners[5] = v_rightBottom * v_far; corners[6] = v_leftTop * v_far; corners[7] = v_leftBottom * v_far; XMVector insideAll = XMVector.TrueInt; for (int i = 0; i < BoundingFrustum.CornerCount; i++) { XMVector c = XMVector3.Rotate(corners[i], v_orientation) + v_origin; XMVector d = XMVector3.LengthSquare(XMVector.Subtract(v_center, c)); insideAll = XMVector.AndInt(insideAll, XMVector.LessOrEqual(d, radiusSq)); } return(XMVector3.EqualInt(insideAll, XMVector.TrueInt) ? ContainmentType.Contains : ContainmentType.Intersects); }
public ContainmentType Contains(BoundingSphere sh) { XMVector sphereCenter = sh.Center; XMVector sphereRadius = XMVector.Replicate(sh.Radius); XMVector boxCenter = this.center; XMVector boxExtents = this.extents; XMVector boxMin = boxCenter - boxExtents; XMVector boxMax = boxCenter + boxExtents; //// Find the distance to the nearest point on the box. //// for each i in (x, y, z) //// if (SphereCenter(i) < BoxMin(i)) d2 += (SphereCenter(i) - BoxMin(i)) ^ 2 //// else if (SphereCenter(i) > BoxMax(i)) d2 += (SphereCenter(i) - BoxMax(i)) ^ 2 XMVector d = XMGlobalConstants.Zero; // Compute d for each dimension. XMVector lessThanMin = XMVector.Less(sphereCenter, boxMin); XMVector greaterThanMax = XMVector.Greater(sphereCenter, boxMax); XMVector minDelta = sphereCenter - boxMin; XMVector maxDelta = sphereCenter - boxMax; // Choose value for each dimension based on the comparison. d = XMVector.Select(d, minDelta, lessThanMin); d = XMVector.Select(d, maxDelta, greaterThanMax); // Use a dot-product to square them and sum them together. XMVector d2 = XMVector3.Dot(d, d); if (XMVector3.Greater(d2, XMVector.Multiply(sphereRadius, sphereRadius))) { return(ContainmentType.Disjoint); } XMVector insideAll = XMVector.LessOrEqual(boxMin + sphereRadius, sphereCenter); insideAll = XMVector.AndInt(insideAll, XMVector.LessOrEqual(sphereCenter, boxMax - sphereRadius)); insideAll = XMVector.AndInt(insideAll, XMVector.Greater(boxMax - boxMin, sphereRadius)); return(XMVector3.EqualInt(insideAll, XMVector.TrueInt) ? ContainmentType.Contains : ContainmentType.Intersects); }
public ContainmentType Contains(XMVector v0, XMVector v1, XMVector v2) { if (!this.Intersects(v0, v1, v2)) { return(ContainmentType.Disjoint); } XMVector boxCenter = this.center; XMVector boxExtents = this.extents; XMVector d = XMVector.Subtract(v0, boxCenter).Abs(); XMVector inside = XMVector.LessOrEqual(d, boxExtents); d = XMVector.Subtract(v1, boxCenter).Abs(); inside = XMVector.AndInt(inside, XMVector.LessOrEqual(d, boxExtents)); d = XMVector.Subtract(v2, boxCenter).Abs(); inside = XMVector.AndInt(inside, XMVector.LessOrEqual(d, boxExtents)); return(XMVector3.EqualInt(inside, XMVector.TrueInt) ? ContainmentType.Contains : ContainmentType.Intersects); }
public ContainmentType Contains(XMVector v0, XMVector v1, XMVector v2) { if (!this.Intersects(v0, v1, v2)) { return(ContainmentType.Disjoint); } XMVector v_center = this.center; XMVector v_radius = XMVector.Replicate(this.radius); XMVector radiusSquared = XMVector.Multiply(v_radius, v_radius); XMVector distanceSquared = XMVector3.LengthSquare(v0 - v_center); XMVector inside = XMVector.LessOrEqual(distanceSquared, radiusSquared); distanceSquared = XMVector3.LengthSquare(v1 - v_center); inside = XMVector.AndInt(inside, XMVector.LessOrEqual(distanceSquared, radiusSquared)); distanceSquared = XMVector3.LengthSquare(v2 - v_center); inside = XMVector.AndInt(inside, XMVector.LessOrEqual(distanceSquared, radiusSquared)); return(XMVector3.EqualInt(inside, XMVector.TrueInt) ? ContainmentType.Contains : ContainmentType.Intersects); }
public ContainmentType Contains(BoundingFrustum fr) { if (!fr.Intersects(this)) { return(ContainmentType.Disjoint); } XMFloat3[] corners = fr.GetCorners(); XMVector v_center = this.center; XMVector v_extents = this.extents; XMVector inside = XMVector.TrueInt; for (int i = 0; i < BoundingFrustum.CornerCount; i++) { XMVector point = corners[i]; XMVector d = XMVector.Subtract(point, v_center).Abs(); inside = XMVector.AndInt(inside, XMVector.LessOrEqual(d, v_extents)); } return(XMVector3.EqualInt(inside, XMVector.TrueInt) ? ContainmentType.Contains : ContainmentType.Intersects); }