diff --git a/RecrownedAthenaeum/Camera/Camera2D.cs b/RecrownedAthenaeum/Camera/Camera2D.cs index f5d93ef..accdf24 100644 --- a/RecrownedAthenaeum/Camera/Camera2D.cs +++ b/RecrownedAthenaeum/Camera/Camera2D.cs @@ -15,13 +15,30 @@ namespace RecrownedAthenaeum.Camera /// public Vector2 Position { get { return new Vector2(position.X, position.Y); } set { position.X = value.X; position.Y = value.Y; } } + /// + /// Places camera in the center given the corner position. + /// + public Vector2 CenterPosition { set { position.X = value.X + graphicsDevice.Viewport.Width / 2f; position.Y = value.Y + graphicsDevice.Viewport.Height / 2f; } } + /// /// A 2D camera from the generic . /// /// The graphics device to use if not using the one in . public Camera2D(GraphicsDevice graphicsDevice = null) : base(graphicsDevice) { + projectionMatrix = Matrix.CreateOrthographic(this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, 1); + CenterPosition = new Vector2(0, 0); + Apply(); + } + /// + /// Applies for 2D. + /// Sets where the camera is looking for the view matrix to the position of the camera. + /// + public override void Apply() + { + lookAt = new Vector3(Position, 1f); + base.Apply(); } /// @@ -38,13 +55,18 @@ namespace RecrownedAthenaeum.Camera distance *= (float)(1.0f - Math.Pow(1 - alpha, delta / 0.02f)); Position += distance; - - Apply(); } - private Matrix BasicOrthographic() + /// + /// Moves the camera. + /// Apply needs to be called. + /// + /// Magnitude of how much to move per axis. + public void MoveCamera(Vector2 move) { - return Matrix.CreateOrthographic(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 1); + Console.WriteLine(move); + Position += move; + Console.WriteLine(Position); } } } diff --git a/RecrownedAthenaeum/Camera/Camera3D.cs b/RecrownedAthenaeum/Camera/Camera3D.cs index b2d8f96..9651f7a 100644 --- a/RecrownedAthenaeum/Camera/Camera3D.cs +++ b/RecrownedAthenaeum/Camera/Camera3D.cs @@ -64,8 +64,9 @@ namespace RecrownedAthenaeum.Camera worldMatrix = Matrix.Identity; lookAt = Vector3.Forward; upDirection = Vector3.Up; - Center(); - projectionMatrix = Matrix.CreateOrthographic(this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, 1); + + GraphicsDevice gDevice = this.graphicsDevice; + projectionMatrix = Matrix.Identity; Apply(); } @@ -75,17 +76,17 @@ namespace RecrownedAthenaeum.Camera public virtual void Apply() { ViewMatrix = Matrix.CreateLookAt(position, lookAt, upDirection); - TransformationMatrix = projectionMatrix * ViewMatrix * worldMatrix; + TransformationMatrix = worldMatrix * ViewMatrix * projectionMatrix; } /// - /// Centers the camera to middle of width and height of game window. + /// Moves camera by the given amount. /// - public void Center() + /// A that contains how much in each direction to move. + public void MoveCamera(Vector3 move) { - position.Z = 0; - position.X = this.graphicsDevice.Viewport.Width * 0.5f; - position.Y = this.graphicsDevice.Viewport.Height * 0.5f; + position += move; + Apply(); } } }