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 |
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.
| BARE2D::Camera2D::Camera2D | ( | ) |
Definition at line 9 of file Camera2D.cpp.
| BARE2D::Camera2D::~Camera2D | ( | ) |
Definition at line 14 of file Camera2D.cpp.
| const glm::mat4 & BARE2D::Camera2D::getCameraMatrix | ( | ) | const |
| glm::vec2 BARE2D::Camera2D::getFocus | ( | ) | const |
Definition at line 161 of file Camera2D.cpp.
References BARE2D::CameraState::focus, and m_state.
| CameraState BARE2D::Camera2D::getLastState | ( | ) |
Definition at line 181 of file Camera2D.cpp.
References m_lastState.
| glm::vec2 BARE2D::Camera2D::getScale | ( | ) | const |
Definition at line 165 of file Camera2D.cpp.
References m_state, and BARE2D::CameraState::scale.
| CameraState BARE2D::Camera2D::getState | ( | ) |
| glm::vec2 BARE2D::Camera2D::getStatePosition | ( | ) | const |
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:| glm::vec2 BARE2D::Camera2D::getViewspaceCoord | ( | glm::vec2 | pos | ) | const |
Converts a coordinate from Worldspace to Viewspace.
| pos | A point in Worldspace |
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:| glm::vec4 BARE2D::Camera2D::getViewspaceRect | ( | glm::vec4 | destRect | ) | const |
Definition at line 113 of file Camera2D.cpp.
References getViewspaceCoord(), and getViewspaceSize().
Here is the call graph for this function:| glm::vec2 BARE2D::Camera2D::getViewspaceResolution | ( | ) | const |
| glm::vec2 BARE2D::Camera2D::getViewspaceSize | ( | glm::vec2 | size | ) | const |
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:| glm::vec2 BARE2D::Camera2D::getWorldspaceCoord | ( | glm::vec2 | pos | ) | const |
Converts a coordinate from Worldspace to Viewspace.
| pos | A point in Viewspace |
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:| glm::vec4 BARE2D::Camera2D::getWorldspaceRect | ( | glm::vec4 | destRect | ) | const |
Definition at line 103 of file Camera2D.cpp.
References getWorldspaceCoord(), and getWorldspaceSize().
Here is the call graph for this function:| glm::vec2 BARE2D::Camera2D::getWorldspaceSize | ( | glm::vec2 | size | ) | const |
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:| void BARE2D::Camera2D::init | ( | float | screenWidth, |
| float | screenHeight | ||
| ) |
Initializes the camera.
| screenWidth | The width of the screen or FBO the camera needs to transform things within. The 'visual field' |
| screenHeight | The 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.
| bool BARE2D::Camera2D::isRectInViewspace | ( | glm::vec4 & | destRect | ) | const |
Definition at line 173 of file Camera2D.cpp.
| void BARE2D::Camera2D::offsetFocus | ( | glm::vec2 | deltaPos | ) |
Moves the center of the camera to focus + deltaPos.
| deltaPos | The change to move by |
Definition at line 131 of file Camera2D.cpp.
References BARE2D::CameraState::focus, m_lastState, m_matrixNeedsUpdate, and m_state.
| void BARE2D::Camera2D::offsetScale | ( | float | deltaScaleX, |
| float | deltaScaleY | ||
| ) |
Adds to the zoom factor of the camera.
| deltaScaleX | The x direction |
| deltaScaleY | The y direction |
Definition at line 148 of file Camera2D.cpp.
References m_lastState, m_matrixNeedsUpdate, m_state, and BARE2D::CameraState::scale.
| void BARE2D::Camera2D::setFocus | ( | glm::vec2 | newFocus | ) |
Sets the center of the camera to newFocus.
| newFocus | The 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.
| void BARE2D::Camera2D::setScale | ( | float | newScaleX, |
| float | newScaleY | ||
| ) |
Sets the scale of the camera.
| newScaleX | The scale to set ot |
| newScaleY | The scale to set ot |
Definition at line 139 of file Camera2D.cpp.
References m_lastState, m_matrixNeedsUpdate, m_state, and BARE2D::CameraState::scale.
| 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.
|
private |
Definition at line 145 of file Camera2D.hpp.
Referenced by getCameraMatrix(), init(), and update().
|
private |
Definition at line 142 of file Camera2D.hpp.
Referenced by getLastState(), init(), offsetFocus(), offsetScale(), setFocus(), and setScale().
|
private |
Definition at line 147 of file Camera2D.hpp.
Referenced by init(), offsetFocus(), offsetScale(), setFocus(), setScale(), and update().
|
private |
Definition at line 145 of file Camera2D.hpp.
|
private |
Definition at line 138 of file Camera2D.hpp.
Referenced by getStatePosition(), getViewspaceResolution(), init(), and update().
|
private |
Definition at line 140 of file Camera2D.hpp.
Referenced by getFocus(), getScale(), getState(), getStatePosition(), getViewspaceCoord(), getViewspaceSize(), getWorldspaceCoord(), getWorldspaceSize(), init(), offsetFocus(), offsetScale(), setFocus(), setScale(), and update().