<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.xna.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Samples, Starter Kits, Tutorials</title><link>http://forums.xna.com/forums/59.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 0.0)</generator><item><title>Re: Upgraded the Chase Camera with rotation.</title><link>http://forums.xna.com/forums/thread/182005.aspx</link><pubDate>Sun, 24 May 2009 03:08:57 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:182005</guid><dc:creator>madgamer</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/182005.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=59&amp;PostID=182005</wfw:commentRss><description>Hey,&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I had the chance to play around with your updated ChaseCamera yesterday. I had already done some considerable modifications to the ChaseCamera sample game, so I didn&amp;#39;t have much luck with it. Whenever I would click the mouse button and drag, the view would rotate, but it was as if the camera was no longer updating it&amp;#39;s position - ie. the target that I was following would begin to move around freely (running away from the camera) while the camera appeared to rotate around a fixed point in space.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This could be caused by something else I had done (I made the ship much faster and only allowed for movement along X and Z - more like a car).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Also, the call to Mouse.Center() created some interesting bugs. If I tab out of the game while it&amp;#39;s running, then anywhere that I click on my screen does not register the mouse click for windows, but instead re-centers my mouse! At that point, the only thing I could do to end the sample program was ctrl+alt+del.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As I said in my original post, I wanted the camera to rotate based on the right thumbstick of the controller. For this particular application, I simply needed the camera to rotate to specific locations at either left, right, or in front (looking back). My solution was to simply set the ChaseCamera.desiredOffsetPosition Vector based on user input.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So far it&amp;#39;s working splendidly.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Just my input.&lt;/div&gt;&lt;div&gt;Thanks,&lt;/div&gt;&lt;div&gt;Tim&lt;/div&gt;</description></item><item><title>Re: Upgraded the Chase Camera with rotation.</title><link>http://forums.xna.com/forums/thread/181688.aspx</link><pubDate>Sat, 23 May 2009 02:17:43 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:181688</guid><dc:creator>madgamer</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/181688.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=59&amp;PostID=181688</wfw:commentRss><description>Sounds like you just did exactly what I was planning for my next step. I want to use the Right Thumbstick on the 360 controller to rotate my camera around the player character. Thanks, I&amp;#39;ll check this out today.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Tim&lt;/div&gt;</description></item><item><title>Re: Upgraded the Chase Camera with rotation.</title><link>http://forums.xna.com/forums/thread/178906.aspx</link><pubDate>Sat, 16 May 2009 19:12:33 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:178906</guid><dc:creator>Bail</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/178906.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=59&amp;PostID=178906</wfw:commentRss><description>Thanks man, this has been really helpful&lt;br /&gt;</description></item><item><title>Re: Upgraded the Chase Camera with rotation.</title><link>http://forums.xna.com/forums/thread/127104.aspx</link><pubDate>Sat, 10 Jan 2009 07:11:38 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:127104</guid><dc:creator>GreenBayRacer13fly</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/127104.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=59&amp;PostID=127104</wfw:commentRss><description>awsome work!&amp;nbsp; ima try this sometime.&lt;br /&gt;</description></item><item><title>Upgraded the Chase Camera with rotation.</title><link>http://forums.xna.com/forums/thread/126484.aspx</link><pubDate>Thu, 08 Jan 2009 18:01:45 GMT</pubDate><guid isPermaLink="false">4aa5dbf6-357b-46b2-b5b2-1b660a6dc370:126484</guid><dc:creator>THE LEXX</dc:creator><slash:comments>0</slash:comments><comments>http://forums.xna.com/forums/thread/126484.aspx</comments><wfw:commentRss>http://forums.xna.com/forums/commentrss.aspx?SectionID=59&amp;PostID=126484</wfw:commentRss><description>Greetings. &lt;br /&gt;
I used the Chase Camera demo for a demo project at work, and wanted to improve it a little with a rotation around the model for a more variable 3rd person view. Kind of like EVE Online. &lt;br /&gt;
&lt;br /&gt;
It also differs a little in that it is made a part of the components and the update method is called normally from the game loop. Forgive my nomenclature as I am not well versed in XNA program structures. I found the tutorial quite useful and wanted to share this version for those who might find it as useful as I found the original version. I got the Quaternion code from another demo, &lt;a href="http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2/Quaternions.php"&gt;http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2/Quaternions.php&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;/**&lt;br /&gt;
 * Chase Camera.&lt;br /&gt;
 * &lt;br /&gt;
 * Ref: &lt;a href="http://creators.xna.com/en-US/sample/chasecamera"&gt;http://creators.xna.com/en-US/sample/chasecamera&lt;/a&gt;&lt;br /&gt;
 * &lt;br /&gt;
 * To use (in main class):&lt;br /&gt;
  ChaseCamera camera;&lt;br /&gt;
  bool cameraSpringEnabled = true;&lt;br /&gt;
 &lt;br /&gt;
  camera = new ChaseCamera(this, content);&lt;br /&gt;
  // Set the camera offsets&lt;br /&gt;
  camera.DesiredPositionOffset = new Vector3(100.0f, 45.0f, -100.0f);&lt;br /&gt;
  camera.LookAtOffset = new Vector3(0.0f, 0.0f, 0.0f);&lt;br /&gt;
  // Set camera perspective&lt;br /&gt;
  camera.NearPlaneDistance = 10.0f;&lt;br /&gt;
  camera.FarPlaneDistance = 100000.0f;  &lt;br /&gt;
  &lt;br /&gt;
  this.Components.Add(camera);  // in initialize() function.&lt;br /&gt;
  // Set the camera aspect ratio&lt;br /&gt;
  // This must be done after the class to base.Initalize() which will&lt;br /&gt;
  // initialize the graphics device.&lt;br /&gt;
  camera.AspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height;&lt;/p&gt;
&lt;p&gt;  // Perform an inital reset on the camera so that it starts at the resting&lt;br /&gt;
  // position. If we don&amp;#39;t do this, the camera will start at the origin and&lt;br /&gt;
  // race across the world to get behind the chased object.&lt;br /&gt;
  // This is performed here because the aspect ratio is needed by Reset.&lt;br /&gt;
  UpdateCameraChaseTarget();&lt;br /&gt;
  camera.Reset();     &lt;/p&gt;
&lt;p&gt;  Function in main class:&lt;br /&gt;
   protected override void Update(GameTime gameTime)&lt;br /&gt;
    {&lt;br /&gt;
      UpdateCameraChaseTarget();&lt;br /&gt;
      base.Update(gameTime);&lt;br /&gt;
    }&lt;br /&gt;
  UpdateCameraChaseTarget(); // Called in main class Update function.&lt;br /&gt;
  &lt;br /&gt;
 * &lt;br /&gt;
 */&lt;/p&gt;
