Beispiel #1
0
        /// <summary>
        /// Extracts perspective camera parameters from the frustum, doesn't work with orthographic frustums.
        /// </summary>
        /// <returns>Perspective camera parameters from the frustum</returns>
        public FrustumCameraParams GetCameraParams()
        {
            var corners     = GetCorners();
            var cameraParam = new FrustumCameraParams();

            cameraParam.Position    = Get3PlanesInterPoint(ref pRight, ref pTop, ref pLeft);
            cameraParam.LookAtDir   = pNear.Normal;
            cameraParam.UpDir       = Vector3.Normalize(Vector3.Cross(pRight.Normal, pNear.Normal));
            cameraParam.FOV         = (float)((Math.PI / 2.0 - Math.Acos(Vector3.Dot(pNear.Normal, pTop.Normal))) * 2);
            cameraParam.AspectRatio = (corners[6] - corners[5]).Length() / (corners[4] - corners[5]).Length();
            cameraParam.ZNear       = (cameraParam.Position + (pNear.Normal * pNear.D)).Length();
            cameraParam.ZFar        = (cameraParam.Position + (pFar.Normal * pFar.D)).Length();
            return(cameraParam);
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new frustum relaying on perspective camera parameters
 /// </summary>
 /// <param name="cameraParams">The camera params.</param>
 /// <returns>The bounding frustum from camera params</returns>
 public static BoundingFrustum FromCamera(FrustumCameraParams cameraParams)
 {
     return(FromCamera(cameraParams.Position, cameraParams.LookAtDir, cameraParams.UpDir, cameraParams.FOV, cameraParams.ZNear, cameraParams.ZFar, cameraParams.AspectRatio));
 }