BARE2D
BARE2D::Camera2D Class Reference

The basic camera for a 2D world. There are two spaces - the Worldspace and the Viewspace. The Worldspace is standard for all cameras, it is the 'gameworld' space. The Viewspace is the subspace of the worldspace. It is what the camera captures. Scale is zoom factor. NOT resolution scalar. More...

#include <Camera2D.hpp>

+ Collaboration diagram for BARE2D::Camera2D:

Public Member Functions

 Camera2D ()
 
 ~Camera2D ()
 
void init (float screenWidth, float screenHeight)
 Initializes the camera. More...
 
void update ()
 Updates the matrix if necessary. More...
 
glm::vec2 getWorldspaceCoord (glm::vec2 pos) const
 Converts a coordinate from Worldspace to Viewspace. More...
 
glm::vec2 getViewspaceCoord (glm::vec2 pos) const
 Converts a coordinate from Worldspace to Viewspace. More...
 
glm::vec2 getWorldspaceSize (glm::vec2 size) const
 
glm::vec2 getViewspaceSize (glm::vec2 size) const
 
glm::vec4 getWorldspaceRect (glm::vec4 destRect) const
 
glm::vec4 getViewspaceRect (glm::vec4 destRect) const
 
void setFocus (glm::vec2 newFocus)
 Sets the center of the camera to newFocus. More...
 
void offsetFocus (glm::vec2 deltaPos)
 Moves the center of the camera to focus + deltaPos. More...
 
void setScale (float newScaleX, float newScaleY)
 Sets the scale of the camera. More...
 
void offsetScale (float deltaScaleX, float deltaScaleY)
 Adds to the zoom factor of the camera. More...
 
glm::vec2 getViewspaceResolution () const
 
glm::vec2 getFocus () const
 
glm::vec2 getStatePosition () const
 
glm::vec2 getScale () const
 
const glm::mat4 & getCameraMatrix () const
 
bool isRectInViewspace (glm::vec4 &destRect) const
 
CameraState getState ()
 
CameraState getLastState ()
 

Private Attributes

glm::vec2 m_resolution
 
CameraState m_state
 
CameraState m_lastState
 
glm::mat4 m_cameraMatrix
 
glm::mat4 m_orthographicMatrix
 
bool m_matrixNeedsUpdate = false
 

Detailed Description

The basic camera for a 2D world. There are two spaces - the Worldspace and the Viewspace. The Worldspace is standard for all cameras, it is the 'gameworld' space. The Viewspace is the subspace of the worldspace. It is what the camera captures. Scale is zoom factor. NOT resolution scalar.

Definition at line 23 of file Camera2D.hpp.

Constructor & Destructor Documentation

◆ Camera2D()

BARE2D::Camera2D::Camera2D ( )

Definition at line 9 of file Camera2D.cpp.

◆ ~Camera2D()

BARE2D::Camera2D::~Camera2D ( )

Definition at line 14 of file Camera2D.cpp.

Member Function Documentation

◆ getCameraMatrix()

const glm::mat4 & BARE2D::Camera2D::getCameraMatrix ( ) const
Returns
The camera matrix.

Definition at line 169 of file Camera2D.cpp.

References m_cameraMatrix.

◆ getFocus()

glm::vec2 BARE2D::Camera2D::getFocus ( ) const
Returns
The camera focus

Definition at line 161 of file Camera2D.cpp.

References BARE2D::CameraState::focus, and m_state.

◆ getLastState()

CameraState BARE2D::Camera2D::getLastState ( )
Returns
The camera's last state before modification of the current state.

Definition at line 181 of file Camera2D.cpp.

References m_lastState.

◆ getScale()

glm::vec2 BARE2D::Camera2D::getScale ( ) const
Returns
The zoom levels

Definition at line 165 of file Camera2D.cpp.

References m_state, and BARE2D::CameraState::scale.

◆ getState()

CameraState BARE2D::Camera2D::getState ( )
Returns
The camera's current state.

Definition at line 177 of file Camera2D.cpp.

References m_state.

◆ getStatePosition()

glm::vec2 BARE2D::Camera2D::getStatePosition ( ) const
Returns
The camera's bottom-left position.

Definition at line 185 of file Camera2D.cpp.

References BARE2D::CameraState::focus, m_resolution, m_state, and BARE2D::CameraState::scale.

Referenced by getViewspaceCoord(), and getWorldspaceCoord().

+ Here is the caller graph for this function:

◆ getViewspaceCoord()

glm::vec2 BARE2D::Camera2D::getViewspaceCoord ( glm::vec2  pos) const

Converts a coordinate from Worldspace to Viewspace.

Parameters
posA point in Worldspace
Returns
The converted point in Viewspace.

Definition at line 74 of file Camera2D.cpp.

References getStatePosition(), m_state, and BARE2D::CameraState::scale.

Referenced by getViewspaceRect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getViewspaceRect()

glm::vec4 BARE2D::Camera2D::getViewspaceRect ( glm::vec4  destRect) const
Returns
The Viewspace rectangle (dest/rect) from a Worldspace rectangle (dest/rect)

Definition at line 113 of file Camera2D.cpp.

References getViewspaceCoord(), and getViewspaceSize().

+ Here is the call graph for this function:

◆ getViewspaceResolution()

glm::vec2 BARE2D::Camera2D::getViewspaceResolution ( ) const
Returns
The POV size

