00001 using System; 00002 using Microsoft.Xna.Framework; 00003 00004 namespace Mindshifter 00005 { 00010 public sealed class CameraSpring 00011 { 00012 private Vector3 mOrigin; 00013 private Vector3 mPosition; 00014 private Vector3 mVelocity; 00015 00016 private float mStiffness; 00017 private float mDamping; 00018 00022 public Vector3 Origin 00023 { 00024 get { return mOrigin; } 00025 set { mOrigin = value; } 00026 } 00027 00031 public Vector3 Position 00032 { 00033 get { return mPosition; } 00034 } 00035 00039 public Vector3 Velocity 00040 { 00041 get { return mVelocity; } 00042 } 00043 00047 public float Stiffness 00048 { 00049 get { return mStiffness; } 00050 set { mStiffness = value; } 00051 } 00052 00056 public float Damping 00057 { 00058 get { return mDamping; } 00059 set { mDamping = value; } 00060 } 00061 00065 public CameraSpring() 00066 { 00067 mStiffness = 36f; 00068 mDamping = 12f; 00069 } 00070 00075 public void Update(float elapsed) 00076 { 00077 Vector3 stretch = mPosition - mOrigin; 00078 Vector3 acceleration = -mStiffness * stretch - mDamping * mVelocity; 00079 mVelocity += acceleration * elapsed; 00080 mPosition += mVelocity * elapsed; 00081 } 00082 } 00083 }