/* * PerspectiveCamera2D.cs * Authors: Bradley Blankenship * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; namespace tAC_Engine.Graphics.Cameras { /// /// Creates a perspective camera with a fixed position and look at angle to /// give an appearence of a 2D scene with depth /// public class Perspective2DCamera : PerspectiveCamera { #region Properties /// /// Gets/Sets the eye vector /// public override Vector3 Eye { get { return mEye; } set { // Check to see if we need to set values and recalculate if (mEye != value) { mLookAt -= mEye; mEye = value; mLookAt += mEye; CreateView(); } } } /// /// Gets the look at vector /// public override Vector3 LookAt { get { return mLookAt; } // Do not allow overriding; this must stay the same for // a proper 2D camera. set { } } /// /// Gets the up vector /// public override Vector3 Up { get { return mUp; } // Do not allow overriding; this must stay the same for // a proper 2D camera. set { } } #endregion #region Constructs /// /// Default Projection Camera with no values set. /// public Perspective2DCamera() { // Create the projection and view matrixes CreateView(); CreateProjection(); } /// /// Paramaterized Constructor for perspective camera. /// /// The position vector of the camera /// The field of view, in radians /// The aspect ratio for the camera /// The distance to the near plane /// The distance to the far plane public Perspective2DCamera(Vector3 eye, float fov, float aspectRatio, float near, float far) { // Set all of the values mEye.X = eye.X; mEye.Y = eye.Y; mEye.Z = 0; mLookAt = Vector3.Forward + mEye; mUp = Vector3.Up; mFOV = fov; mAspectRatio = aspectRatio; mNear = near; mFar = far; // Create the view and projection matrixes CreateView(); CreateProjection(); } #endregion #region Helpers /// /// Creates the projection Matrix for the given camera. /// protected override void CreateProjection() { // Create the projection matrix mProjection = Matrix.CreatePerspectiveFieldOfView(mFOV, mAspectRatio, mNear, mFar); } #endregion } }