Example #1
0
        public static bool SetupFrustum(ViewportInfo vp, ClippingInfo clipping)
        {
            double n0 = vp.FrustumNear;
            double f0 = vp.FrustumFar;

            // Because picking relies heavily on the projection, we first set the
            // viewport frustum here, capture and save it, then let the conduits
            // do what ever they want with it...eventually the viewport will be put
            // back to the captured state before leaving the pipeline...
            ClippingInfo m_SavedClipping = clipping;

            vp.SetFrustumNearFar(clipping.bbox_near, clipping.bbox_far,
                                 clipping.min_near_dist, clipping.min_near_over_far,
                                 clipping.target_dist
                                 );

            vp.GetFrustum(out m_SavedClipping.left,
                          out m_SavedClipping.right,
                          out m_SavedClipping.bottom,
                          out m_SavedClipping.top,
                          out m_SavedClipping.bbox_near,
                          out m_SavedClipping.bbox_far);

            // Next, set the values that the pipeline will actually use...
            if (!(AdjustFrustum(vp, clipping)))
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Find the Perspective viewport in the 3dm file and sets up the default view.
        /// </summary>
        public void LoadCamera()
        {
            if (App.Manager.CurrentModel == null)
            {
                return;
            }

            Camera = new ViewportInfo();
            bool cameraIsInitialized = false;

            int viewCount = App.Manager.CurrentModel.ModelFile.Views.Count;

            // find first perspective viewport projection in file
            if (viewCount > 0)
            {
                foreach (var view in App.Manager.CurrentModel.ModelFile.Views)
                {
                    if (view.Viewport.IsPerspectiveProjection)
                    {
                        cameraIsInitialized = true;
                        Camera             = view.Viewport;
                        Camera.TargetPoint = view.Viewport.TargetPoint;
                        Camera.SetScreenPort(0, (int)View.Bounds.Size.Width, 0, (int)View.Bounds.Size.Height, 1, 1000);
                        Camera.FrustumAspect = Camera.ScreenPortAspect;
                        Camera.SetFrustumNearFar(App.Manager.CurrentModel.BBox);
                        break;
                    }
                }
            }

            // If there isn't one, then cook up a viewport from scratch...
            if (!cameraIsInitialized)
            {
                Camera.SetScreenPort(0, (int)View.Bounds.Size.Width, 0, (int)View.Bounds.Size.Height, 1, 1000);
                Camera.TargetPoint = new Rhino.Geometry.Point3d(0, 0, 0);
                var plane = new Rhino.Geometry.Plane(Rhino.Geometry.Point3d.Origin, new Rhino.Geometry.Vector3d(-1, -1, -1));
                Camera.SetCameraLocation(new Rhino.Geometry.Point3d(10, 10, 10));
                var dir = new Rhino.Geometry.Vector3d(-1, -1, -1);
                dir.Unitize();
                Camera.SetCameraDirection(dir);
                Camera.SetCameraUp(plane.YAxis);
                Camera.SetFrustum(-1, 1, -1, 1, 0.1, 1000);
                Camera.FrustumAspect           = Camera.ScreenPortAspect;
                Camera.IsPerspectiveProjection = true;
                Camera.Camera35mmLensLength    = 50;
                if (App.Manager.CurrentModel != null)
                {
                    if (App.Manager.CurrentModel.AllMeshes != null)
                    {
                        Camera.DollyExtents(App.Manager.CurrentModel.AllMeshes, 1.0);
                    }
                }
            }
        }
Example #3
0
 private static bool AdjustFrustum(ViewportInfo vp, ClippingInfo clipping)
 {
     vp.SetFrustumNearFar(vp.FrustumNear * 0.1, vp.FrustumFar * 10);
     return(true);
 }