2019-12-28 21:41:06 +00:00
using OpenTK ;
2019-12-28 20:35:01 +00:00
namespace RecrownedAthenaeum.Graphics.Render
2019-02-06 06:11:22 +00:00
{
/// <summary>
2019-03-24 00:04:43 +00:00
/// A generic camera. Functions in 3D.
2019-02-06 06:11:22 +00:00
/// </summary>
2019-03-24 00:04:43 +00:00
public class BasicCamera
2019-02-06 06:11:22 +00:00
{
2019-03-10 06:46:28 +00:00
/// <summary>
2019-03-21 00:28:16 +00:00
/// The scale for the world.
2019-03-10 06:46:28 +00:00
/// </summary>
public float worldScale = 1f ;
2019-02-06 06:11:22 +00:00
/// <summary>
/// Current position in the world.
/// </summary>
public Vector3 position ;
/// <summary>
/// The place the 3D camera is looking at.
/// </summary>
public Vector3 lookAt ;
/// <summary>
2019-03-24 00:04:43 +00:00
/// The direction up is for the camera.
2019-02-06 06:11:22 +00:00
/// </summary>
public Vector3 upDirection ;
/// <summary>
/// The transform matrix representing the world (rotation and translations of the original world).
/// </summary>
public Matrix worldMatrix ;
/// <summary>
/// The view matrix that describes where the camera looks.
/// </summary>
2019-03-10 06:46:28 +00:00
public Matrix ViewMatrix { get ; protected set ; }
2019-02-06 06:11:22 +00:00
/// <summary>
/// The projection matrix.
/// </summary>
public Matrix projectionMatrix ;
/// <summary>
2019-03-24 00:04:43 +00:00
/// A basic effect that will be updated with the correct matrice information everytime <see cref="Apply"/> is called. Can be null and thus will not be used.
2019-02-06 06:11:22 +00:00
/// </summary>
2019-03-24 00:04:43 +00:00
public BasicEffect basicEffect ;
2019-02-25 04:44:02 +00:00
2019-02-06 06:11:22 +00:00
/// <summary>
/// Constructs 3D camera with an orthographic projection matrix with dimensions of graphics devices viewport. All changes to matrices should have apply called after changes.
/// </summary>
2019-03-24 00:04:43 +00:00
/// <param name="basicEffect">A basic effect that will be updated with the correct matrice information everytime <see cref="Apply"/> is called. Can be null and thus will not be used.</param>
public BasicCamera ( BasicEffect basicEffect = null )
2019-02-06 06:11:22 +00:00
{
worldMatrix = Matrix . Identity ;
lookAt = Vector3 . Forward ;
upDirection = Vector3 . Up ;
2019-02-11 05:28:48 +00:00
projectionMatrix = Matrix . Identity ;
2019-03-24 00:04:43 +00:00
this . basicEffect = basicEffect ;
2019-02-06 06:11:22 +00:00
Apply ( ) ;
}
/// <summary>
/// Applies the changes to the fields and properties of the camera.
/// </summary>
public virtual void Apply ( )
{
ViewMatrix = Matrix . CreateLookAt ( position , lookAt , upDirection ) ;
2019-03-10 06:46:28 +00:00
worldMatrix * = Matrix . CreateScale ( worldScale ) ;
2019-02-25 04:44:02 +00:00
2019-03-24 00:04:43 +00:00
if ( basicEffect ! = null )
{
basicEffect . World = worldMatrix ;
basicEffect . Projection = projectionMatrix ;
basicEffect . View = ViewMatrix ;
}
2019-02-06 06:11:22 +00:00
}
/// <summary>
2019-02-11 05:28:48 +00:00
/// Moves camera by the given amount.
2019-02-06 06:11:22 +00:00
/// </summary>
2019-02-11 05:28:48 +00:00
/// <param name="move">A <see cref="Vector3"/> that contains how much in each direction to move.</param>
public void MoveCamera ( Vector3 move )
2019-02-06 06:11:22 +00:00
{
2019-02-11 05:28:48 +00:00
position + = move ;
Apply ( ) ;
2019-02-06 06:11:22 +00:00
}
}
}