![]() |
Divide Framework 0.1
A free and open-source 3D Framework under heavy development
|
#include <Camera.h>
Public Types | |
enum class | Mode : U8 { FREE_FLY = 0 , STATIC , FIRST_PERSON , THIRD_PERSON , ORBIT , SCRIPTED , COUNT } |
enum class | UtilityCamera : U8 { _2D = 0 , _2D_FLIP_Y , DEFAULT , CUBE , DUAL_PARABOLOID , COUNT } |
Public Member Functions | |
Camera (const std::string_view name, Mode mode, const vec3< F32 > &eye=VECTOR3_ZERO) | |
void | fromCamera (const Camera &camera) |
Copies all of the internal data from the specified camera to the current one. | |
void | fromSnapshot (const CameraSnapshot &snapshot) |
Sets the internal snapshot data (eye, orientation, etc) to match the specified value. | |
bool | updateLookAt () |
Return true if the cached camera state wasn't up-to-date. | |
void | setReflection (const Plane< F32 > &reflectionPlane) noexcept |
Specify a reflection plane that alters the final view matrix to be a mirror of the internal lookAt matrix. | |
void | clearReflection () noexcept |
Clears the reflection plane specified (if any) | |
void | setGlobalRotation (F32 yaw, F32 pitch, F32 roll=0.0f) noexcept |
Global rotations are applied relative to the world axis, not the camera's. | |
void | setGlobalRotation (const vec3< Angle::DEGREES< F32 > > &euler) noexcept |
Global rotations are applied relative to the world axis, not the camera's. | |
const mat4< F32 > & | lookAt (const mat4< F32 > &viewMatrix) |
Sets the camera's view matrix to specify the specified value by extracting the eye position, orientation and other data from it. | |
const mat4< F32 > & | lookAt (const vec3< F32 > &eye, const vec3< F32 > &target, const vec3< F32 > &up) |
Sets the camera's position, target and up directions. | |
const mat4< F32 > & | lookAt (const vec3< F32 > &target) |
Sets the camera to point at the specified target point. | |
const mat4< F32 > & | lookAt (const vec3< F32 > &eye, const vec3< F32 > &target) |
Sets the camera to point at the specified target point from the specified eye position. | |
void | setYaw (const Angle::DEGREES< F32 > angle) noexcept |
void | setPitch (const Angle::DEGREES< F32 > angle) noexcept |
Sets the camera's Pitch angle. Yaw and Roll are previous extracted values. | |
void | setRoll (const Angle::DEGREES< F32 > angle) noexcept |
Sets the camera's Roll angle. Yaw and Pitch are previous extracted values. | |
void | setGlobalYaw (const Angle::DEGREES< F32 > angle) noexcept |
void | setGlobalPitch (const Angle::DEGREES< F32 > angle) noexcept |
Sets the camera's Pitch angle. Yaw and Roll are previous extracted values. | |
void | setGlobalRoll (const Angle::DEGREES< F32 > angle) noexcept |
Sets the camera's Roll angle. Yaw and Pitch are previous extracted values. | |
void | setEye (const F32 x, const F32 y, const F32 z) noexcept |
Sets the camera's eye position. | |
void | setEye (const vec3< F32 > &position) noexcept |
Sets the camera's eye position. | |
void | setRotation (const Quaternion< F32 > &q) noexcept |
Sets the camera's orientation. | |
void | setRotation (const Angle::DEGREES< F32 > yaw, const Angle::DEGREES< F32 > pitch, const Angle::DEGREES< F32 > roll=0.0f) noexcept |
Sets the camera's orientation. | |
void | rotate (const Quaternion< F32 > &q) |
Rotates the camera (changes its orientation) by the specified quaternion (_orientation *= q) | |
void | rotate (Angle::DEGREES< F32 > yaw, Angle::DEGREES< F32 > pitch, Angle::DEGREES< F32 > roll) noexcept |
void | rotate (const vec3< F32 > &axis, const Angle::DEGREES< F32 > angle) |
Creates a quaternion based on the specified axis-angle and calls "rotate" to change the orientation. | |
void | rotateYaw (Angle::DEGREES< F32 > angle) |
void | rotateRoll (Angle::DEGREES< F32 > angle) |
Change camera's roll. | |
void | rotatePitch (Angle::DEGREES< F32 > angle) |
Change camera's pitch. | |
void | move (F32 dx, F32 dy, F32 dz) noexcept |
Moves the camera by the specified offsets in each direction. | |
void | moveForward (const F32 factor) noexcept |
Moves the camera forward or backwards. | |
void | moveStrafe (const F32 factor) noexcept |
Moves the camera left or right. | |
void | moveUp (const F32 factor) noexcept |
Moves the camera up or down. | |
void | setFixedYawAxis (const bool useFixed, const vec3< F32 > &fixedAxis=WORLD_Y_AXIS) noexcept |
Exactly as in Ogre3D: locks the yaw movement to the specified axis. | |
bool | moveRelative (const vec3< F32 > &relMovement) |
bool | rotateRelative (const vec3< F32 > &relRotation) |
bool | zoom (F32 zoomFactor) noexcept |
void | setEuler (const vec3< Angle::DEGREES< F32 > > &euler) noexcept |
Set the camera's rotation to match the specified euler angles. | |
void | setEuler (const Angle::DEGREES< F32 > &pitch, const Angle::DEGREES< F32 > &yaw, const Angle::DEGREES< F32 > &roll) noexcept |
Set the camera's rotation to match the specified euler angles. | |
void | setAspectRatio (F32 ratio) noexcept |
void | setVerticalFoV (Angle::DEGREES< F32 > verticalFoV) noexcept |
void | setHorizontalFoV (Angle::DEGREES< F32 > horizontalFoV) noexcept |
const mat4< F32 > & | setProjection (vec2< F32 > zPlanes) |
const mat4< F32 > & | setProjection (F32 verticalFoV, vec2< F32 > zPlanes) |
const mat4< F32 > & | setProjection (F32 aspectRatio, F32 verticalFoV, vec2< F32 > zPlanes) |
const mat4< F32 > & | setProjection (const vec4< F32 > &rect, vec2< F32 > zPlanes) |
const mat4< F32 > & | setProjection (const mat4< F32 > &projection, vec2< F32 > zPlanes, bool isOrtho) noexcept |
void | setTarget (TransformComponent *tComp, const vec3< F32 > &offsetDirection=VECTOR3_ZERO) noexcept |
Offset direction is a (eventually normalized) vector that is scaled by curRadius and applied to the camera's eye position. | |
bool | moveFromPlayerState (const SceneStatePerPlayer &playerState) |
void | saveToXML (boost::property_tree::ptree &pt, std::string prefix="") const |
void | loadFromXML (const boost::property_tree::ptree &pt, std::string prefix="") |
vec3< F32 > | unProject (F32 winCoordsX, F32 winCoordsY, const Rect< I32 > &viewport) const noexcept |
vec3< F32 > | unProject (const vec3< F32 > &winCoords, const Rect< I32 > &viewport) const noexcept |
vec2< F32 > | project (const vec3< F32 > &worldCoords, const Rect< I32 > &viewport) const noexcept |
bool | removeUpdateListener (U32 id) |
U32 | addUpdateListener (const CameraListener &f) |
const CameraSnapshot & | snapshot () const noexcept |
Returns the internal camera snapshot data (eye, orientation, etc) | |
Angle::DEGREES< F32 > | getHorizontalFoV () const noexcept |
Returns the horizontal field of view, calculated from the vertical FoV and aspect ratio. | |
const mat4< F32 > & | viewMatrix () const noexcept |
Returns the most recent/up-to-date view matrix. | |
const mat4< F32 > & | viewMatrix () noexcept |
Updates the view matrix and returns the result. | |
const mat4< F32 > & | projectionMatrix () const noexcept |
Returns the most recent/up-to-date projection matrix. | |
const mat4< F32 > & | projectionMatrix () noexcept |
Updates the projection matrix and returns the result. | |
const mat4< F32 > & | viewProjectionMatrix () const noexcept |
Returns the most recent/up-to-date viewProjection matrix. | |
const mat4< F32 > & | viewProjectionMatrix () noexcept |
Updates the viewProjection matrix and returns the result. | |
const mat4< F32 > & | worldMatrix () const noexcept |
Returns the most recent/up-to-date inverse of the view matrix. | |
const mat4< F32 > & | worldMatrix () noexcept |
Updates the view matrix and returns its inverse as the worldMatrix. | |
const Frustum & | getFrustum () const noexcept |
Returns the most recent/up-to-date frustum. | |
Frustum & | getFrustum () noexcept |
Updates the frustum and returns the result. | |
PROPERTY_R_IW (vec4< F32 >, orthoRect, VECTOR4_UNIT) | |
PROPERTY_R_IW (vec3< Angle::DEGREES< F32 > >, euler, VECTOR3_ZERO) | |
PROPERTY_RW (vec3< F32 >, speedFactor, { 5.f }) | |
PROPERTY_RW (F32, maxRadius, 10.f) | |
PROPERTY_RW (F32, minRadius, 0.1f) | |
PROPERTY_RW (F32, curRadius, 8.f) | |
PROPERTY_RW (Mode, mode, Mode::COUNT) | |
PROPERTY_RW (bool, frustumLocked, false) | |
PROPERTY_RW (bool, rotationLocked, false) | |
PROPERTY_RW (bool, movementLocked, false) | |
PROPERTY_R_IW (bool, reflectionActive, false) | |
![]() | |
Resource (std::string_view resourceName, std::string_view typeName) | |
ResourceState | getState () const noexcept |
PROPERTY_R (Str< 32 >, typeName) | |
PROPERTY_R (Str< 256 >, resourceName) | |
![]() | |
GUIDWrapper () noexcept | |
GUIDWrapper (const GUIDWrapper &old) noexcept | |
GUIDWrapper (GUIDWrapper &&old) noexcept | |
virtual | ~GUIDWrapper ()=default |
FORCE_INLINE I64 | getGUID () const noexcept |
GUIDWrapper & | operator= (const GUIDWrapper &old)=delete |
GUIDWrapper & | operator= (GUIDWrapper &&other)=delete |
Static Public Member Functions | |
static mat4< F32 > | LookAt (const vec3< F32 > &eye, const vec3< F32 > &target, const vec3< F32 > &up) noexcept |
template<bool zeroToOneDepth = true> | |
static mat4< F32 > | Ortho (F32 left, F32 right, F32 bottom, F32 top, F32 zNear, F32 zFar) noexcept |
template<bool zeroToOneDepth = true> | |
static mat4< F32 > | Perspective (Angle::DEGREES< F32 > fovyRad, F32 aspect, F32 zNear, F32 zFar) noexcept |
template<bool zeroToOneDepth = true> | |
static mat4< F32 > | FrustumMatrix (F32 left, F32 right, F32 bottom, F32 top, F32 nearVal, F32 farVal) noexcept |
static void | Update (U64 deltaTimeUS) |
static void | InitPool () |
static void | DestroyPool () |
static bool | DestroyCamera (Camera *&camera) |
static Camera * | GetUtilityCamera (const UtilityCamera type) |
static Camera * | CreateCamera (const Str< 256 > &cameraName, Mode cameraMode) |
static Camera * | FindCamera (const U64 nameHash) |
static bool | RemoveChangeListener (U32 id) |
static U32 | AddChangeListener (const CameraListener &f) |
![]() | |
static I64 | generateGUID () noexcept |
Static Public Attributes | |
static constexpr F32 | DEFAULT_CAMERA_MOVE_SPEED = 20.f |
static constexpr F32 | DEFAULT_CAMERA_TURN_SPEED = 20.f |
static constexpr F32 | MAX_CAMERA_MOVE_SPEED = 20.f |
static constexpr F32 | MAX_CAMERA_TURN_SPEED = 20.f |
static constexpr F32 | s_minNearZ = 0.1f |
Protected Member Functions | |
bool | updateFrustum () |
Extract the frustum associated with our current PoV. | |
bool | updateViewMatrix () noexcept |
bool | updateProjection () noexcept |
void | update () noexcept |
![]() | |
virtual void | setState (ResourceState currentState) |
Static Protected Member Functions | |
static CameraEntry * | FindCameraEntry (const U64 nameHash) |
static CameraEntry * | FindCameraEntryLocked (const U64 nameHash) |
Protected Attributes | |
CameraListenerMap | _updateCameraListeners |
CameraSnapshot | _data |
Frustum | _frustum |
TransformComponent * | _targetTransform { nullptr } |
mat4< F32 > | _viewProjectionMatrix |
Plane< F32 > | _reflectionPlane |
vec3< Angle::RADIANS< F32 > > | _cameraRotation { VECTOR3_ZERO } |
vec3< F32 > | _fixedYawAxis { WORLD_Y_AXIS } |
vec3< F32 > | _offsetDir { WORLD_Z_AXIS } |
Angle::DEGREES< F32 > | _accumPitchDegrees { 0.0f } |
F32 | _currentRotationX { 0.0f } |
F32 | _currentRotationY { 0.0f } |
U32 | _updateCameraId { 0u } |
bool | _projectionDirty { true } |
bool | _viewMatrixDirty { false } |
bool | _frustumDirty { true } |
bool | _yawFixed { false } |
bool | _rotationDirty { true } |
![]() | |
std::atomic< ResourceState > | _resourceState |
![]() | |
const I64 | _guid |
|
strong |
|
strong |
|
explicit |
Definition at line 257 of file Camera.cpp.
|
static |
Definition at line 249 of file Camera.cpp.
U32 Divide::Camera::addUpdateListener | ( | const CameraListener & | f | ) |
Definition at line 464 of file Camera.cpp.
|
noexcept |
Clears the reflection plane specified (if any)
Definition at line 479 of file Camera.cpp.
|
static |
Definition at line 147 of file Camera.cpp.
|
static |
Definition at line 175 of file Camera.cpp.
|
static |
Definition at line 139 of file Camera.cpp.
Definition at line 224 of file Camera.cpp.
|
staticprotected |
Definition at line 200 of file Camera.cpp.
|
staticprotected |
Definition at line 208 of file Camera.cpp.
void Divide::Camera::fromCamera | ( | const Camera & | camera | ) |
Copies all of the internal data from the specified camera to the current one.
Definition at line 272 of file Camera.cpp.
void Divide::Camera::fromSnapshot | ( | const CameraSnapshot & | snapshot | ) |
Sets the internal snapshot data (eye, orientation, etc) to match the specified value.
Definition at line 297 of file Camera.cpp.
|
staticnoexcept |
Definition at line 273 of file Camera.inl.
|
inlinenoexcept |
Returns the most recent/up-to-date frustum.
Definition at line 202 of file Camera.inl.
|
inlinenoexcept |
Updates the frustum and returns the result.
Definition at line 207 of file Camera.inl.
|
noexcept |
Returns the horizontal field of view, calculated from the vertical FoV and aspect ratio.
Definition at line 586 of file Camera.cpp.
|
static |
Definition at line 120 of file Camera.cpp.
|
static |
Definition at line 130 of file Camera.cpp.
void Divide::Camera::loadFromXML | ( | const boost::property_tree::ptree & | pt, |
std::string | prefix = "" |
||
) |
Definition at line 1017 of file Camera.cpp.
Sets the camera's view matrix to specify the specified value by extracting the eye position, orientation and other data from it.
Definition at line 354 of file Camera.cpp.
|
inline |
Sets the camera to point at the specified target point from the specified eye position.
Definition at line 59 of file Camera.inl.
const mat4< F32 > & Divide::Camera::lookAt | ( | const vec3< F32 > & | eye, |
const vec3< F32 > & | target, | ||
const vec3< F32 > & | up | ||
) |
Sets the camera's position, target and up directions.
Definition at line 367 of file Camera.cpp.
|
staticnoexcept |
Definition at line 938 of file Camera.cpp.
Sets the camera to point at the specified target point.
Definition at line 54 of file Camera.inl.
Moves the camera by the specified offsets in each direction.
Definition at line 668 of file Camera.cpp.
|
inlinenoexcept |
Moves the camera forward or backwards.
Definition at line 123 of file Camera.inl.
bool Divide::Camera::moveFromPlayerState | ( | const SceneStatePerPlayer & | playerState | ) |
Definition at line 704 of file Camera.cpp.
Definition at line 737 of file Camera.cpp.
|
inlinenoexcept |
Moves the camera left or right.
Definition at line 129 of file Camera.inl.
|
inlinenoexcept |
Moves the camera up or down.
Definition at line 135 of file Camera.inl.
|
staticnoexcept |
Definition at line 219 of file Camera.inl.
|
staticnoexcept |
Definition at line 245 of file Camera.inl.
|
noexcept |
Definition at line 917 of file Camera.cpp.
Returns the most recent/up-to-date projection matrix.
Definition at line 168 of file Camera.inl.
Updates the projection matrix and returns the result.
Definition at line 173 of file Camera.inl.
Divide::Camera::PROPERTY_R_IW | ( | bool | , |
reflectionActive | , | ||
false | |||
) |
Divide::Camera::PROPERTY_R_IW | ( | vec3< Angle::DEGREES< F32 > > | , |
euler | , | ||
VECTOR3_ZERO | |||
) |
Divide::Camera::PROPERTY_R_IW | ( | vec4< F32 > | , |
orthoRect | , | ||
VECTOR4_UNIT | |||
) |
Divide::Camera::PROPERTY_RW | ( | bool | , |
frustumLocked | , | ||
false | |||
) |
Divide::Camera::PROPERTY_RW | ( | bool | , |
movementLocked | , | ||
false | |||
) |
Divide::Camera::PROPERTY_RW | ( | bool | , |
rotationLocked | , | ||
false | |||
) |
Divide::Camera::PROPERTY_RW | ( | F32 | , |
curRadius | , | ||
8. | f | ||
) |
Divide::Camera::PROPERTY_RW | ( | F32 | , |
maxRadius | , | ||
10. | f | ||
) |
Divide::Camera::PROPERTY_RW | ( | F32 | , |
minRadius | , | ||
0. | 1f | ||
) |
Divide::Camera::PROPERTY_RW | ( | Mode | , |
mode | , | ||
Mode::COUNT | |||
) |
|
static |
Definition at line 235 of file Camera.cpp.
bool Divide::Camera::removeUpdateListener | ( | U32 | id | ) |
Definition at line 450 of file Camera.cpp.
|
noexcept |
Sets the camera's orientation to match the specified yaw, pitch and roll values; Creates a quaternion based on the specified Euler angles and calls "rotate" to change the orientation
Definition at line 597 of file Camera.cpp.
void Divide::Camera::rotate | ( | const Quaternion< F32 > & | q | ) |
Rotates the camera (changes its orientation) by the specified quaternion (_orientation *= q)
Definition at line 427 of file Camera.cpp.
|
inline |
Creates a quaternion based on the specified axis-angle and calls "rotate" to change the orientation.
Definition at line 118 of file Camera.inl.
void Divide::Camera::rotatePitch | ( | Angle::DEGREES< F32 > | angle | ) |
Change camera's pitch.
Definition at line 663 of file Camera.cpp.
Definition at line 748 of file Camera.cpp.
void Divide::Camera::rotateRoll | ( | Angle::DEGREES< F32 > | angle | ) |
Change camera's roll.
Definition at line 658 of file Camera.cpp.
void Divide::Camera::rotateYaw | ( | Angle::DEGREES< F32 > | angle | ) |
Yaw, Pitch and Roll call "rotate" with a appropriate quaternion for each rotation. Because the camera is facing the -Z axis, a positive angle will create a positive Yaw behind the camera and a negative one in front of the camera (so we invert the angle - left will turn left when facing -Z)
Definition at line 653 of file Camera.cpp.
void Divide::Camera::saveToXML | ( | boost::property_tree::ptree & | pt, |
std::string | prefix = "" |
||
) | const |
Definition at line 969 of file Camera.cpp.
|
noexcept |
Definition at line 568 of file Camera.cpp.
|
inlinenoexcept |
Set the camera's rotation to match the specified euler angles.
Definition at line 152 of file Camera.inl.
|
inlinenoexcept |
Set the camera's rotation to match the specified euler angles.
Definition at line 147 of file Camera.inl.
Sets the camera's eye position.
Definition at line 100 of file Camera.inl.
Sets the camera's eye position.
Definition at line 106 of file Camera.inl.
|
inlinenoexcept |
Exactly as in Ogre3D: locks the yaw movement to the specified axis.
Definition at line 141 of file Camera.inl.
|
inlinenoexcept |
Sets the camera's Pitch angle. Yaw and Roll are previous extracted values.
Definition at line 89 of file Camera.inl.
|
inlinenoexcept |
Sets the camera's Roll angle. Yaw and Pitch are previous extracted values.
Definition at line 95 of file Camera.inl.
|
inlinenoexcept |
Global rotations are applied relative to the world axis, not the camera's.
Definition at line 48 of file Camera.inl.
Global rotations are applied relative to the world axis, not the camera's.
Definition at line 405 of file Camera.cpp.
|
inlinenoexcept |
Sets the camera's Yaw angle. This creates a new orientation quaternion for the camera and extracts the Euler angles
Definition at line 83 of file Camera.inl.
|
noexcept |
Definition at line 580 of file Camera.cpp.
|
inlinenoexcept |
Sets the camera's Pitch angle. Yaw and Roll are previous extracted values.
Definition at line 70 of file Camera.inl.
|
noexcept |
Definition at line 554 of file Camera.cpp.
Definition at line 541 of file Camera.cpp.
const mat4< F32 > & Divide::Camera::setProjection | ( | F32 | aspectRatio, |
F32 | verticalFoV, | ||
vec2< F32 > | zPlanes | ||
) |
Definition at line 526 of file Camera.cpp.
Definition at line 521 of file Camera.cpp.
Definition at line 516 of file Camera.cpp.
Specify a reflection plane that alters the final view matrix to be a mirror of the internal lookAt matrix.
Definition at line 472 of file Camera.cpp.
|
inlinenoexcept |
Sets the camera's Roll angle. Yaw and Pitch are previous extracted values.
Definition at line 76 of file Camera.inl.
|
noexcept |
Sets the camera's orientation.
Definition at line 592 of file Camera.cpp.
|
inlinenoexcept |
Sets the camera's orientation.
Definition at line 111 of file Camera.inl.
|
noexcept |
Offset direction is a (eventually normalized) vector that is scaled by curRadius and applied to the camera's eye position.
Definition at line 348 of file Camera.cpp.
|
noexcept |
Definition at line 574 of file Camera.cpp.
|
inlinenoexcept |
Sets the camera's Yaw angle. This creates a new orientation quaternion for the camera and extracts the Euler angles
Definition at line 64 of file Camera.inl.
|
inlinenoexcept |
Returns the internal camera snapshot data (eye, orientation, etc)
Definition at line 43 of file Camera.inl.
|
inlinenoexcept |
Definition at line 213 of file Camera.inl.
|
noexcept |
Returns the world space direction for the specified winCoords for this camera Use snapshot()._eye + unProject(...) * distance for a world-space position
Definition at line 879 of file Camera.cpp.
|
protectednoexcept |
Definition at line 317 of file Camera.cpp.
|
static |
Definition at line 107 of file Camera.cpp.
|
protected |
Extract the frustum associated with our current PoV.
Definition at line 856 of file Camera.cpp.
bool Divide::Camera::updateLookAt | ( | ) |
Return true if the cached camera state wasn't up-to-date.
Tell the rendering API to set up our desired PoV.
Definition at line 384 of file Camera.cpp.
|
protectednoexcept |
Definition at line 485 of file Camera.cpp.
|
protectednoexcept |
Definition at line 818 of file Camera.cpp.
Returns the most recent/up-to-date view matrix.
Definition at line 157 of file Camera.inl.
Updates the view matrix and returns the result.
Definition at line 162 of file Camera.inl.
Returns the most recent/up-to-date viewProjection matrix.
Definition at line 186 of file Camera.inl.
Updates the viewProjection matrix and returns the result.
Definition at line 179 of file Camera.inl.
Returns the most recent/up-to-date inverse of the view matrix.
Definition at line 197 of file Camera.inl.
Updates the view matrix and returns its inverse as the worldMatrix.
Definition at line 191 of file Camera.inl.
|
noexcept |
Definition at line 806 of file Camera.cpp.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |