Example #1
0
        /// <summary>
        /// Sets up and initializes the viewport by setting the Uniforms
        /// </summary>
        public void SetupViewport(ViewportInfo viewport)
        {
            Transform mv            = new Transform();
            bool      haveModelView = false;

            if (m_Uniforms.rglModelViewProjectionMatrix >= 0)
            {
                Transform mvp = viewport.GetXform(CoordinateSystem.World, CoordinateSystem.Clip);

                m_MVPXform = mvp;

                float[] modelViewProjection = mvp.ToFloatArray(false);
                GL.UniformMatrix4(m_Uniforms.rglModelViewProjectionMatrix, 1, false, modelViewProjection);
            }

            if (m_Uniforms.rglModelViewMatrix >= 0)
            {
                mv = viewport.GetXform(CoordinateSystem.World, CoordinateSystem.Camera);

                m_MVXform     = mv;
                haveModelView = true;

                float[] modelView = mv.ToFloatArray(false);
                GL.UniformMatrix4(m_Uniforms.rglModelViewMatrix, 1, false, modelView);
            }

            if (m_Uniforms.rglProjectionMatrix >= 0)
            {
                Transform pr = viewport.GetXform(CoordinateSystem.Camera, CoordinateSystem.Clip);

                float[] projection = pr.ToFloatArray(false);
                GL.UniformMatrix4(m_Uniforms.rglProjectionMatrix, 1, false, projection);
            }

            if (m_Uniforms.rglNormalMatrix >= 0)
            {
                float[] normalMatrix = new float[9];

                if (!haveModelView)
                {
                    mv        = viewport.GetXform(CoordinateSystem.World, CoordinateSystem.Camera);
                    m_MVXform = mv;
                }

                Matrix4Dto3F(mv, ref normalMatrix, false);
                GL.UniformMatrix3(m_Uniforms.rglNormalMatrix, 1, false, normalMatrix);
            }
        }
Example #2
0
        /// <summary>
        /// LateralPan of a viewport between two points
        /// </summary>
        public static void LateralPan(this ViewportInfo viewport, CGPoint fromPoint, CGPoint toPoint, bool flipX, bool flipY)
        {
            double deltaX, deltaY, s;

            Rhino.Geometry.Transform s2c          = viewport.GetXform(CoordinateSystem.Screen, CoordinateSystem.Clip);
            Rhino.Geometry.Point3d   screenPoint0 = new Rhino.Geometry.Point3d(fromPoint.X, fromPoint.Y, 0.0);
            Rhino.Geometry.Point3d   screenPoint1 = new Rhino.Geometry.Point3d(toPoint.X, toPoint.Y, 0.0);
            Rhino.Geometry.Point3d   clipPoint0   = s2c * screenPoint0;
            Rhino.Geometry.Point3d   clipPoint1   = s2c * screenPoint1;
            deltaX  = 0.5 * (clipPoint1.X - clipPoint0.X);
            deltaY  = 0.5 * (clipPoint1.Y - clipPoint0.Y);
            deltaX *= (viewport.FrustumRight - viewport.FrustumLeft);
            deltaY *= (viewport.FrustumBottom - viewport.FrustumTop);
            if (viewport.IsPerspectiveProjection)
            {
                s       = viewport.TargetPoint.DistanceTo(viewport.CameraLocation) / viewport.FrustumNear;
                deltaX *= flipX ? -s : s;
                deltaY *= flipY ? -s : s;
            }
            Rhino.Geometry.Vector3d dollyVector = (deltaX * viewport.CameraX) + (deltaY * viewport.CameraY);
            viewport.TargetPoint = viewport.TargetPoint - dollyVector;
            viewport.SetCameraLocation(viewport.CameraLocation - dollyVector);
        }