Exemple #1
0
        public override void Update()
        {
            int X, Y, Wheel = 0;

            Engine.Input.GetMouse(out X, out Y, out Wheel);
            RLog.Info(String.Format("Mouse [ X:{0}, Y:{1} ]", X, Y));
            Vector2 center_of_window = new Vector2(GameWindow.Width / 2, GameWindow.Height / 2);
            Vector2 mouse_direction  = new Vector2(X, Y);

            mouse_direction    = (mouse_direction - center_of_window);
            mouse_direction.X /= GameWindow.Width;
            mouse_direction.Y /= GameWindow.Height;
            mouse_direction   *= .80f;
            var cam = Engine.GetCamera();

            if (Engine.Input.IsKeyDown(RKey.W))
            {
                direction += cam.Matrix.Forward * 0.1f;
            }
            if (Engine.Input.IsKeyDown(RKey.S))
            {
                direction += cam.Matrix.Backward * 0.1f;
            }
            if (Engine.Input.IsKeyDown(RKey.A))
            {
                direction += cam.Matrix.Left * 0.1f;
            }
            if (Engine.Input.IsKeyDown(RKey.D))
            {
                direction += cam.Matrix.Right * 0.1f;
            }
            panning.X += mouse_direction.X * 2f;
            panning.Y += mouse_direction.Y * 2f;
            sponza.Update();
            direction *= 0.90f;
            //cam.RotateX(-mouse_direction.Y * 2f);
            //if (cam.Rotation.X > Math.PI/2)
            //    cam.Rotation = new Quaternion((float)Math.PI/2, cam.Rotation.Y, cam.Rotation.Z, cam.Rotation.W);
            //if (cam.Rotation.X < -Math.PI/2)
            //    cam.Rotation = new Quaternion(-(float)Math.PI/2, cam.Rotation.Y, cam.Rotation.Z, cam.Rotation.W);
            //
            //cam.RotateY(-mouse_direction.X * 2f);
            cam.Move(direction);
            cam.Update();
            //if(GameWindow.Focused)
            //Engine.Input.CenterMouse();
            if (Engine.Input.IsKeyDown(RKey.Escape))
            {
                GameWindow.Exit();
            }
        }
Exemple #2
0
        public override void Update()
        {
            float   dt   = (float)(Engine.GetElapsedTime() / Engine.GetFPS());
            Vector3 move = Vector3.Zero;

            RLog.Info(String.Format("Time: {0}", dt));
            int X, Y, Wheel = 0;

            Engine.Input.GetMouse(out X, out Y, out Wheel);

            var     window_bounds   = GameWindow.ClientRectangle;
            Vector2 mouse_position  = new Vector2(X, Y);
            Vector2 mouse_direction = mouse_position - prev_mouse;

            RLog.Info(String.Format("Mouse [ X:{0}, Y:{1} ]", mouse_direction.X, mouse_direction.Y));

            var cam = Engine.GetCamera();


            if (Engine.Input.IsKeyDown(RKey.W))
            {
                move.Z += 0.5f * dt;
            }
            if (Engine.Input.IsKeyDown(RKey.S))
            {
                move.Z -= 0.5f * dt;
            }
            if (Engine.Input.IsKeyDown(RKey.A))
            {
                move.X += 0.5f * dt;
            }
            if (Engine.Input.IsKeyDown(RKey.D))
            {
                move.X -= 0.5f * dt;
            }

            sponza.Update();

            //cam.Rotate(Quaternion.CreateFromYawPitchRoll(MathHelper.ToRadians(yaw), MathHelper.ToRadians(pitch), 0));
            cam.Move(move);
            cam.ViewDirection = Vector3.Transform(cam.ViewDirection, Matrix.CreateFromAxisAngle(
                                                      cam.Up, (-MathHelper.PiOver4 / 150) * mouse_direction.X));

            cam.ViewDirection = Vector3.Transform(cam.ViewDirection, Matrix.CreateFromAxisAngle(
                                                      Vector3.Cross(cam.Up, cam.ViewDirection),
                                                      (-MathHelper.PiOver4 / 100) * mouse_direction.Y));

            cam.Up = Vector3.Transform(cam.Up, Matrix.CreateFromAxisAngle(Vector3.Cross(cam.Up, cam.ViewDirection),
                                                                          (-MathHelper.PiOver4 / 100) * mouse_direction.Y));

            //cam.View = Matrix.CreateLookAt(cam.Position, cam.Position + cam.ViewDirection, cam.Up);
            //cam.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(70f), Engine.GetViewport().AspectRatio, 0.1f, 1000f);
            cam.Update();

            prev_mouse = mouse_position;
            Engine.Input.CenterMouse();

            if (Engine.Input.IsKeyDown(RKey.Escape))
            {
                GameWindow.Exit();
            }
        }