topical media & game development
game-xna-intro-XnaGraphicEngineChapter5-Game-SimpleCamera.cs / cs
// Project: XnaGraphicEngine, File: SimpleCamera.cs
// Namespace: XnaGraphicEngine.Game, Class: SimpleCamera
// Path: C:\code\Xna\XnaGraphicEngine\Game, Author: Abi
// Code lines: 126, Size of file: 3,06 KB
// Creation date: 13.03.2007 22:57
// Last modified: 16.03.2007 05:02
// Generated with Commenter by abi.exDream.com
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using XnaGraphicEngine.Helpers;
#endregion
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;
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.