ASGE
3.2.0
Simple Game Framework in GL
|
#include <Camera.hpp>
Classes | |
struct | CameraView |
Public Types | |
using | Translation = std::array< float, 3 > |
Public Member Functions | |
Camera ()=default | |
Camera (float width, float height) | |
Camera (Point2D focal_point, float width, float height) | |
virtual | ~Camera ()=default |
void | lookAt (Point2D focal_point) |
virtual void | update (const ASGE::GameTime &game_time) |
virtual void | translate (float x, float y, float z) |
virtual void | translateX (float x) |
virtual void | translateY (float y) |
virtual void | translateZ (float zoom) |
void | setZoom (float zoom) |
void | resize (float width, float height) |
CameraView | getView () const |
float | getZoom () const |
const ASGE::Point2D & | position () const |
void | clamp (const CameraView &) |
A 2D orthogonal camera class.
The Camera class is designed as a simple way to alter the view being drawn to the screen. The view described by the camera will be scaled to the viewport, so it is recommend to size it identically to the viewport or to at least use the same aspect ratio to prevent scaling artifacts. This basic implementation provides translation in the X and Y axis and use of Z to control the zoom level of the camera. In order to apply a translation to the camera, the translate function must be called. The default implementation is to move the camera by the requested translation amount.There is no damping or smoothing applied. If this is required, the class should be inherited from and the update function overridden.
Usage:
Definition at line 54 of file Camera.hpp.
|
default |
Default constructor with no predefined view.
ASGE::Camera::Camera | ( | float | width, |
float | height | ||
) |
Constructs the camera and sets the view width and height.
Whilst the camera view's width and height will be set, it assumed that the camera will be looking at {0,0}. This is considered the center of the camera's view and is analogous to its focal point. The final view will be sized accordingly i.e. {-width, width} and {-height, height}.
[in] | width | The width of the camera's view. |
[in] | height | The height of the camera's view. |
ASGE::Camera::Camera | ( | Point2D | focal_point, |
float | width, | ||
float | height | ||
) |
Constructs a camera, with a focal point and a view size.
These parameters will dictate where the camera is looking and how much of the scene it will show. It's important to note that the focal point of a camera is the middle of it's view, not the top left (0,0) i.e. {-width, width} and {-height, height}.
[in] | focal_point | The camera's focal point. |
[in] | width | The width of the camera's view. |
[in] | height | The height of the camera's view. |
|
virtualdefault |
Default destructor.
void ASGE::Camera::clamp | ( | const CameraView & | ) |
Clamps the camera view.
It is often desirable to clamp the field of vision for the camera to ensure only specific regions of the game screen are shown. Consider a tile map where the camera should not exceed the width or height of the map. This function can be used to clamp the view to a set of predefined values, representing min_x
, max_x
, min_y
and max_y
. These would then be used to simply clamp the view's x and y positions.
[in] | view_bounds | The four bounds to use in xy space. |
CameraView ASGE::Camera::getView | ( | ) | const |
A view that describes the camera's framing.
Use this to frame the action, which in turn is rendered to the window. This view can be used directly to control the projection matrix used for mapping to the game window. Everything inside the view will be mapped directly to the screens viewport. The bounding volume controls the depth of items rendered.
float ASGE::Camera::getZoom | ( | ) | const |
Retrieves the current zoom level for the camera.
void ASGE::Camera::lookAt | ( | Point2D | focal_point | ) |
Set's the camera's focal point.
focal_point | The new center point of the camera's view. |
const ASGE::Point2D& ASGE::Camera::position | ( | ) | const |
Retrieves the camera's current position on the XY axis.
void ASGE::Camera::resize | ( | float | width, |
float | height | ||
) |
Resizes the camera's view.
[in] | width | The new width of the camera's view. |
[in] | height | The new height of the camera's view. |
void ASGE::Camera::setZoom | ( | float | zoom | ) |
Adjust the camera's zoom.
[in] | zoom | The amount to adjust the zoom by. |
|
virtual |
Adds a translation amount in all three axis.
The translation is not applied until the update function is called. You can think of the translation vector applied to the camera's movement.
[in] | x | The amount to move in the x axis. |
[in] | y | The amount to move in the y axis. |
[in] | z | The amount of zoom to apply. |
|
virtual |
Moves the camera's view in the x axis.
[in] | x | The amount to translate the view by. |
|
virtual |
Moves the camera's view in the y axis.
[in] | y | The amount to translate the view by. |
|
virtual |
Adjust the camera's zoom.
[in] | zoom | The amount to adjust the zoom by. |
|
virtual |
Does nothing.
Override this function if you wish to add more complex behaviours such as smoothing and delta-time related animations to the camera's movement.
[in] | game_time | The game's duration and the frame time delta. |