예제 #1
0
        //Poll keyboard events
        public void PollKeyboard()
        {
            //Hit escape to quit
            //if (Keyboard[Key.Escape])
            //    Exit();

            //Keyboard controls
            if (Keyboard.GetState()[Key.W])
            {
                cam.Position += cam.speed * cam.front;
            }

            if (Keyboard.GetState()[Key.S])
            {
                cam.Position -= cam.speed * cam.front;
            }

            if (Keyboard.GetState()[Key.A])
            {
                cam.Position -= Vector3.Normalize(Vector3.Cross(cam.front, cam.up)) * cam.speed;
            }

            if (Keyboard.GetState()[Key.D])
            {
                cam.Position += Vector3.Normalize(Vector3.Cross(cam.front, cam.up)) * cam.speed;
            }

            //Toggle cam control
            if (Keyboard.GetState()[Key.Z])
            {
                //Prevents camera from toggling states if z is being held down
                if (!zPressed)
                {
                    CenterMouse();
                    camActive     = !camActive;                 // ! Toggles boolean
                    CursorVisible = !CursorVisible;             //Toggles cursor boolean
                }
                zPressed = true;
            }
            else
            {
                zPressed = false;
            }

            if (Keyboard.GetState()[Key.BracketLeft])
            {
                //Prevents from activating if button is held down
                if (!leftBracketPressed)
                {
                    if (gridSpace != 1)
                    {
                        gridSpace /= 2;
                        grid.Dispose();
                        grid = new RenderObject(MeshFactory.CreateGrid(gridSpace));
                    }
                }
                leftBracketPressed = true;
            }
            else
            {
                leftBracketPressed = false;
            }

            //Increase grid by 2x
            if (Keyboard.GetState()[Key.BracketRight])
            {
                //Prevents from activating if button is held down
                if (!rightBracketPressed)
                {
                    if (gridSpace != 512)
                    {
                        gridSpace *= 2;
                        grid       = new RenderObject(MeshFactory.CreateGrid(gridSpace));
                    }
                }
                rightBracketPressed = true;
            }
            else
            {
                rightBracketPressed = false;
            }

            //Decrease grid by 1/2
            if (Keyboard.GetState()[Key.G])
            {
                //Prevents from activating if held down
                if (!gPressed)
                {
                    drawGrid = !drawGrid;                     //Toggle grid
                }
                gPressed = true;
            }
            else
            {
                gPressed = false;
            }

            //Speed up cam by 10x
            if (Keyboard.GetState()[Key.ShiftLeft])
            {
                cam.speed = cam.originalSpeed * 10;
            }
            else
            {
                cam.speed = cam.originalSpeed;
            }
        }
예제 #2
0
        protected override void OnLoad(EventArgs e)
        {
            //Setup GUI
            //InitializeGui();



            //Add vertices to renderobjects list
            BSP.Read(currentMap);

            _defaultShader.Add(_baseDirectory + "\\Rendering\\Shaders\\defaultVertexShader.vert");
            _defaultShader.Add(_baseDirectory + "\\Rendering\\Shaders\\defaultFragmentShader.frag");
            _lineShader.Add(_baseDirectory + "\\Rendering\\Shaders\\lineFragmentShader.frag");
            _lineShader.Add(_baseDirectory + "\\Rendering\\Shaders\\defaultVertexShader.vert");

            //_shadedShader.Add(_baseDirectory + "/Rendering/Shaders/shadedVertexShader.vert");
            //_shadedShader.Add(_baseDirectory + "/Rendering/Shaders/shadedFragmentShader.frag");

            //_shadedShader.Add(_baseDirectory + "\\Rendering\\Shaders\\normalVertexShader.vert");
            //_shadedShader.Add(_baseDirectory + "\\Rendering\\Shaders\\normalFragmentShader.frag");
            //_shadedShader.Add(_baseDirectory + "\\Rendering\\Shaders\\normalGeometryShader.geom");

            List <FaceLump> temp = new List <FaceLump>();

            temp = BSP.faceList;
            var edgeList = BSP.edgeList;

            //Vector4[] vertices = MeshFactory.CreateSolidCube(64f);
            //List<Color4> colors = new List<Color4>();
            //List<Vector3> normal = new List<Vector3>();
            //for (int i = 0; i < vertices.Length ; i++)
            //{
            //    colors.Add(Color4.Green);
            //    normal.Add(new Vector3(1, 0, 0));
            //}


            //renderObjects.Add(new RenderObject(vertices, colors.ToArray(), normal.ToArray()));
            //renderObjects.Add(new RenderObject(MeshFactory.PlaneLumpToVertices(BSP.planeList[0])));
            //renderObjects.Add(new RenderObject(MeshFactory.FaceLumptoVertex(temp)));
            //renderObjects.Add(new RenderObject(MeshFactory.CreatePlane(32, Color4.Blue)));
            renderObjects.AddRange(MeshFactory.FaceLumptoVertex(temp));
            //renderObjects.Add(MeshFactory.FaceLumptoVertex(temp[0]));
            //renderObjects.Add(MeshFactory.FaceLumptoVertex(temp[1]));
            //renderObjects.Add(MeshFactory.FaceLumptoVertex(temp[2]));
            //renderObjects.Add(new RenderObject(MeshFactory.Vector3toVertex(vertexList)));
            //renderObjects.Add(new RenderObject(MeshFactory.EdgeToVertices(edgeList)));
            //renderObjects.Add(new RenderObject(MeshFactory.CreateSolidCube(64f, Color4.DarkSlateBlue)));

            grid = new RenderObject(MeshFactory.CreateGrid(16));

            Shader.CreateShaderProgram(ref _defaultShaderProgram, _defaultShader);
            Shader.CreateShaderProgram(ref _lineShaderProgram, _lineShader);
            //Shader.CreateShaderProgram(ref _shadedShaderProgram, _shadedShader);

            //Setup OpenGL settings
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.Multisample);


            //Hide cursor
            CursorVisible = true;

            //Wireframe
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.PatchParameter(PatchParameterInt.PatchVertices, 3);
            GL.LineWidth(2);
            GL.PointSize(10);

            //Setup background color
            //GL.ClearColor(Color.SkyBlue);

            //Calculate aspect ratio
            cam.AspectRatio = (float)Width / (float)Height;

            //Calculate initial projection and view matrix
            cam.CalcProjectionMatrix();
        }