Пример #1
0
        static void Main(string[] args)
        {
            Window w = new Window(1920, 1080);

            EngineCore.AddImage("default.png", "default");

            DefaultShader ds            = new DefaultShader("default.vert", "default.frag");
            String        defaultShader = EngineCore.AddShader(ds, "Default");

            GUIShader gui       = new GUIShader("gui.vert", "gui.frag");
            String    guiShader = EngineCore.AddShader(gui, "GUI");

            WaterShader water       = new WaterShader("water.vert", "water.frag");
            String      waterShader = EngineCore.AddShader(water, "Water");

            SkyboxShader skybox       = new SkyboxShader("skybox.vert", "skybox.frag");
            String       skyboxShader = EngineCore.AddShader(skybox, "Skybox");

            ShadowShader shadow       = new ShadowShader("shadow.vert", "shadow.frag");
            String       shadowShader = EngineCore.AddShader(shadow, "Shadow");

            TerrainShader terrain       = new TerrainShader("terrain.vert", "terrain.frag");
            String        terrainShader = EngineCore.AddShader(terrain, "Terrain");


            String cubeModel    = EngineCore.AddModel("cubeything.obj", "cube");
            String terrainModel = EngineCore.AddModel("terrain.obj", "terrain");
            String quad         = EngineCore.AddModel("quad.obj", "Quad");
            String cubeObj      = EngineCore.AddModel("cube.obj", "Cube");

            EngineCore.AddModel("tree.obj", "tree");
            EngineCore.AddModel("rock.obj", "rock");



            Light l = new Light(new Vector3(0, 3, 0), System.Drawing.Color.White);

            ds.lights.Add(l);
            terrain.lights.Add(l);

            Light l2 = new Light(new Vector3(0, 10, 0), System.Drawing.Color.White);

            water.lights.Add(l2);

            EngineCore.AddImage("tree.png", "treeImg");
            EngineCore.AddImage("rock.png", "rockImg");

            String boatObj = EngineCore.AddModel("boat.obj", "Boat");

            EngineCore.AddImage("boards.jpg", "Boards");
            Boat boat = new Boat(new Vector3(2, 0.2f, 2), new Vector3(0, 34, 0), new Vector3(0.25f, 0.25f, 0.25f), "Boards");

            EngineCore.AddObject("Boat", boat);

            String  ground     = EngineCore.AddImage("grass.jpg", "Ground");
            Terrain terrainObj = new Terrain("New Terrain", "Ground", "heightMap.png");

            EngineCore.AddObject("Terrain", terrainObj);

            EngineCore.AddImage("dudv.png", "DuDvMap");
            EngineCore.AddImage("normal.png", "NormalMap");
            Water waterObj = new Water(new Vector3(0, 0.25f, 0), System.Drawing.Color.Blue, new Vector2(1920, 1080), "DuDvMap", new Vector3(10, 10, 10));

            waterObj.AttachNormalMap("NormalMap");
            EngineCore.AddObject("water", waterObj);

            EngineCore.AddSkybox(new string[] { "Skybox/xpos.png",
                                                "Skybox/xneg.png",
                                                "Skybox/ypos.png",
                                                "Skybox/yneg.png",
                                                "Skybox/zpos.png",
                                                "Skybox/zneg.png" }, "Skybox", 500);

            w.Run();
        }
Пример #2
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            EngineCore.gameCamera.Update();
            if (Keyboard[Key.Escape])
            {
                Exit();
            }
            EngineCore.gameCamera.rotation.Y += 0.08f * (Mouse.GetState().X - lastMousePosition.X);
            EngineCore.gameCamera.rotation.X += 0.08f * (Mouse.GetState().Y - lastMousePosition.Y);
            if (!selecting)
            {
                if (Keyboard[Key.W])
                {
                    EngineCore.gameCamera.position -= EngineCore.gameCamera.forward * 0.15f;
                }
                if (Keyboard[Key.S])
                {
                    EngineCore.gameCamera.position += EngineCore.gameCamera.forward * 0.15f;
                }
                if (Keyboard[Key.D])
                {
                    EngineCore.gameCamera.position += EngineCore.gameCamera.right * 0.15f;
                }
                if (Keyboard[Key.A])
                {
                    EngineCore.gameCamera.position -= EngineCore.gameCamera.right * 0.15f;
                }
            }
            else
            {
                if (Keyboard[Key.W])
                {
                    EngineCore.selected.position -= new Vector3(EngineCore.gameCamera.forward.X, 0, EngineCore.gameCamera.forward.Z) * 0.15f;
                }
                if (Keyboard[Key.S])
                {
                    EngineCore.selected.position += new Vector3(EngineCore.gameCamera.forward.X, 0, EngineCore.gameCamera.forward.Z) * 0.15f;
                }
                if (Keyboard[Key.D])
                {
                    EngineCore.selected.position += new Vector3(EngineCore.gameCamera.right.X, 0, EngineCore.gameCamera.right.Z) * 0.15f;
                }
                if (Keyboard[Key.A])
                {
                    EngineCore.selected.position -= new Vector3(EngineCore.gameCamera.right.X, 0, EngineCore.gameCamera.right.Z) * 0.15f;
                }
                if (Keyboard[Key.Q])
                {
                    EngineCore.selected.position.Y -= 0.025f;
                }
                if (Keyboard[Key.E])
                {
                    EngineCore.selected.position.Y += 0.025f;
                }

                EngineCore.gameCamera.position += EngineCore.gameCamera.forward * Mouse.GetState().WheelPrecise * 0.001f;
            }

            if (Keyboard[Key.Number1] && !num1Down)
            {
                RenderedEntity tree = new RenderedEntity(Vector3.Zero, new Vector3(0, rotationGenerator.Next(360), 0), Vector3.One * ((float)rotationGenerator.NextDouble() * 0.5f + 0.5f), "tree", "Default", "treeImg");
                EngineCore.AddObject("tree" + num, tree);
                num++;
                num1Down            = true;
                EngineCore.selected = tree;
                selecting           = true;
            }
            if (!Keyboard[Key.Number1])
            {
                num1Down = false;
            }

            if (Keyboard[Key.Number2] && !num2Down)
            {
                RenderedEntity rock = new RenderedEntity(Vector3.Zero, new Vector3(0, rotationGenerator.Next(360), 0), Vector3.One * ((float)rotationGenerator.NextDouble() * 0.2f + 0.2f), "rock", "Default", "rockImg");
                EngineCore.AddObject("rock" + num, rock);
                num++;
                num2Down            = true;
                EngineCore.selected = rock;
                selecting           = true;
            }
            if (!Keyboard[Key.Number2])
            {
                num2Down = false;
            }

            if (Keyboard[Key.Enter])
            {
                selecting = false;
            }

            if (Keyboard[Key.Up])
            {
                ((Water)EngineCore.gameObjects["water"]).position.Y += 0.05f;
                EngineCore.gameObjects["Boat"].position.Y           += 0.05f;
            }
            if (Keyboard[Key.Down])
            {
                ((Water)EngineCore.gameObjects["water"]).position.Y -= 0.05f;
                EngineCore.gameObjects["Boat"].position.Y           -= 0.05f;
            }
            EngineCore.gameCamera.CalculateMatrices(false);
            lastMousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
        }