&lt;p&gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using Microsoft.Xna.Framework;&lt;br /&gt;
using Microsoft.Xna.Framework.Content;&lt;br /&gt;
using Microsoft.Xna.Framework.Input;&lt;/p&gt;
&lt;p&gt;namespace GraphicsDemoDOTNET&lt;br /&gt;
{&lt;br /&gt;
  public class ChaseCamera : DrawableGameComponent&lt;br /&gt;
  {&lt;br /&gt;
    private static ChaseCamera activeCamera = null;&lt;br /&gt;
    private ContentManager _content;&lt;/p&gt;
&lt;p&gt;    &lt;br /&gt;
    private Quaternion rotation;&lt;br /&gt;
    private float turnSpeed = 30f;&lt;br /&gt;
    int centerX;&lt;br /&gt;
    int centerY;&lt;/p&gt;
&lt;p&gt;    int mscroll;&lt;br /&gt;
    &lt;/p&gt;
&lt;p&gt;    #region Chased object properties (set externally each frame)&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Position of object being chased.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 ChasePosition&lt;br /&gt;
    {&lt;br /&gt;
      get { return chasePosition; }&lt;br /&gt;
      set { chasePosition = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private Vector3 chasePosition;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Direction the chased object is facing.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 ChaseDirection&lt;br /&gt;
    {&lt;br /&gt;
      get { return chaseDirection; }&lt;br /&gt;
      set { chaseDirection = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private Vector3 chaseDirection;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Chased object&amp;#39;s Up vector.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 Up&lt;br /&gt;
    {&lt;br /&gt;
      get { return up; }&lt;br /&gt;
      set { up = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private Vector3 up = Vector3.Up;&lt;/p&gt;
&lt;p&gt;    #endregion&lt;/p&gt;
&lt;p&gt;    public static ChaseCamera ActiveCamera&lt;br /&gt;
    {&lt;br /&gt;
      get { return activeCamera; }&lt;br /&gt;
      set { activeCamera = value; }&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    public ChaseCamera(Game game, ContentManager content)&lt;br /&gt;
      : base(game)&lt;br /&gt;
    {&lt;br /&gt;
      _content = content;&lt;br /&gt;
      Reset();&lt;br /&gt;
      if (ActiveCamera == null)&lt;br /&gt;
        ActiveCamera = this;&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    #region Desired camera positioning (set when creating camera or changing view)&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Desired camera position in the chased object&amp;#39;s coordinate system.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 DesiredPositionOffset&lt;br /&gt;
    {&lt;br /&gt;
      get { return desiredPositionOffset; }&lt;br /&gt;
      set { desiredPositionOffset = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private Vector3 desiredPositionOffset = new Vector3(0, 0.0f, 0.0f);&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Desired camera position in world space.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 DesiredPosition&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        // Ensure correct value even if update has not been called this frame&lt;br /&gt;
        UpdateWorldPositions();&lt;/p&gt;
&lt;p&gt;        return desiredPosition;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    private Vector3 desiredPosition;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Look at point in the chased object&amp;#39;s coordinate system.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 LookAtOffset&lt;br /&gt;
    {&lt;br /&gt;
      get { return lookAtOffset; }&lt;br /&gt;
      set { lookAtOffset = value; }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private Vector3 lookAtOffset = new Vector3(0, 0, 0);&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Look at point in world space.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 LookAt&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      { // Ensure correct value even if update has not been called this frame&lt;br /&gt;
        UpdateWorldPositions();&lt;br /&gt;
        return lookAt;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    private Vector3 lookAt;&lt;/p&gt;
&lt;p&gt;    #endregion&lt;/p&gt;
&lt;p&gt;    #region Camera physics (typically set when creating camera)&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Physics coefficient which controls the influence of the camera&amp;#39;s position&lt;br /&gt;
    /// over the spring force. The stiffer the spring, the closer it will stay to&lt;br /&gt;
    /// the chased object.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public float Stiffness&lt;br /&gt;
    {&lt;br /&gt;
      get { return stiffness; }&lt;br /&gt;
      set { stiffness = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private float stiffness = 1800.0f;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Physics coefficient which approximates internal friction of the spring.&lt;br /&gt;
    /// Sufficient damping will prevent the spring from oscillating infinitely.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public float Damping&lt;br /&gt;
    {&lt;br /&gt;
      get { return damping; }&lt;br /&gt;
      set { damping = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private float damping = 600.0f;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Mass of the camera body. Heaver objects require stiffer springs with less&lt;br /&gt;
    /// damping to move at the same rate as lighter objects.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public float Mass&lt;br /&gt;
    {&lt;br /&gt;
      get { return mass; }&lt;br /&gt;
      set { mass = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private float mass = 50.0f;&lt;/p&gt;
&lt;p&gt;    #endregion&lt;/p&gt;
&lt;p&gt;    #region Current camera properties (updated by camera physics)&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Position of camera in world space.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 Position&lt;br /&gt;
    {&lt;br /&gt;
      get { return position; }&lt;br /&gt;
    }&lt;br /&gt;
    private Vector3 position;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Velocity of camera.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Vector3 Velocity&lt;br /&gt;
    {&lt;br /&gt;
      get { return velocity; }&lt;br /&gt;
    }&lt;br /&gt;
    private Vector3 velocity;&lt;/p&gt;
&lt;p&gt;    #endregion&lt;/p&gt;
&lt;p&gt;    #region Perspective properties&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Perspective aspect ratio. Default value should be overriden by application.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public float AspectRatio&lt;br /&gt;
    {&lt;br /&gt;
      get { return aspectRatio; }&lt;br /&gt;
      set { aspectRatio = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private float aspectRatio = 4.0f / 3.0f;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Perspective field of view.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public float FieldOfView&lt;br /&gt;
    {&lt;br /&gt;
      get { return fieldOfView; }&lt;br /&gt;
      set { fieldOfView = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private float fieldOfView = MathHelper.ToRadians(45.0f); // Width of the view&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Distance to the near clipping plane.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public float NearPlaneDistance&lt;br /&gt;
    {&lt;br /&gt;
      get { return nearPlaneDistance; }&lt;br /&gt;
      set { nearPlaneDistance = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private float nearPlaneDistance = 1.0f;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Distance to the far clipping plane.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public float FarPlaneDistance&lt;br /&gt;
    {&lt;br /&gt;
      get { return farPlaneDistance; }&lt;br /&gt;
      set { farPlaneDistance = value; }&lt;br /&gt;
    }&lt;br /&gt;
    private float farPlaneDistance = 10000.0f;&lt;/p&gt;
&lt;p&gt;    #endregion&lt;/p&gt;
&lt;p&gt;    #region Matrix properties&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// View transform matrix.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Matrix View&lt;br /&gt;
    {&lt;br /&gt;
      get { return view; }&lt;br /&gt;
    }&lt;br /&gt;
    private Matrix view;&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Projecton transform matrix.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public Matrix Projection&lt;br /&gt;
    {&lt;br /&gt;
      get { return projection; }&lt;br /&gt;
    }&lt;br /&gt;
    private Matrix projection;&lt;/p&gt;
&lt;p&gt;    #endregion&lt;/p&gt;
&lt;p&gt;    #region Methods&lt;/p&gt;
&lt;p&gt;    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Rebuilds object space values in world space. Invoke before publicly&lt;br /&gt;
    /// returning or privately accessing world space values.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    private void UpdateWorldPositions()&lt;br /&gt;
    {&lt;br /&gt;
      // Construct a matrix to transform from object space to worldspace&lt;br /&gt;
      Matrix transform = Matrix.Identity;&lt;br /&gt;
      transform.Forward = ChaseDirection;&lt;br /&gt;
      transform.Up = Up;&lt;br /&gt;
      transform.Right = Vector3.Cross(Up, ChaseDirection);&lt;/p&gt;
&lt;p&gt;      // Calculate desired camera properties in world space&lt;br /&gt;
      desiredPosition = ChasePosition +&lt;br /&gt;
          Vector3.TransformNormal(DesiredPositionOffset, transform);&lt;br /&gt;
      lookAt = ChasePosition +&lt;br /&gt;
          Vector3.TransformNormal(LookAtOffset, transform);&lt;br /&gt;
    }&lt;br /&gt;
    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Rebuilds camera&amp;#39;s view and projection matricies.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    private void UpdateMatrices()&lt;br /&gt;
    {&lt;br /&gt;
      view = Matrix.CreateLookAt(this.Position, this.LookAt, this.Up);    &lt;br /&gt;
      projection = Matrix.CreatePerspectiveFieldOfView(FieldOfView,&lt;br /&gt;
          AspectRatio, NearPlaneDistance, FarPlaneDistance);&lt;br /&gt;
    }&lt;br /&gt;
    private void UpdateMatrices(int i)&lt;br /&gt;
    {&lt;br /&gt;
      Vector3 campos = new Vector3(0, 0.1f, 0.6f);&lt;br /&gt;
      campos = Vector3.Transform(campos, Matrix.CreateFromQuaternion(rotation));      &lt;br /&gt;
      Vector3 camup = new Vector3(0, 0, 0);&lt;br /&gt;
      camup = Vector3.Transform(camup, Matrix.CreateFromQuaternion(rotation));&lt;/p&gt;
&lt;p&gt;      view = Matrix.CreateLookAt(this.Position+campos, this.LookAt, this.Up + camup);&lt;/p&gt;
&lt;p&gt;      projection = Matrix.CreatePerspectiveFieldOfView(FieldOfView,&lt;br /&gt;
                               AspectRatio, NearPlaneDistance, FarPlaneDistance);&lt;/p&gt;
&lt;p&gt;    }&lt;br /&gt;
    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Forces camera to be at desired position and to stop moving. The is useful&lt;br /&gt;
    /// when the chased object is first created or after it has been teleported.&lt;br /&gt;
    /// Failing to call this after a large change to the chased object&amp;#39;s position&lt;br /&gt;
    /// will result in the camera quickly flying across the world.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public void Reset()&lt;br /&gt;
    {&lt;br /&gt;
      UpdateWorldPositions();&lt;br /&gt;
      // Stop motion&lt;br /&gt;
      velocity = Vector3.Zero;&lt;br /&gt;
      // Force desired position&lt;br /&gt;
      position = desiredPosition;&lt;br /&gt;
      rotation = new Quaternion(0, 0, 0, 1);      &lt;br /&gt;
      UpdateMatrices();&lt;br /&gt;
    }&lt;br /&gt;
    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Animates the camera from its current position towards the desired offset&lt;br /&gt;
    /// behind the chased object. The camera&amp;#39;s animation is controlled by a simple&lt;br /&gt;
    /// physical spring attached to the camera and anchored to the desired position.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    public override void Update(GameTime gameTime)&lt;br /&gt;
    {&lt;br /&gt;
      if (gameTime == null)&lt;br /&gt;
        throw new ArgumentNullException(&amp;quot;gameTime&amp;quot;);&lt;br /&gt;
      //KeyboardState keyboard = Keyboard.GetState();&lt;br /&gt;
      MouseState mouse = Mouse.GetState();&lt;br /&gt;
      UpdateWorldPositions();&lt;br /&gt;
           &lt;br /&gt;
      if (mouse.LeftButton == ButtonState.Pressed)&lt;br /&gt;
      {&lt;br /&gt;
        mscroll = 0;&lt;br /&gt;
        centerX = Game.Window.ClientBounds.Width / 2;&lt;br /&gt;
        centerY = Game.Window.ClientBounds.Height / 2;       &lt;br /&gt;
        Mouse.SetPosition(centerX, centerY);&lt;br /&gt;
        //RevolveGlobal(new Vector3(1, 0, 0), (MathHelper.ToRadians((mouse.Y - centerY) * turnSpeed * 0.01f)));&lt;br /&gt;
        Revolve(new Vector3(1, 0, 0), (mouse.Y - centerY) * 0.01f);&lt;br /&gt;
        //RevolveGlobal(new Vector3(0, 1, 0), (MathHelper.ToRadians((mouse.X - centerX) * turnSpeed * 0.01f)));&lt;br /&gt;
        Revolve(new Vector3(0, 1, 0), (mouse.X - centerX) * 0.01f);&lt;br /&gt;
     //   TranslateGlobal(new Vector3(0, 0, 0));&lt;br /&gt;
        Translate(new Vector3(0, 0, 0));             &lt;br /&gt;
        UpdateMatrices(1);&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
        mscroll = 1;&lt;br /&gt;
        float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;&lt;br /&gt;
        // Calculate spring force&lt;br /&gt;
        Vector3 stretch = position - desiredPosition;&lt;br /&gt;
        Vector3 force = -stiffness * stretch - damping * velocity;&lt;br /&gt;
        // Apply acceleration&lt;br /&gt;
        Vector3 acceleration = force / mass;&lt;br /&gt;
        velocity += acceleration * elapsed;&lt;br /&gt;
        // Apply velocity&lt;br /&gt;
        position += velocity * elapsed;        &lt;br /&gt;
        UpdateMatrices();      &lt;br /&gt;
      }&lt;br /&gt;
      //if (mouse.ScrollWheelValue &amp;lt;= mscroll)&lt;br /&gt;
      if (mscroll !=0 )&lt;br /&gt;
      {&lt;br /&gt;
        Translate(new Vector3(0, 0, mouse.ScrollWheelValue * 0.01f));        &lt;br /&gt;
      }&lt;br /&gt;
    }       &lt;br /&gt;
    #endregion&lt;/p&gt;
&lt;p&gt;    public void Rotate(Vector3 axis, float angle)&lt;br /&gt;
    {&lt;br /&gt;
      axis = Vector3.Transform(axis, Matrix.CreateFromQuaternion(rotation));&lt;br /&gt;
      rotation = Quaternion.Normalize(Quaternion.CreateFromAxisAngle(axis, angle) * rotation);&lt;br /&gt;
    }&lt;br /&gt;
    public void RotateGlobal(Vector3 axis, float angle)&lt;br /&gt;
    {&lt;br /&gt;
      rotation = Quaternion.Normalize(Quaternion.CreateFromAxisAngle(axis, angle) * rotation);&lt;br /&gt;
    }&lt;br /&gt;
    public void Translate(Vector3 distance)&lt;br /&gt;
    {&lt;br /&gt;
      position += Vector3.Transform(distance, Matrix.CreateFromQuaternion(rotation));&lt;br /&gt;
    }&lt;br /&gt;
    public void TranslateGlobal(Vector3 distance)&lt;br /&gt;
    {&lt;br /&gt;
      position += distance;&lt;br /&gt;
    }&lt;br /&gt;
    public void Revolve(Vector3 axis, float angle)&lt;br /&gt;
    {&lt;br /&gt;
      Vector3 revolveAxis = Vector3.Transform(axis, Matrix.CreateFromQuaternion(rotation));&lt;br /&gt;
      Quaternion rotate = Quaternion.CreateFromAxisAngle(revolveAxis, angle);&lt;br /&gt;
      position = Vector3.Transform(position - ChasePosition, Matrix.CreateFromQuaternion(rotate)) + ChasePosition;&lt;br /&gt;
      Rotate(axis, angle);&lt;br /&gt;
    }&lt;br /&gt;
    public void RevolveGlobal(Vector3 axis, float angle)&lt;br /&gt;
    {&lt;br /&gt;
      Quaternion rotate = Quaternion.CreateFromAxisAngle(axis, angle);&lt;br /&gt;
      position = Vector3.Transform(position - ChasePosition, Matrix.CreateFromQuaternion(rotate)) + ChasePosition;&lt;br /&gt;
      RotateGlobal(axis, angle);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;/p&gt;</description></item></channel></rss>