private void InitScene() { this.cascadedShadow.InitScene(this.selectedMesh, this.cascadeConfig); XMVector vMeshExtents = this.cascadedShadow.SceneAABBMax - this.cascadedShadow.SceneAABBMin; XMVector vMeshLength = XMVector3.Length(vMeshExtents); float fMeshLength = vMeshLength.GetByIndex(0); this.Settings.MeshLength = fMeshLength; }
public ContainmentType Contains(BoundingSphere sh) { XMVector center1 = this.center; float r1 = this.radius; XMVector center2 = sh.center; float r2 = sh.radius; XMVector v = XMVector.Subtract(center2, center1); XMVector dist = XMVector3.Length(v); float d = dist.X; return((r1 + r2 >= d) ? ((r1 - r2 >= d) ? ContainmentType.Contains : ContainmentType.Intersects) : ContainmentType.Disjoint); }
public override void SetViewParams(XMVector vEyePt, XMVector vLookatPt) { base.SetViewParams(vEyePt, vLookatPt); // Propogate changes to the member arcball XMMatrix mRotation = XMMatrix.LookAtLH(vEyePt, vLookatPt, XMVector.FromFloat(0.0f, 1.0f, 0.0f, 0.0f)); XMVector quat = XMQuaternion.RotationMatrix(mRotation); m_ViewArcBall.SetQuatNow(quat); // Set the radius according to the distance XMVector vEyeToPoint = XMVector.Subtract(vLookatPt, vEyePt); float len = XMVector3.Length(vEyeToPoint).X; SetRadius(len); // View information changed. FrameMove should be called. m_bDragSinceLastUpdate = true; }
public static BoundingSphere CreateMerged(BoundingSphere s1, BoundingSphere s2) { XMVector center1 = s1.center; float r1 = s1.radius; XMVector center2 = s2.center; float r2 = s2.radius; XMVector v = XMVector.Subtract(center2, center1); XMVector dist = XMVector3.Length(v); float d = dist.X; if (r1 + r2 >= d) { if (r1 - r2 >= d) { return(s1); } else if (r2 - r1 >= d) { return(s2); } } XMVector n = XMVector.Divide(v, dist); float t1 = Math.Min(-r1, d - r2); float t2 = Math.Max(r1, d + r2); float t_5 = (t2 - t1) * 0.5f; XMVector n_center = XMVector.Add(center1, XMVector.Multiply(n, XMVector.Replicate(t_5 + t1))); return(new BoundingSphere(n_center, t_5)); }
public static bool XMPlaneIsUnit(XMVector plane) { XMVector difference = XMVector3.Length(plane) - XMVector.One; return(XMVector4.Less(difference.Abs(), Internal.UnitPlaneEpsilon)); }
public static bool XMVector3IsUnit(XMVector v) { XMVector difference = XMVector3.Length(v) - XMVector.One; return(XMVector4.Less(difference.Abs(), Internal.UnitVectorEpsilon)); }
public static BoundingSphere CreateFromPoints(XMFloat3[] points) { if (points == null) { throw new ArgumentNullException("points"); } if (points.Length == 0) { throw new ArgumentOutOfRangeException("points"); } // Find the points with minimum and maximum x, y, and z XMVector minX, maxX, minY, maxY, minZ, maxZ; minX = maxX = minY = maxY = minZ = maxZ = points[0]; for (int i = 1; i < points.Length; i++) { XMVector point = points[i]; float px = point.X; float py = point.Y; float pz = point.Z; if (px < minX.X) { minX = point; } if (px > maxX.X) { maxX = point; } if (py < minY.Y) { minY = point; } if (py > maxY.Y) { maxY = point; } if (pz < minZ.Z) { minZ = point; } if (pz > maxZ.Z) { maxZ = point; } } // Use the min/max pair that are farthest apart to form the initial sphere. XMVector deltaX = maxX - minX; XMVector distX = XMVector3.Length(deltaX); XMVector deltaY = maxY - minY; XMVector distY = XMVector3.Length(deltaY); XMVector deltaZ = maxZ - minZ; XMVector distZ = XMVector3.Length(deltaZ); XMVector v_center; XMVector v_radius; if (XMVector3.Greater(distX, distY)) { if (XMVector3.Greater(distX, distZ)) { // Use min/max x. v_center = XMVector.Lerp(maxX, minX, 0.5f); v_radius = distX * 0.5f; } else { // Use min/max z. v_center = XMVector.Lerp(maxZ, minZ, 0.5f); v_radius = distZ * 0.5f; } } else { //// Y >= X if (XMVector3.Greater(distY, distZ)) { // Use min/max y. v_center = XMVector.Lerp(maxY, minY, 0.5f); v_radius = distY * 0.5f; } else { // Use min/max z. v_center = XMVector.Lerp(maxZ, minZ, 0.5f); v_radius = distZ * 0.5f; } } // Add any points not inside the sphere. for (int i = 0; i < points.Length; i++) { XMVector point = points[i]; XMVector delta = point - v_center; XMVector dist = XMVector3.Length(delta); if (XMVector3.Greater(dist, v_radius)) { // Adjust sphere to include the new point. v_radius = (v_radius + dist) * 0.5f; v_center += (XMVector.Replicate(1.0f) - XMVector.Divide(v_radius, dist)) * delta; } } return(new BoundingSphere(v_center, v_radius.X)); }
public static BoundingSphere CreateFromOrientedBox(BoundingOrientedBox box) { // Bounding box orientation is irrelevant because a sphere is rotationally invariant return(new BoundingSphere(box.Center, XMVector3.Length(box.Extents).X)); }
public static BoundingSphere CreateFromBox(BoundingBox box) { return(new BoundingSphere(box.Center, XMVector3.Length(box.Extents).X)); }