/*
* FollowCamera.cs
* Authors:
* 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 tAC_Engine.Graphics.Cameras;
using tAC_Engine.Graphics.Entities;
using Microsoft.Xna.Framework;
namespace tAC_Engine.Graphics.Cameras
{
///
/// Defines a perspective 3D camera that follows a given object
///
public class FollowCamera : Perspective3DCamera
{
#region Fields
///
/// The amount of rotation along the x axis
///
public float xRot;
///
/// The amount of rotation along the y axis
///
public float yRot;
///
/// The amount of rotation along the z axis
///
public float zRot;
// Position offset
Vector3 mOffset;
// Model in which the camera follows
EntityModel mFollow;
#endregion
#region Properties
///
/// Gets/Sets the postion offset
///
public Vector3 Offset
{
get { return mOffset; }
set { mOffset = value; }
}
///
/// Gets/Sets the object in which the camera will follow
///
public EntityModel Follow
{
get { return mFollow; }
set { mFollow = value; }
}
#endregion
#region Creation
///
/// Creates a camera that will follow a model
///
/// the model to follow
/// the distance the camrea will be away from the model
/// The direction in which up is for the camera
/// The camera's field of view
/// The apsect ratio (width to height) of the camera
/// How close to the camera rendering can start
/// How far from the camera rendering can go
public FollowCamera(EntityModel follow, Vector3 offset, Vector3 up, float fov, float aspectRatio, float near, float far)
: base(Vector3.Zero, Vector3.Zero, up, fov, aspectRatio, near, far)
{
mFollow = follow;
mOffset = offset;
xRot = 0.0f;
yRot = 0.0f;
zRot = 0.0f;
}
///
/// Creates the angle at which the scene is viewed at to be displayed
///
protected override void CreateView()
{
//base.CreateView();
if (mFollow != null)
{
mEye = new Vector3(0, 5, 0);
//mEye = Vector3.Transform(Offset, Matrix.CreateFromYawPitchRoll(mFollow.rotY, mFollow.rotX, mFollow.rotZ));
// mEye = mEye + //mFollow.TransformationMatrix.Translation;
Vector3 camUp = Up;
//camUp = Vector3.Transform(camUp, Matrix.CreateFromYawPitchRoll(mFollow.rotY, mFollow.rotX, mFollow.rotZ));
mView = Matrix.CreateLookAt(mEye, mFollow.TransformationMatrix.Translation, camUp);
}
}
#endregion
#region Update
///
/// Updates the follow camera
///
public void update()
{
CreateView();
}
#endregion
}
}