Added documentation to Camera2D class
This commit is contained in:
@@ -21,7 +21,6 @@ namespace CaveGame::Client
|
||||
/// The default constructor does not initialize any values.
|
||||
Camera2D();
|
||||
|
||||
|
||||
/// Performs one iteration of the camera's internal logic.
|
||||
/// @param elapsed The delta-time (in seconds) between this iteration and the last.
|
||||
void Update(float elapsed);
|
||||
@@ -46,11 +45,16 @@ namespace CaveGame::Client
|
||||
/// Sets the amount of zoom in the camera transformation.
|
||||
void Zoom(float val);
|
||||
|
||||
/// Enables free camera movement controls.
|
||||
void SetFreeCam(bool freeCam);
|
||||
|
||||
/// Returns whether free camera controls are enabled.
|
||||
bool GetFreeCam() const;
|
||||
|
||||
/// Zooms the camera in by the given amount.
|
||||
void ZoomIn(float amt);
|
||||
|
||||
/// Zooms the camera out by the given amount.
|
||||
void ZoomOut(float amt);
|
||||
|
||||
/// Returns the amount of rotation (in degrees) in the camera transformation.
|
||||
@@ -62,13 +66,10 @@ namespace CaveGame::Client
|
||||
/// Rotates the camera by the given amount (in degrees).
|
||||
void Rotate(float angles);
|
||||
|
||||
Vector2 ScreenCenterPosition() const;
|
||||
Vector2 ScreenTopLeftPosition() const;
|
||||
Vector2 ScreenToWorld(const Vector2& device_coordinates) const
|
||||
{
|
||||
Vector2 pos = ScaledTopLeft() + (device_coordinates/zoom);
|
||||
return pos;
|
||||
}
|
||||
/// Converts top-left origin screen coordinates into world-space coordinates, with respect to zoom scale.
|
||||
Vector2 ScreenToWorld(const Vector2& device_coordinates) const;
|
||||
|
||||
/// Converts world-space coordinates into top-left origin screen coordinates, with respect to zoom scale.
|
||||
Vector2 WorldToScreen(const Vector2& position) const;
|
||||
|
||||
/// Returns the current cartesian coordinates of the camera transformation.
|
||||
@@ -98,10 +99,15 @@ namespace CaveGame::Client
|
||||
|
||||
/// Returns the gameworld-coordinates at the top-left of the screen, with scaling taken into account.
|
||||
[[nodiscard]] Vector2 ScaledTopLeft() const;
|
||||
|
||||
/// Returns the world-space coordinates at the focal point of the camera. Generally, this should also be the
|
||||
/// world-space coordinates of the center of the screen.
|
||||
[[nodiscard]] Vector2 Center() const;
|
||||
|
||||
/// Returns the "radius" of the viewport. (size / 2.f)
|
||||
[[nodiscard]] Vector2 HalfSizeOffset() const;
|
||||
|
||||
/// Returns the "radius" of the viewport, scaled by the camera zoom.
|
||||
[[nodiscard]] Vector2 ScaledHalfSizeOffset() const;
|
||||
|
||||
/// Returns the base movement speed of the camera.
|
||||
@@ -110,7 +116,7 @@ namespace CaveGame::Client
|
||||
/// Sets the base movement speed of the camera.
|
||||
void MoveSpeed(float value);
|
||||
protected:
|
||||
// Process user-input for freecam.
|
||||
/// Process user-input for freecam.
|
||||
void UpdateFreecamControls(float delta);
|
||||
protected:
|
||||
Vector2 velocity;
|
||||
|
@@ -9,7 +9,6 @@ namespace CaveGame::Client
|
||||
|
||||
void Camera2D::UpdateFreecamControls(float elapsed)
|
||||
{
|
||||
|
||||
// TODO: implement freecam panning via mouse.
|
||||
|
||||
if (InputService::IsKeyDown(Keys::LeftArrow))
|
||||
@@ -89,6 +88,11 @@ namespace CaveGame::Client
|
||||
|
||||
void Camera2D::Rotate(float angles) { rotation+=angles;}
|
||||
|
||||
Vector2 Camera2D::ScreenToWorld(const Vector2 &device_coordinates) const {
|
||||
Vector2 pos = ScaledTopLeft() + (device_coordinates/zoom);
|
||||
return pos;
|
||||
}
|
||||
|
||||
Vector2 Camera2D::Position() const { return position; }
|
||||
|
||||
void Camera2D::MoveLeft(float rate) {
|
||||
|
Reference in New Issue
Block a user