/// <summary> /// Get the distance which when added to camera position along the lookat direction will do the effect of zoom to extents (zoom to fit) operation, /// so all the passed points will fit in the current view. /// if the returned value is positive, the camera will move toward the lookat direction (ZoomIn). /// if the returned value is negative, the camera will move in the reverse direction of the lookat direction (ZoomOut). /// </summary> /// <param name="points">The points.</param> /// <returns>The zoom to fit distance</returns> public float GetZoomToExtentsShiftDistance(MyVector3[] points) { float vAngle = (float)((Math.PI / 2.0 - Math.Acos(MyVector3.Dot(pNear.Normal, pTop.Normal)))); float vSin = (float)Math.Sin(vAngle); float hAngle = (float)((Math.PI / 2.0 - Math.Acos(MyVector3.Dot(pNear.Normal, pLeft.Normal)))); float hSin = (float)Math.Sin(hAngle); float horizontalToVerticalMapping = vSin / hSin; var ioFrustrum = GetInsideOutClone(); float maxPointDist = float.MinValue; for (int i = 0; i < points.Length; i++) { float pointDist = MyCollision.DistancePlanePoint(ref ioFrustrum.pTop, ref points[i]); pointDist = Math.Max(pointDist, MyCollision.DistancePlanePoint(ref ioFrustrum.pBottom, ref points[i])); pointDist = Math.Max(pointDist, MyCollision.DistancePlanePoint(ref ioFrustrum.pLeft, ref points[i]) * horizontalToVerticalMapping); pointDist = Math.Max(pointDist, MyCollision.DistancePlanePoint(ref ioFrustrum.pRight, ref points[i]) * horizontalToVerticalMapping); maxPointDist = Math.Max(maxPointDist, pointDist); } return(-maxPointDist / vSin); }