Camera2D now tested to work. Probably.
This commit is contained in:
parent
751bdd72e8
commit
56eb4e9e7f
@ -15,13 +15,30 @@ namespace RecrownedAthenaeum.Camera
|
||||
/// </summary>
|
||||
public Vector2 Position { get { return new Vector2(position.X, position.Y); } set { position.X = value.X; position.Y = value.Y; } }
|
||||
|
||||
/// <summary>
|
||||
/// Places camera in the center given the corner position.
|
||||
/// </summary>
|
||||
public Vector2 CenterPosition { set { position.X = value.X + graphicsDevice.Viewport.Width / 2f; position.Y = value.Y + graphicsDevice.Viewport.Height / 2f; } }
|
||||
|
||||
/// <summary>
|
||||
/// A 2D camera from the generic <see cref="Camera3D"/>.
|
||||
/// </summary>
|
||||
/// <param name="graphicsDevice">The graphics device to use if not using the one in <see cref="Configuration"/>.</param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies for 2D.
|
||||
/// Sets where the camera is looking for the view matrix to the position of the camera.
|
||||
/// </summary>
|
||||
public override void Apply()
|
||||
{
|
||||
lookAt = new Vector3(Position, 1f);
|
||||
base.Apply();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -38,13 +55,18 @@ namespace RecrownedAthenaeum.Camera
|
||||
distance *= (float)(1.0f - Math.Pow(1 - alpha, delta / 0.02f));
|
||||
|
||||
Position += distance;
|
||||
|
||||
Apply();
|
||||
}
|
||||
|
||||
private Matrix BasicOrthographic()
|
||||
/// <summary>
|
||||
/// Moves the camera.
|
||||
/// Apply needs to be called.
|
||||
/// </summary>
|
||||
/// <param name="move">Magnitude of how much to move per axis.</param>
|
||||
public void MoveCamera(Vector2 move)
|
||||
{
|
||||
return Matrix.CreateOrthographic(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 1);
|
||||
Console.WriteLine(move);
|
||||
Position += move;
|
||||
Console.WriteLine(Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Centers the camera to middle of width and height of game window.
|
||||
/// Moves camera by the given amount.
|
||||
/// </summary>
|
||||
public void Center()
|
||||
/// <param name="move">A <see cref="Vector3"/> that contains how much in each direction to move.</param>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user