public WindowsPhoneSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            GraphicsScreen.ClearBackground = true;
            GraphicsScreen.BackgroundColor = Color.CornflowerBlue;

            // Set a fixed camera.
            var projection = new PerspectiveProjection();

            projection.SetFieldOfView(
                MathHelper.ToRadians(30),
                GraphicsService.GraphicsDevice.Viewport.AspectRatio,
                1f,
                1000.0f);
            Vector3F cameraTarget   = new Vector3F(0, 1, 0);
            Vector3F cameraPosition = new Vector3F(0, 12, 0);
            Vector3F cameraUpVector = new Vector3F(0, 0, -1);

            GraphicsScreen.CameraNode = new CameraNode(new Camera(projection))
            {
                View = Matrix44F.CreateLookAt(cameraPosition, cameraTarget, cameraUpVector),
            };

            // We use the accelerometer to control the camera view. The accelerometer registers every
            // little change, but we do not want a shaky camera. We can use a low-pass filter to smooth
            // the sensor signal.
            _lowPassFilter = new LowPassFilter(new Vector3F(0, -1, 0))
            {
                TimeConstant = 0.15f, // Let's try a time constant of 0.15 seconds.
                // When increasing the time constant the camera becomes more stable,
                // but also slower.
            };

            // Enable touch gestures
            _originalEnabledGestures   = TouchPanel.EnabledGestures;
            TouchPanel.EnabledGestures =
                GestureType.Tap      // Tap is used to drop new bodies.
                | GestureType.Flick  // Flick creates an explosion.
                | GestureType.Hold   // Hold to clear the scene.
                | GestureType.Pinch; // Pinch can be used to zoom in or out.

            InitializePhysics();
        }
Exemple #2
0
    public WindowsPhoneSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      GraphicsScreen.ClearBackground = true;
      GraphicsScreen.BackgroundColor = Color.CornflowerBlue;

      // Set a fixed camera.
      var projection = new PerspectiveProjection();
      projection.SetFieldOfView(
        MathHelper.ToRadians(30),
        GraphicsService.GraphicsDevice.Viewport.AspectRatio,
        1f,
        1000.0f);
      Vector3F cameraTarget = new Vector3F(0, 1, 0);
      Vector3F cameraPosition = new Vector3F(0, 12, 0);
      Vector3F cameraUpVector = new Vector3F(0, 0, -1);
      GraphicsScreen.CameraNode = new CameraNode(new Camera(projection))
      {
        View = Matrix44F.CreateLookAt(cameraPosition, cameraTarget, cameraUpVector),
      };

      // We use the accelerometer to control the camera view. The accelerometer registers every 
      // little change, but we do not want a shaky camera. We can use a low-pass filter to smooth
      // the sensor signal. 
      _lowPassFilter = new LowPassFilter(new Vector3F(0, -1, 0))
      {
        TimeConstant = 0.15f, // Let's try a time constant of 0.15 seconds.
        // When increasing the time constant the camera becomes more stable,
        // but also slower.
      };

      // Enable touch gestures
      _originalEnabledGestures = TouchPanel.EnabledGestures;
      TouchPanel.EnabledGestures =
        GestureType.Tap           // Tap is used to drop new bodies.
        | GestureType.Flick       // Flick creates an explosion.
        | GestureType.Hold        // Hold to clear the scene.
        | GestureType.Pinch;      // Pinch can be used to zoom in or out.

      InitializePhysics();
    }