• Main Page
  • Packages
  • Classes
  • Files
  • File List

C:/Doug/CSharp/XnaCollisionLib/XnaCollisionLib/Utils/Camera.cs

Go to the documentation of this file.
00001 using System;
00002 using Microsoft.Xna.Framework;
00003 
00004 namespace XnaCollisionLib.Utils
00005 {
00006     public class Camera
00007     {
00008         public Camera()
00009         {
00010             Position = new Vector3(0, 1, 0);
00011             Target = new Vector3(0, 0, 0);
00012             Up = new Vector3(0, 0, 1);
00013             Aspect = 800.0f / 600.0f;
00014             FieldOfView = 60;
00015             NearPlane = 1;
00016             FarPlane = 5000;
00017         }
00018 
00019         public Vector3 Position
00020         {
00021             get;
00022             set;
00023         }
00024 
00025         public Vector3 Target
00026         {
00027             get;
00028             set;
00029         }
00030 
00031         public Vector3 Up
00032         {
00033             get;
00034             set;
00035         }
00036 
00037         public float Aspect
00038         {
00039             get;
00040             set;
00041         }
00042 
00043         public float FieldOfView
00044         {
00045             get;
00046             set;
00047         }
00048 
00049         public float NearPlane
00050         {
00051             get;
00052             set;
00053         }
00054 
00055         public float FarPlane
00056         {
00057             get;
00058             set;
00059         }
00060 
00061         public Matrix View
00062         {
00063             get { return Matrix.CreateLookAt(Position, Target, Vector3.Normalize(Up)); }
00064         }
00065 
00066         public Matrix Projection
00067         {
00068             get { return Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(FieldOfView), Aspect, NearPlane, FarPlane); }
00069         }
00070 
00071         public void RotateAroundPosition(Vector2 d, Vector3 rotationAxis)
00072         {
00073             Vector3 f = Vector3.Normalize(Target - Position);
00074             Vector3 u = Vector3.Normalize(Up);
00075             Vector3 r = Vector3.Normalize(Vector3.Cross(f, u));
00076             Matrix rot = Matrix.CreateFromAxisAngle(rotationAxis, MathHelper.ToRadians(d.X));
00077 
00078             f = Vector3.TransformNormal(f, rot);
00079             r = Vector3.TransformNormal(r, rot);
00080             u = Vector3.Normalize(Vector3.Cross(r, f));
00081             rot = Matrix.CreateFromAxisAngle(r, MathHelper.ToRadians(d.Y));
00082             Target = Position + Vector3.TransformNormal(f, rot);
00083             Up = Vector3.TransformNormal(u, rot);
00084         }
00085     }
00086 }

Generated on Thu Jul 15 2010 19:56:39 for XnaCollisionLib by  doxygen 1.7.0