示例#1
0
        public static bool IsVisible(this PerspectiveCamera camera, Point3D worldPoint)
        {
            try
            {
                Point3D local = ProjectionCameraExtension.GetWorldToLocal(camera).Transform(worldPoint);
                // camera lookdirection is along -Z axis
                if (local.Z >= 0.0)
                {
                    return(false);
                }

                const double deg2rad        = 0.01745329;
                double       distance       = Abs(local.Z);
                double       frustrumHeight = 2.0 * distance * Tan(camera.FieldOfView * deg2rad * 0.5);
                if (Abs(local.X) > frustrumHeight / 2.0)
                {
                    return(false);
                }

                if (Abs(local.Y) > frustrumHeight / 2.0)
                {
                    return(false);
                }

                return(true);
            }
            catch { return(false); }
        }
示例#2
0
        public static bool IsVisible(this PerspectiveCamera camera, Point3D worldPoint, double aspectRatio)
        {
            try
            {
                Point3D local = ProjectionCameraExtension.GetWorldToLocal(camera).Transform(worldPoint);
                // camera lookdirection is along -Z axis
                if (local.Z >= 0.0)
                {
                    return(false);
                }

                const double deg2rad  = 0.01745329;
                double       distance = Abs(local.Z);

                double horizontalFOV = camera.FieldOfView;
                double verticalFOV   = camera.FieldOfView;
                if (aspectRatio >= 1)
                {
                    verticalFOV = horizontalFOV / aspectRatio;
                }
                else
                {
                    horizontalFOV = verticalFOV * aspectRatio;
                }
                double frustrumWidth  = 2.0 * distance * Tan(horizontalFOV * deg2rad * 0.5);
                double frustrumHeight = 2.0 * distance * Tan(verticalFOV * deg2rad * 0.5);
                if (Abs(local.X) > frustrumWidth / 2.0)
                {
                    return(false);
                }

                if (Abs(local.Y) > frustrumHeight / 2.0)
                {
                    return(false);
                }

                return(true);
            }
            catch { return(false); }
        }