#region File Description //----------------------------------------------------------------------------- // GameCamera.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #endregion #region Using Statements using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using RobotGameData.Helper; #endregion namespace RobotGameData.Camera { /// /// It's a tremble camera /// public class GameCamera : CameraBase { #region Fields /// /// The Camera's trembling amount /// Vector3 trembleOffset = Vector3.Zero; float trembleCircle = 0.0f; float trembleTime = 0.0f; float trembleAccTime = 0.0f; #endregion #region Properties public Vector3 TrembleOffset { get { return this.trembleOffset; } } #endregion /// /// Constructor. /// public GameCamera() : base() { trembleOffset = Vector3.Zero; trembleCircle = 0.0f; trembleTime = 0.0f; trembleAccTime = 0.0f; } /// /// Update the tremble time and position /// protected override void OnUpdate(GameTime gameTime) { // Calculates trembling time if (trembleAccTime < trembleTime) { trembleAccTime += (float)gameTime.ElapsedGameTime.TotalSeconds; // Set to randomize trembling position trembleOffset.X = HelperMath.RandomNormal() * HelperMath.RandomNormal2() * trembleCircle; trembleOffset.Y = HelperMath.RandomNormal() * HelperMath.RandomNormal2() * trembleCircle; trembleOffset.Z = 0.0f; } // Stop trembling time else if (trembleAccTime >= trembleTime) { trembleAccTime = 0.0f; trembleTime = 0.0f; } base.OnUpdate(gameTime); } /// /// Tremble the camera /// /// tremble time /// tremble amount public void SetTremble(float rTime, float rCircle) { trembleAccTime = 0.0f; trembleTime = rTime; trembleCircle = rCircle; } } }