using OpenTK; namespace RecrownedAthenaeum.Graphics.Render { /// /// A generic camera. Functions in 3D. /// public class BasicCamera { /// /// The scale for the world. /// public float worldScale = 1f; /// /// Current position in the world. /// public Vector3 position; /// /// The place the 3D camera is looking at. /// public Vector3 lookAt; /// /// The direction up is for the camera. /// public Vector3 upDirection; /// /// The transform matrix representing the world (rotation and translations of the original world). /// public Matrix3 worldMatrix; /// /// The view matrix that describes where the camera looks. /// public Matrix3 ViewMatrix { get; protected set; } /// /// The projection matrix. /// public Matrix3 projectionMatrix; /// /// A basic effect that will be updated with the correct matrice information everytime is called. Can be null and thus will not be used. /// public BasicEffect basicEffect; /// /// Constructs 3D camera with an orthographic projection matrix with dimensions of graphics devices viewport. All changes to matrices should have apply called after changes. /// /// A basic effect that will be updated with the correct matrice information everytime is called. Can be null and thus will not be used. public BasicCamera(BasicEffect basicEffect = null) { worldMatrix = Matrix.Identity; lookAt = Vector3.Forward; upDirection = Vector3.Up; projectionMatrix = Matrix.Identity; this.basicEffect = basicEffect; Apply(); } /// /// Applies the changes to the fields and properties of the camera. /// public virtual void Apply() { ViewMatrix = Matrix.CreateLookAt(position, lookAt, upDirection); worldMatrix *= Matrix.CreateScale(worldScale); if (basicEffect != null) { basicEffect.World = worldMatrix; basicEffect.Projection = projectionMatrix; basicEffect.View = ViewMatrix; } } /// /// Moves camera by the given amount. /// /// A that contains how much in each direction to move. public void MoveCamera(Vector3 move) { position += move; Apply(); } } }