//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.Stream
{
#region Using Statements
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
///
/// Camera class
///
public class Camera
{
///
/// Viewport associated with this Camera
///
public Viewport viewport;
///
/// Allows user to move camera around relative the Mass's currentPosition
///
public Vector3 offset = new Vector3(700, 1500, 700);
///
/// Constructor
///
public Camera()
{
viewport = new Viewport();
}
///
/// Generates the View Matrix based on the mass's position and the camera offset
///
/// Player's current position
/// Player's normal Vector
/// Player's up vector
/// View Matrix
public Matrix GetViewMatrix(Vector3 currentPosition, Vector3 normalVector, Vector3 upVector)
{
// Calculate new camera position relative to current position
Vector3 cameraPosition = currentPosition - (offset * normalVector);
// Calculate new lookAtPosition in the opposite direction of cameraPosition relative to current position
Vector3 lookAtPosition = currentPosition + normalVector + (offset * normalVector);
// Use just the height value or camera goes wobbly sideways
Vector3 upVec = upVector + new Vector3(0, offset.Y, 0);
// Make sure camera doesn't go below player position (clipping)
if(cameraPosition.Y < currentPosition.Y)
cameraPosition.Y = currentPosition.Y;
// return final view matrix
return Matrix.CreateLookAt(
cameraPosition,
lookAtPosition,
upVec
);
}
///
/// Generates the projection matrix
///
/// Projection matrix
public Matrix GetProjectionMatrix()
{
return
Matrix.CreatePerspectiveFieldOfView(
(float)Math.PI / 4,
viewport.Width / viewport.Height,
0.3f, 100000f
);
}
}
}