Exemplo n.º 1
0
 // XXX: Resize() and StartDraw() leave the matrix in a different mode than they got it in...
 public static void Resize()
 {
     Projection = Matrix4d.CreateOrthographic(CameraDistance * AspectRatio,
                                              CameraDistance, ClipNear, ClipFar);
     GL.MatrixMode(MatrixMode.Projection);
     GL.LoadMatrix(ref Projection);
 }
Exemplo n.º 2
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            var proj = Matrix4d.CreateOrthographic(ViewHeight * Width / Height, ViewHeight, -1, 1);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref proj);

            GL.Viewport(ClientRectangle);
            GL.ClearColor(Back);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.LineWidth(1.5f);
            GL.Begin(PrimitiveType.LineStrip);
            GL.Color4(Front);
            for (var i = 0; i < _path.Length && i < _time; i++)
            {
                var p = _path[i];
                GL.Vertex2(p);
            }
            GL.End();

            SwapBuffers();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates a 4x4 double Matrix representing the camera's View (with Perspective added)
        /// </summary>
        /// <param name="Pos">The camera's Position</param>
        /// <param name="Up">The camera's Up vector</param>
        /// <param name="Target">The camera's Target vector</param>
        /// <param name="cameraType">The camera's Type</param>
        /// <param name="zFar">The camera's ZFar</param>
        /// <param name="zNear">The camera's zNear</param>
        /// <param name="cameraWidth">The camera's width</param>
        /// <param name="cameraHeight">The camera's height</param>
        /// <param name="cameraAspect">The camera's aspect ratio</param>
        /// <param name="cameraFOV">The camera's field of view</param>
        /// <returns>a 4x4 double Matrix</returns>
        private Matrix4d generateMatrix(Vector3d Pos, Vector3d Up, Vector3d Target, ComponentConstants.CAM_TYPES cameraType, double zNear, double zFar, double cameraWidth = 0, double cameraHeight = 0, double cameraAspect = 0, double cameraFOV = 0)
        {
            Matrix4d ProjectionMatrix;

            if (cameraType == ComponentConstants.CAM_TYPES.ORTHOGRAPHIC)
            {
                ProjectionMatrix = Matrix4d.CreateOrthographic(cameraWidth, cameraHeight, zNear, zFar);
            }
            else
            {
                ProjectionMatrix = Matrix4d.CreatePerspectiveFieldOfView(cameraFOV, cameraAspect, zNear, zFar);
            }

            Matrix4d ViewMatrix = Matrix4d.LookAt(Pos, Target, Up);

            Matrix4d ResultMatrix = ProjectionMatrix * ViewMatrix;

            return(ResultMatrix);
        }
Exemplo n.º 4
0
 void keyDown(object o, KeyboardKeyEventArgs e)
 {
     if (e.Key == Key.D)
     {
         this.pos_x += 10.0;
     }
     if (e.Key == Key.A)
     {
         this.pos_x -= 10.0;
     }
     if (e.Key == Key.W)
     {
         this.pos_z += 10.0;
     }
     if (e.Key == Key.X)
     {
         this.pos_z -= 10.0;
     }
     if (e.Key == Key.S)
     {
         this.pos_y -= 10.0;
     }
     GL.MatrixMode(MatrixMode.Projection);
     GL.LoadIdentity();
     if (e.Key == Key.O)
     {
         matriz = Matrix4d.CreateOrthographic(300.0, 300.0, 1.0, 300.0);
     }
     if (e.Key == Key.P)
     {
         //  matriz = Matrix4d.Perspective(45.0f, ventana.Width / ventana.Height, 50.0f, 200.0f);
         matriz = Matrix4d.Perspective(45.0f, ventana.Width / ventana.Height, 2.0f, 2000.0f);
         // matriz = Matrix4d.CreatePerspectiveFieldOfView(20.0f, ventana.Width / ventana.Height, 50.0f, 200.0f);
     }
     GL.LoadMatrix(ref matriz);
     GL.MatrixMode(MatrixMode.Modelview);
 }
 public override Matrix4d ComputeProjectionMatrix(ICamera camera)
 {
     return(Matrix4d.CreateOrthographic(CameraWidth, CameraHeight, NearPlane, FarPlane));
 }