Exemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);


            Keyboard.KeyDown += (object sender, KeyboardKeyEventArgs key) => {
                if (key.Key == Key.F12)
                {
                    if (VSync == VSyncMode.Off)
                    {
                        VSync = VSyncMode.Adaptive;
                    }
                    else
                    {
                        VSync = VSyncMode.Off;
                    }
                }
                if (key.Key == Key.F11)
                {
                    if (WindowState != WindowState.Fullscreen)
                    {
                        WindowState = WindowState.Fullscreen;
                    }
                    else
                    {
                        WindowState = WindowState.Normal;
                    }
                }
                if (key.Key == Key.F10)
                {
                    Wireframe = !Wireframe;
                }
                if (key.Key == Key.F9)
                {
                    Bloom = !Bloom;
                }
                if (key.Key == Key.F8)
                {
                    Fxaa = !Fxaa;
                }
                if (key.Key == Key.F7)
                {
                    LightScattering = !LightScattering;
                }
                if (key.Key == Key.F1)
                {
                    ModelBatch.RowOrder = !ModelBatch.RowOrder;
                }
                if (key.Key == Key.F6)
                {
                    sun.Color = (sun.Color.Length == 0 ? new Vector3(1, 1, 1) : new Vector3(0, 0, 0));
                }
                if (key.Key == Key.Tab)
                {
                    Root.Remove(monkeynode);
                    Root.Add(monkeynode = new GameObject());
                }
                if (key.Key == Key.Space)
                {
                    monkeynode.Add(new ModelRenderer(monkey, new Matrix4(1, 0, 0, Camera.Position.X,
                                                                         0, 1, 0, Camera.Position.Y,
                                                                         0, 0, 1, Camera.Position.Z,
                                                                         0, 0, 0, 1) * Matrix4.CreateFromQuaternion(Camera.Rotation) * Matrix4.CreateRotationY((float)Math.PI)));
                }
            };
            Mouse.ButtonDown += (object sender, MouseButtonEventArgs key) => {
                if (CursorVisible == false)
                {
                    if (key.Button == MouseButton.Left)
                    {
                        Random rew = new Random();
                        monkeynode.Add(new PointLight(Camera.Position).SetColor(new Vector3((float)rew.NextDouble(), (float)rew.NextDouble(), (float)rew.NextDouble()) * 4));
                    }
                    if (key.Button == MouseButton.Middle)
                    {
                        Random rew = new Random();
                        monkeynode.Add(new DirectionalLight(Camera.Forward).SetColor(new Vector3((float)rew.NextDouble(), (float)rew.NextDouble(), (float)rew.NextDouble()) * 0.5f));
                    }
                    if (key.Button == MouseButton.Right)
                    {
                        Random rew = new Random();
                        monkeynode.Add(new SpotLight(Camera.Position, Camera.Forward).SetCLQ(1, 0.09f, 0.0001f).SetColor(new Vector3((float)rew.NextDouble(), (float)rew.NextDouble(), (float)rew.NextDouble()) * 4));
                    }
                }
            };

            AmbientLight = new Vector3(0.1f, 0.1f, 0.1f);

            sun  = new DirectionalLight(new Vector3(0, -1, 0));
            time = 30;
            Root.Add(sun);
            Root.Add(new LightScatteringComponent(new Vector3(1.0f, 0.8f, 0.3f)));


            monkey = ModelBatch.LoadModel(Faces.FromFile(@".\Data\Model\Monkey.lpm"));//new Model(faces)
            Root.Add((specialmonkey = new ModelRenderer(monkey, Matrix4.Identity)));
            Root.Add(new ModelRenderer(ModelBatch.LoadModel(Faces.FromFile(@".\Data\Model\World.lpm"))));
            Root.Add(monkeynode = new GameObject());
        }