/*
* OrthographicCamera.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
{
///
/// Defines an orthographic camera to give a 2D visual effect
///
public class OrthographicCamera : Camera
{
#region Fields
// The width of the screen
float mWidth;
// The height of the screen
float mHeight;
// The near plane distance
float mNear;
// The far plane distance
float mFar;
#endregion
#region Properties
///
/// 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 { }
}
///
/// 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)
{
// Alter the lookAt
mLookAt -= mEye;
mEye = value;
mLookAt += mEye;
CreateView();
}
}
}
///
/// Gets/Sets the screen width
///
public float Width
{
get { return mWidth; }
set
{
// Check to see if we need to recalculate the camera projection
if (mWidth != value)
{
mWidth = value;
CreateProjection();
}
}
}
///
/// Gets/Sets the screen height
///
public float Height
{
get { return mHeight; }
set
{
// Check to see if we need to recalculate the camera projection
if (mHeight != value)
{
mHeight = value;
CreateProjection();
}
}
}
///
/// Gets/Sets the distance to the near plane
///
public float Near
{
get { return mNear; }
set
{
// Check to see if we need to recalculate the camera projection
if (mNear != value)
{
mNear = value;
CreateProjection();
}
}
}
///
/// Gets/Sets the distance to the far plane
///
public float Far
{
get { return mFar; }
set
{
// Check to see if we need to recalculate the camera projection
if (mFar != value)
{
mFar = value;
CreateProjection();
}
}
}
#endregion
#region Constructs
///
/// Basic constructor
///
public OrthographicCamera()
{
// Create the view and projection matrices
CreateView();
CreateProjection();
}
///
/// Paramaterized constructor
///
/// Position of where the camera eye is
/// Width of the projection field
/// Height of the projection field
/// Distance to the near plane
/// Distance to the far plane
public OrthographicCamera(Vector3 eye, float width, float height,
float near, float far)
{
// Set the values
mEye = eye;
mLookAt = Vector3.Forward + mEye;
mUp = Vector3.Up;
mWidth = width;
mHeight = height;
mNear = near;
mFar = far;
// Create the views and projection matrices
CreateView();
CreateProjection();
}
#endregion
#region Helpers
///
/// CreateProjection - Creates the projection Matrix for the given camera.
///
protected override void CreateProjection()
{
// Create the projection matrix
mProjection = Matrix.CreateOrthographic(mWidth, mHeight, mNear, mFar);
}
#endregion
}
}