ASGE  3.2.0
Simple Game Framework in GL
ASGE::Camera Class Reference

#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::Point2Dposition () const
 
void clamp (const CameraView &)
 

Detailed Description

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.

Physically Based Rendering: From Theory To Implementation, © 2004-2019 Matt Pharr, Wenzel Jakob, and Greg Humphreys

Usage:

ASGE::Camera camera {1024, 768};
camera.translateY(-2048 * gt.deltaInSecs());
camera.update(gt);
renderer->setProjectionMatrix(camera.getView());
A 2D orthogonal camera class.
Definition: Camera.hpp:55
virtual void translateY(float y)

Definition at line 54 of file Camera.hpp.

Constructor & Destructor Documentation

◆ Camera() [1/3]

ASGE::Camera::Camera ( )
default

Default constructor with no predefined view.

Note
Not providing a view will result in nothing being rendered.

◆ Camera() [2/3]

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}.

Parameters
[in]widthThe width of the camera's view.
[in]heightThe height of the camera's view.

◆ Camera() [3/3]

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}.

Parameters
[in]focal_pointThe camera's focal point.
[in]widthThe width of the camera's view.
[in]heightThe height of the camera's view.

◆ ~Camera()

virtual ASGE::Camera::~Camera ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ clamp()

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.

Parameters
[in]view_boundsThe four bounds to use in xy space.

◆ getView()

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.

Returns
ASGE::Camera::CameraView
Physically Based Rendering: From Theory To Implementation, © 2004-2019 Matt Pharr, Wenzel Jakob, and Greg Humphreys

◆ getZoom()

float ASGE::Camera::getZoom ( ) const

Retrieves the current zoom level for the camera.

Returns
The camera's zoom.

◆ lookAt()

void ASGE::Camera::lookAt ( Point2D  focal_point)

Set's the camera's focal point.

Parameters
focal_pointThe new center point of the camera's view.
See also
ASGE::Point2D

◆ position()

const ASGE::Point2D& ASGE::Camera::position ( ) const

Retrieves the camera's current position on the XY axis.

Returns
The camera's position.

◆ resize()

void ASGE::Camera::resize ( float  width,
float  height 
)

Resizes the camera's view.

Note
This does not maintain the aspect ratio of the camera.
Parameters
[in]widthThe new width of the camera's view.
[in]heightThe new height of the camera's view.

◆ setZoom()

void ASGE::Camera::setZoom ( float  zoom)

Adjust the camera's zoom.

Parameters
[in]zoomThe amount to adjust the zoom by.

◆ translate()

virtual void ASGE::Camera::translate ( float  x,
float  y,
float  z 
)
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.

Parameters
[in]xThe amount to move in the x axis.
[in]yThe amount to move in the y axis.
[in]zThe amount of zoom to apply.

◆ translateX()

virtual void ASGE::Camera::translateX ( float  x)
virtual

Moves the camera's view in the x axis.

Parameters
[in]xThe amount to translate the view by.

◆ translateY()

virtual void ASGE::Camera::translateY ( float  y)
virtual

Moves the camera's view in the y axis.

Parameters
[in]yThe amount to translate the view by.

◆ translateZ()

virtual void ASGE::Camera::translateZ ( float  zoom)
virtual

Adjust the camera's zoom.

Parameters
[in]zoomThe amount to adjust the zoom by.

◆ update()

virtual void ASGE::Camera::update ( const ASGE::GameTime game_time)
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.

Parameters
[in]game_timeThe game's duration and the frame time delta.

The documentation for this class was generated from the following file: