public static XMVector XMPlaneTransform(XMVector plane, XMVector rotation, XMVector translation) { XMVector v_normal = XMVector3.Rotate(plane, rotation); XMVector vD = XMVector.SplatW(plane) - XMVector3.Dot(v_normal, translation); return(new XMVector(v_normal.X, v_normal.Y, v_normal.Z, vD.W)); }
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 BoundingBox Transform(float scale, XMVector rotation, XMVector translation) { Debug.Assert(Internal.XMQuaternionIsUnit(rotation), "Reviewed"); // Load center and extents. XMVector boxCenter = this.center; XMVector boxExtents = this.extents; XMVector vectorScale = XMVector.Replicate(scale); // Compute and transform the corners and find new min/max bounds. XMVector corner = XMVector.MultiplyAdd(boxExtents, CollisionGlobalConstants.BoxOffsets[0], boxCenter); corner = XMVector3.Rotate(corner * vectorScale, rotation) + translation; XMVector min, max; min = max = corner; for (int i = 1; i < BoundingBox.CornerCount; i++) { corner = XMVector.MultiplyAdd(boxExtents, CollisionGlobalConstants.BoxOffsets[i], boxCenter); corner = XMVector3.Rotate(corner * vectorScale, rotation) + translation; min = XMVector.Min(min, corner); max = XMVector.Max(max, corner); } // Store center and extents. return(new BoundingBox((min + max) * 0.5f, (max - min) * 0.5f)); }
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(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 BoundingSphere Transform(float scale, XMVector rotation, XMVector translation) { // Load the center of the sphere. XMVector v_center = this.center; // Transform the center of the sphere. v_center = XMVector3.Rotate(v_center * XMVector.Replicate(scale), rotation) + translation; BoundingSphere result; // Store the center sphere. result.center = v_center; // Scale the radius of the pshere. result.radius = this.radius * scale; return(result); }