Esempio n. 1
0
        public override void Update()
        {
            while (Shapes2Remove.Count > 0)
            {
                Shapes3D.Remove(Shapes2Remove.Pop().Name);
            }


            CheckKeyBoard();

            CheckMouse();

            Camera.LevelU2XZ(0.9998470f);

            Camera.Update();

            switch (CurrentState)
            {
            case State.Loading:
                return;

            case State.Starting:
                Start();
                return;

            case State.Running:
                Run();
                return;

            case State.Finishing:
                Finish();
                return;

            case State.Unloading:
                Unload();
                return;

            default:
                break;
            }
        }
Esempio n. 2
0
        public override void CheckKeyBoard()
        {
            base.CheckKeyBoard();


            if (GameWindow.Keyboard[Key.F10] && coolDown == 0)
            {
                Bitmap bitmapScreenShot = Tools.GrabScreenshot(GameWindow);

                bitmapScreenShot.Save("ScreenShots\\screenshot.bmp");

                coolDown = 20;
            }

            if (GameWindow.Keyboard[Key.Space] && coolDown == 0)
            {
                Shapes3D["pointSprites"].Position =
                    new Vector3(0, 50, 0);
                coolDown = 20;
            }

            if (GameWindow.Keyboard[Key.F] && coolDown == 0)
            {
                Shapes3D["sphereEnvCubeMap"].Position =
                    new Vector3(TargetPosition.X,
                                0.05f,
                                TargetPosition.Y);
                coolDown = 20;
            }

            if (GameWindow.Keyboard[Key.C] && coolDown == 0)
            {
                File.WriteAllText("cmera.txt",
                                  "position: " + Camera.Position +
                                  "quaternion: " + Camera.Quaternion);
                coolDown = 20;
            }

            if (GameWindow.Keyboard[Key.F11] && coolDown == 0)
            {
                Audio.Play(2, Vector3.Zero, true);
                coolDown = 20;
            }

            if (GameWindow.Keyboard[Key.F12] && coolDown == 0)
            {
                MyGame.Debug  = String.Empty;
                MyGame.Debug1 = String.Empty;
                coolDown      = 5;
            }

            if (GameWindow.Keyboard[Key.F3] && coolDown == 0)
            {
                TextRender.Visible = !TextRender.Visible;
                coolDown           = 10;
            }

            if (GameWindow.Keyboard[Key.F1] && coolDown == 0)
            {
                Vector3 v1 = new Vector3(Camera.CameraUVW.Row0);
                Vector3 v2 = new Vector3(Camera.CameraUVW.Row0.X,
                                         0f, Camera.CameraUVW.Row0.Z);

                v2.Normalize();

                float CameraUangle = Vector3.Dot(v2, v1);

                Vector3 axis = new Vector3(Camera.CameraUVW.Row2.X,
                                           Camera.CameraUVW.Row2.Y,
                                           Camera.CameraUVW.Row2.Z);

                float angle = (float)Math.Acos(Convert.ToDouble(CameraUangle));

                if (Camera.CameraUVW.Row0.Y > 0)
                {
                    Camera.Rotate(axis, angle);
                }
                else
                {
                    Camera.Rotate(axis, -angle);
                }


                coolDown = 20;
            }



            if (GameWindow.Keyboard[Key.I] &&
                (MyGame.TableXAngle < MathHelper.
                 DegreesToRadians(MyGame.MaxTableAngle)))
            {
                MyGame.TableXAngle += MyGame.DeltaTableAngle;
            }

            if (GameWindow.Keyboard[Key.K] &&
                (MyGame.TableXAngle > -MathHelper.
                 DegreesToRadians(MyGame.MaxTableAngle)))
            {
                MyGame.TableXAngle -= MyGame.DeltaTableAngle;
            }

            if (GameWindow.Keyboard[Key.J] &&
                (MyGame.TableZAngle < MathHelper.
                 DegreesToRadians(MyGame.MaxTableAngle)))
            {
                MyGame.TableZAngle += MyGame.DeltaTableAngle;
            }

            if (GameWindow.Keyboard[Key.L] &&
                (MyGame.TableZAngle > -MathHelper.
                 DegreesToRadians(MyGame.MaxTableAngle)))
            {
                MyGame.TableZAngle -= MyGame.DeltaTableAngle;
            }

            if (GameWindow.Keyboard[Key.Q])
            {
                Camera.TranslateLC(0, 0, 5f);
            }
            if (GameWindow.Keyboard[Key.A])
            {
                Camera.TranslateLC(0, 0, -5f);
            }


            if (GameWindow.Keyboard[Key.X])
            {
                Camera.Position = new Vector3(Camera.Position.X,
                                              -5f + Camera.Position.Y,
                                              Camera.Position.Z);
            }

            if (GameWindow.Keyboard[Key.LShift])
            {
                Camera.Position = new Vector3(Camera.Position.X,
                                              5f + Camera.Position.Y,
                                              Camera.Position.Z);
            }

            float speed = 2f;

            if (GameWindow.Keyboard[Key.Keypad8] && coolDown == 0)
            {
                Shapes3D["sphereEnvCubeMap"].Physic.Vuvw
                    = new Vector3(Shapes3D["sphereEnvCubeMap"].Physic.Vuvw.X,
                                  Shapes3D["sphereEnvCubeMap"].Physic.Vuvw.Y,
                                  -speed);

                coolDown = 5;
            }
            if (GameWindow.Keyboard[Key.Keypad2] && coolDown == 0)
            {
                Shapes3D["sphereEnvCubeMap"].Physic.Vuvw =
                    new Vector3(0, 0, speed);

                coolDown = 5;
            }
            if (GameWindow.Keyboard[Key.Keypad4] && coolDown == 0)
            {
                Shapes3D["sphereEnvCubeMap"].Physic.Vxyz =
                    new Vector3(-speed, 0, 0);

                coolDown = 5;
            }
            if (GameWindow.Keyboard[Key.Keypad6] && coolDown == 0)
            {
                Shapes3D["sphereEnvCubeMap"].Physic.Vxyz =
                    new Vector3(speed, 0, 0);

                coolDown = 5;
            }


            if (GameWindow.Keyboard[Key.Number6] && coolDown == 0)
            {
                ShadowMap.LightView.TranslateWC(-10, 0, 0);
                ShadowMap.UpdateView();

                Shapes3D["sphereEnvCubeMap"].ShadowMatrix =
                    ShadowMap.ShadowMatrix;

                coolDown = 30;
            }
            if (GameWindow.Keyboard[Key.Number7] && coolDown == 0)
            {
                ShadowMap.LightView.TranslateWC(10, 0, 0);
                ShadowMap.UpdateView();

                Shapes3D["sphereEnvCubeMap"].ShadowMatrix =
                    ShadowMap.ShadowMatrix;

                coolDown = 30;
            }



            if (GameWindow.Keyboard[Key.KeypadPlus] && coolDown == 0)
            {
                Vector4 tempV4 = new Vector4(SunLightPosition.X,
                                             SunLightPosition.Y,
                                             SunLightPosition.Z,
                                             0);
                tempV4 = Vector4.Transform(tempV4, Matrix4.CreateRotationY(0.05f));

                SunLightPosition = tempV4.Xyz;
            }
            if (GameWindow.Keyboard[Key.KeypadMinus] && coolDown == 0)
            {
                Vector4 tempV4 = new Vector4(SunLightPosition.X,
                                             SunLightPosition.Y,
                                             SunLightPosition.Z,
                                             0);
                tempV4 = Vector4.Transform(tempV4, Matrix4.CreateRotationY(-0.05f));

                SunLightPosition = tempV4.Xyz;
            }

            if (GameWindow.Keyboard[Key.KeypadMultiply] && coolDown == 0)
            {
                CubesHaveNormalMap = !CubesHaveNormalMap;
                coolDown           = 10;
            }

            if (GameWindow.Keyboard[Key.KeypadDecimal] && coolDown == 0)
            {
                Shapes3D.Remove("sphereEnvCubeMap");

                ToggleSmooth = !ToggleSmooth;

                Shape3D sphere1 = new Sphere3D(new Vector3(-45f, 1.5f, -45f), 1.5f,
                                               Color4.Gold, Textures["sphere_texture"], ToggleSmooth);
                sphere1.Physic.Mass      = 10f;
                sphere1.Physic.Vxyz      = Vector3.Zero;
                sphere1.ShadowMatrix     = ShadowMap.ShadowMatrix;
                sphere1.TextureShadowMap = ShadowMap.DepthTexture;
                sphere1.Bounding.R       = 1.5f;
                sphere1.Load();
                Shapes3D.Add("sphereEnvCubeMap", sphere1);



                coolDown = 10;
            }

            if (GameWindow.Keyboard[Key.M] && coolDown == 0)
            {
                MyGame.MultiView = !MyGame.MultiView;

                if (MyGame.MultiView)
                {
                    MyGame.Width  = 800;
                    MyGame.Height = (int)(MyGame.Width / aspectRatio);
                }
                else
                {
                    MyGame.Width  = GameWindow.Width;
                    MyGame.Height = GameWindow.Height;
                }

                MyGame.ProjectionMatrix =
                    Matrix4.CreatePerspectiveFieldOfView(
                        MathHelper.PiOver4,
                        MyGame.Width / (float)MyGame.Height,
                        0.5f,
                        1000f);

                //ShadowMap.ProjectionMatrixLightView = MyGame.ProjectionMatrix;
                ShadowMap.UpdateView();

                foreach (var item in Shapes3D)
                {
                    item.Value.ShadowMatrix = ShadowMap.ShadowMatrix;
                }

                coolDown = 30;
            }
            //if (Keyboard[Key.S]) Shapes3D["sphere"].
            //        VertexBuffer.SerializeBufer(@"Models\sphere.xml");

            if (GameWindow.Keyboard[Key.T])
            {
                Tools.
                GenerateModelFrom3DS(@"Models\sphere3D.x3d");
            }
        }