topical media & game development 
  
 
 
 
 
  
    
    
  
 game-xna-intro-XnaShooterSoundProject-Game-SimpleCamera.cs / cs
  using System;
  using System.Collections.Generic;
  using System.Text;
  using Microsoft.Xna.Framework;
  using XnaGraphicEngine.Helpers;
  
  namespace XnaGraphicEngine.Game
  {
   <summary>
 Simple camera class just to move around a little.
 Always focuses on the center and uses the same height.
 
</summary>
	class SimpleCamera : GameComponent
        {
                #region Variables
                float x = 0, y = 0;
                float zHeight = 15.0f;
                #endregion
                  #region Constructor
                  public SimpleCamera(BaseGame game)
                          : base(game)
                  {
                  } // SimpleCamera(game)
                  #endregion
  
                  #region Initialize
                  public override void Initialize()
                  {
                          base.Initialize();
                  } // Initialize
                  #endregion
  
                  #region Update
                  public override void Update(GameTime gameTime)
                  {
                          base.Update(gameTime);
  
                          // Update camera position (allow mouse and gamepad)
                          x += Input.MouseXMovement / 10;
                          y += Input.MouseYMovement / 10;
                          x += Input.GamePad.ThumbSticks.Right.X;
                          y += Input.GamePad.ThumbSticks.Right.Y;
                          zHeight += Input.GamePad.ThumbSticks.Left.Y;
                          zHeight += Input.MouseWheelDelta / 20;
                          BaseGame.ViewMatrix = Matrix.CreateLookAt(
                                  new Vector3(x, y, zHeight), Vector3.Zero, Vector3.Up);
                  } // Update(gameTime)
                  #endregion
          } // class SimpleCamera
  } // namespace XnaGraphicEngine.Game
  
  
  
(C) Æliens 
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. 
In case of other copyright issues, contact the author.