Definition at line 157 of file Camera2D.cpp.

References m_resolution.

◆ getViewspaceSize()

glm::vec2 BARE2D::Camera2D::getViewspaceSize ( glm::vec2  size) const
Returns
The Viewspace size from a Worldspace size

Definition at line 95 of file Camera2D.cpp.

References m_state, and BARE2D::CameraState::scale.

Referenced by getViewspaceRect().

+ Here is the caller graph for this function:

◆ getWorldspaceCoord()

glm::vec2 BARE2D::Camera2D::getWorldspaceCoord ( glm::vec2  pos) const

Converts a coordinate from Worldspace to Viewspace.

Parameters
posA point in Viewspace
Returns
The converted point in Worldspace.

Definition at line 62 of file Camera2D.cpp.

References getStatePosition(), m_state, and BARE2D::CameraState::scale.

Referenced by getWorldspaceRect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getWorldspaceRect()

glm::vec4 BARE2D::Camera2D::getWorldspaceRect ( glm::vec4  destRect) const
Returns
The Worldspace rectangle (dest/rect) from a Viewspace rectangle (dest/rect)

Definition at line 103 of file Camera2D.cpp.

References getWorldspaceCoord(), and getWorldspaceSize().

+ Here is the call graph for this function:

◆ getWorldspaceSize()

glm::vec2 BARE2D::Camera2D::getWorldspaceSize ( glm::vec2  size) const
Returns
The Worldspace size from a Viewspace size

Definition at line 87 of file Camera2D.cpp.

References m_state, and BARE2D::CameraState::scale.

Referenced by getWorldspaceRect().

+ Here is the caller graph for this function:

◆ init()

void BARE2D::Camera2D::init ( float  screenWidth,
float  screenHeight 
)

Initializes the camera.

Parameters
screenWidthThe width of the screen or FBO the camera needs to transform things within. The 'visual field'
screenHeightThe height of the screen or FBO the camera needs to transform things within. The 'visual field'

Definition at line 17 of file Camera2D.cpp.

References BARE2D::CameraState::focus, m_cameraMatrix, m_lastState, m_matrixNeedsUpdate, m_orthographicMatrix, m_resolution, m_state, and BARE2D::CameraState::scale.

◆ isRectInViewspace()

bool BARE2D::Camera2D::isRectInViewspace ( glm::vec4 &  destRect) const

Definition at line 173 of file Camera2D.cpp.

◆ offsetFocus()

void BARE2D::Camera2D::offsetFocus ( glm::vec2  deltaPos)

Moves the center of the camera to focus + deltaPos.

Parameters
deltaPosThe change to move by

Definition at line 131 of file Camera2D.cpp.

References BARE2D::CameraState::focus, m_lastState, m_matrixNeedsUpdate, and m_state.

◆ offsetScale()

void BARE2D::Camera2D::offsetScale ( float  deltaScaleX,
float  deltaScaleY 
)

Adds to the zoom factor of the camera.

Parameters
deltaScaleXThe x direction
deltaScaleYThe y direction

Definition at line 148 of file Camera2D.cpp.

References m_lastState, m_matrixNeedsUpdate, m_state, and BARE2D::CameraState::scale.

◆ setFocus()

void BARE2D::Camera2D::setFocus ( glm::vec2  newFocus)

Sets the center of the camera to newFocus.

Parameters
newFocusThe position to set the center of the camera to

Definition at line 123 of file Camera2D.cpp.

References BARE2D::CameraState::focus, m_lastState, m_matrixNeedsUpdate, and m_state.

◆ setScale()

void BARE2D::Camera2D::setScale ( float  newScaleX,
float  newScaleY 
)

Sets the scale of the camera.

Parameters
newScaleXThe scale to set ot
newScaleYThe scale to set ot

Definition at line 139 of file Camera2D.cpp.

References m_lastState, m_matrixNeedsUpdate, m_state, and BARE2D::CameraState::scale.

◆ update()

void BARE2D::Camera2D::update ( )

Updates the matrix if necessary.

Definition at line 35 of file Camera2D.cpp.

References BARE2D::CameraState::focus, m_cameraMatrix, m_matrixNeedsUpdate, m_orthographicMatrix, m_resolution, m_state, and BARE2D::CameraState::scale.

Field Documentation

◆ m_cameraMatrix

glm::mat4 BARE2D::Camera2D::m_cameraMatrix
private

Definition at line 145 of file Camera2D.hpp.

Referenced by getCameraMatrix(), init(), and update().

◆ m_lastState

CameraState BARE2D::Camera2D::m_lastState
private

Definition at line 142 of file Camera2D.hpp.

Referenced by getLastState(), init(), offsetFocus(), offsetScale(), setFocus(), and setScale().

◆ m_matrixNeedsUpdate

bool BARE2D::Camera2D::m_matrixNeedsUpdate = false
private

Definition at line 147 of file Camera2D.hpp.

Referenced by init(), offsetFocus(), offsetScale(), setFocus(), setScale(), and update().

◆ m_orthographicMatrix

glm::mat4 BARE2D::Camera2D::m_orthographicMatrix
private

Definition at line 145 of file Camera2D.hpp.

Referenced by init(), and update().

◆ m_resolution

glm::vec2 BARE2D::Camera2D::m_resolution
private

Definition at line 138 of file Camera2D.hpp.

Referenced by getStatePosition(), getViewspaceResolution(), init(), and update().

◆ m_state


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