Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
Public Member Functions | List of all members
HFCore::Camera Class Reference

Interface useful for controlling the Camera. More...

#include <Camera.h>

Public Member Functions

 Camera ()
 Constructor.
 
virtual ~Camera ()
 Destructor.
 
virtual void update (fp32_hf dt)
 This method should be called by the game loop once for every iteration of the game loop, immediately before rendering takes place. More...
 
virtual void draw (Graphics *g)
 This method should be called by the game loop once for every iteration of the game loop. It will setup camera lookAt matrix based on position and so on. More...
 
virtual void resize (int32_hf screenWidth, int32_hf screenHeight)
 This method should be called by the game loop when window is resized. It will setup the perspective projection matrix. More...
 
virtual void reset ()
 Resets the Camera/Viewport to its default.
 
virtual fp32_hf getViewRadius ()
 If you were to draw a circle inscribed in the viewport, this function will let you know the size of its radius. More...
 
virtual glm::vec2 getWorldMaxVertex ()
 Get the world coordinate of the top-right point of the window. More...
 
virtual glm::vec2 getWorldMinVertex ()
 Get the world coordinate of the bottom-left point of the window. More...
 
virtual glm::vec2 getWorldDimensions ()
 Find out the dimensions of the area currently displayed in the window. More...
 
virtual void setPosition (fp32_hf x, fp32_hf y)
 Set the position of the Camera. More...
 
virtual void setPosition (fp32_hf x, fp32_hf y, fp32_hf z)
 Set the position of the Camera. Z coordinate is used to zoom in and out. More...
 
virtual void setPosition (const glm::vec2 &pos)
 Set the position of the Camera. More...
 
virtual void setPosition (const glm::vec3 &pos)
 Set the position of the Camera. Z coordinate is used to zoom in and out. More...
 
virtual void getPosition (fp32_hf *x, fp32_hf *y)
 Get the position of the Camera. More...
 
virtual void getPosition (fp32_hf *x, fp32_hf *y, fp32_hf *z)
 Get the position of the Camera. More...
 
virtual glm::vec2 getPositionV2 ()
 Get the position of the Camera. More...
 
virtual glm::vec3 getPositionV3 ()
 Get the position of the Camera. More...
 
virtual void setRotationZRad (fp32_hf angle)
 Set the rotation of the Camera about the Z-axis. More...
 
virtual void setRotationZDeg (fp32_hf angle)
 Set the rotation of the Camera about the Z-axis. More...
 
virtual fp32_hf getRotationZRad ()
 Get the rotation angle of the Camera in Radians about the Z-axis. More...
 
virtual fp32_hf getRotationZDeg ()
 Get the rotation angle of the Camera in Degrees about the Z-axis. More...
 
virtual void setZ (fp32_hf z)
 Set the position of the Camera on the Z-axis. More...
 
virtual fp32_hf getZ ()
 Get the position of the camera on the Z-axis. More...
 
virtual fp32_hf getZForViewRadius (fp32_hf radius)
 Get the Z value necessary to achieve the requested view radius. More...
 
virtual void setZByViewRadius (fp32_hf radius)
 Set the Z value necessary to achieve the requested view radius. More...
 
virtual fp32_hf getZNear ()
 Get the Z near clip distance. More...
 
virtual fp32_hf getZFar ()
 Get the Z far clip distance. More...
 
virtual void setZNear (fp32_hf zNear)
 Set the Z near clip distance. More...
 
virtual void setZFar (fp32_hf zFar)
 Set the Z far clip distance. More...
 
virtual void setViewCenter (fp32_hf x, fp32_hf y, fp32_hf z)
 Set the point towards which the camera should aim. More...
 
virtual void setViewCenter (const glm::vec3 &view)
 Set the point towards which the camera should aim. More...
 
virtual glm::vec3 getViewCenter ()
 Get the current look-at target of the camera. More...
 
virtual void setUpDirection (fp32_hf x, fp32_hf y, fp32_hf z)
 Set the up direction. More...
 
virtual void setUpDirection (const glm::vec3 &upDirection)
 Set the up direction. More...
 
virtual glm::vec3 getUpDirection ()
 Get the current up-direction of the camera. More...
 
virtual fp32_hf getFieldOfViewYDeg ()
 Get the field of view angle, in degrees, in the y direction. More...
 
virtual void setFieldOfViewYDeg (fp32_hf fovyDeg)
 Set the field of view angle, in degrees, in the y direction. More...
 

Detailed Description

Interface useful for controlling the Camera.

The Camera class is how you control what your players see at any time. The Camera uses perspective projection matrix underneath.

By default the Camera is positioned 10 units away from the origin, looking down the Z-axis (0.0, 0.0, 10.0). The visible world stretches from (-13.3, -10) to (13.3, 10).

Example code:

void GameMain::draw(HFCore::Graphics *g)
{
if (!g->beginScene())
return;
// set Camera lookAt based on internal EyePos, LookAtPos and
// UpDirection:
HFCORE_CAMERA->draw(g);
g->endScene();
}
void GameMain::update(fp32_hf dt)
{
// update Camera:
HFCORE_CAMERA->update(dt);
}
void GameMain::windowResized(int32_hf windowID, int32_hf w, int32_hf h)
{
// update Camera viewport and perspective projection based on new
// Window size:
HFCORE_CAMERA->resize(w, h);
}

Definition at line 70 of file Camera.h.

Member Function Documentation

◆ draw()

void Camera::draw ( Graphics g)
virtual

This method should be called by the game loop once for every iteration of the game loop. It will setup camera lookAt matrix based on position and so on.

Parameters
gGraphics object.

Definition at line 45 of file Camera.cpp.

◆ getFieldOfViewYDeg()

fp32_hf Camera::getFieldOfViewYDeg ( )
virtual

Get the field of view angle, in degrees, in the y direction.

Returns
The field of view angle.

Definition at line 279 of file Camera.cpp.

◆ getPosition() [1/2]

void Camera::getPosition ( fp32_hf x,
fp32_hf y 
)
virtual

Get the position of the Camera.

Parameters
xSets the X position of the camera if not NULL.
ySets the Y position of the camera if not NULL.

Definition at line 156 of file Camera.cpp.

◆ getPosition() [2/2]

void Camera::getPosition ( fp32_hf x,
fp32_hf y,
fp32_hf z 
)
virtual

Get the position of the Camera.

Parameters
xSets the X position of the camera if not NULL.
ySets the Y position of the camera if not NULL.
zSets the Z position of the camera if not NULL.

Definition at line 164 of file Camera.cpp.

◆ getPositionV2()

glm::vec2 Camera::getPositionV2 ( )
virtual

Get the position of the Camera.

Returns
The (X, Y) position of the camera.

Definition at line 174 of file Camera.cpp.

◆ getPositionV3()

glm::vec3 Camera::getPositionV3 ( )
virtual

Get the position of the Camera.

Returns
The (X, Y, Z) position of the camera.

Definition at line 179 of file Camera.cpp.

◆ getRotationZDeg()

fp32_hf Camera::getRotationZDeg ( )
virtual

Get the rotation angle of the Camera in Degrees about the Z-axis.

Returns
The rotation angle in degrees.

Definition at line 201 of file Camera.cpp.

◆ getRotationZRad()

fp32_hf Camera::getRotationZRad ( )
virtual

Get the rotation angle of the Camera in Radians about the Z-axis.

Returns
The rotation angle in radians.

Definition at line 196 of file Camera.cpp.

◆ getUpDirection()

glm::vec3 Camera::getUpDirection ( )
virtual

Get the current up-direction of the camera.

Returns
The point where the Camera is currently looking.

Definition at line 274 of file Camera.cpp.

◆ getViewCenter()

glm::vec3 Camera::getViewCenter ( )
virtual

Get the current look-at target of the camera.

Returns
The point where the Camera is currently looking.

Definition at line 259 of file Camera.cpp.

◆ getViewRadius()

fp32_hf Camera::getViewRadius ( )
virtual

If you were to draw a circle inscribed in the viewport, this function will let you know the size of its radius.

This is useful for determining how much of the world is currently being displayed.

Note
that if you have a non-square viewport, the circle is bounded by the smaller dimension.
Returns
The radius size in world units.

Definition at line 94 of file Camera.cpp.

◆ getWorldDimensions()

glm::vec2 Camera::getWorldDimensions ( )
virtual

Find out the dimensions of the area currently displayed in the window.

Returns
The dimensions of the viewport in world units.

Definition at line 112 of file Camera.cpp.

◆ getWorldMaxVertex()

glm::vec2 Camera::getWorldMaxVertex ( )
virtual

Get the world coordinate of the top-right point of the window.

Returns
The world coordinate

Definition at line 100 of file Camera.cpp.

◆ getWorldMinVertex()

glm::vec2 Camera::getWorldMinVertex ( )
virtual

Get the world coordinate of the bottom-left point of the window.

Returns
The world coordinate

Definition at line 106 of file Camera.cpp.

◆ getZ()

fp32_hf Camera::getZ ( )
virtual

Get the position of the camera on the Z-axis.

Returns
The Camera Z coordinate.

Definition at line 211 of file Camera.cpp.

◆ getZFar()

fp32_hf Camera::getZFar ( )
virtual

Get the Z far clip distance.

Returns
The far clip distance.

Definition at line 232 of file Camera.cpp.

◆ getZForViewRadius()

fp32_hf Camera::getZForViewRadius ( fp32_hf  radius)
virtual

Get the Z value necessary to achieve the requested view radius.

Parameters
radiusThe desired view radius.
Returns
The Z value.

Definition at line 216 of file Camera.cpp.

◆ getZNear()

fp32_hf Camera::getZNear ( )
virtual

Get the Z near clip distance.

Returns
The near clip distance.

Definition at line 227 of file Camera.cpp.

◆ resize()

void Camera::resize ( int32_hf  screenWidth,
int32_hf  screenHeight 
)
virtual

This method should be called by the game loop when window is resized. It will setup the perspective projection matrix.

Parameters
screenWidthThe new window width.
screenHeightThe new window height.

Definition at line 60 of file Camera.cpp.

◆ setFieldOfViewYDeg()

void Camera::setFieldOfViewYDeg ( fp32_hf  fovyDeg)
virtual

Set the field of view angle, in degrees, in the y direction.

It will be used to setup perspective projection matrix Camera uses.

Parameters
fovyDegThe field of view angle.

Definition at line 284 of file Camera.cpp.

◆ setPosition() [1/4]

void Camera::setPosition ( fp32_hf  x,
fp32_hf  y 
)
virtual

Set the position of the Camera.

Parameters
xThe new X position for the camera
yThe new Y position for the camera

Definition at line 136 of file Camera.cpp.

◆ setPosition() [2/4]

void Camera::setPosition ( fp32_hf  x,
fp32_hf  y,
fp32_hf  z 
)
virtual

Set the position of the Camera. Z coordinate is used to zoom in and out.

Parameters
xThe new X position for the camera
yThe new Y position for the camera
zThe new Z position for the camera

Definition at line 141 of file Camera.cpp.

◆ setPosition() [3/4]

void Camera::setPosition ( const glm::vec2 &  pos)
virtual

Set the position of the Camera.

Parameters
posThe new position for the camera

Definition at line 146 of file Camera.cpp.

◆ setPosition() [4/4]

void Camera::setPosition ( const glm::vec3 &  pos)
virtual

Set the position of the Camera. Z coordinate is used to zoom in and out.

Parameters
posThe new position for the camera

Definition at line 151 of file Camera.cpp.

◆ setRotationZDeg()

void Camera::setRotationZDeg ( fp32_hf  angle)
virtual

Set the rotation of the Camera about the Z-axis.

Parameters
angleRotation angle in Degrees.

Definition at line 190 of file Camera.cpp.

◆ setRotationZRad()

void Camera::setRotationZRad ( fp32_hf  angle)
virtual

Set the rotation of the Camera about the Z-axis.

Parameters
angleRotation angle in Radians.

Definition at line 184 of file Camera.cpp.

◆ setUpDirection() [1/2]

void Camera::setUpDirection ( fp32_hf  x,
fp32_hf  y,
fp32_hf  z 
)
virtual

Set the up direction.

Parameters
xThe X coordinate.
yThe Y coordinate.
zThe Z coordinate.

Definition at line 264 of file Camera.cpp.

◆ setUpDirection() [2/2]

void Camera::setUpDirection ( const glm::vec3 &  upDirection)
virtual

Set the up direction.

Parameters
upDirectionThe new (X, Y, Z) up direction.

Definition at line 269 of file Camera.cpp.

◆ setViewCenter() [1/2]

void Camera::setViewCenter ( fp32_hf  x,
fp32_hf  y,
fp32_hf  z 
)
virtual

Set the point towards which the camera should aim.

Parameters
xThe X coordinate at which the Camera will aim.
yThe Y coordinate at which the Camera will aim.
zThe Z coordinate at which the Camera will aim.

Definition at line 249 of file Camera.cpp.

◆ setViewCenter() [2/2]

void Camera::setViewCenter ( const glm::vec3 &  view)
virtual

Set the point towards which the camera should aim.

Parameters
viewThe new (X, Y, Z) position for the Camera.

Definition at line 254 of file Camera.cpp.

◆ setZ()

void Camera::setZ ( fp32_hf  z)
virtual

Set the position of the Camera on the Z-axis.

Parameters
zThe Camera Z coordinate.

Definition at line 206 of file Camera.cpp.

◆ setZByViewRadius()

void Camera::setZByViewRadius ( fp32_hf  radius)
virtual

Set the Z value necessary to achieve the requested view radius.

Parameters
radiusThe desired view radius.

Definition at line 222 of file Camera.cpp.

◆ setZFar()

void Camera::setZFar ( fp32_hf  zFar)
virtual

Set the Z far clip distance.

Parameters
zFarThe far clip distance.

Definition at line 243 of file Camera.cpp.

◆ setZNear()

void Camera::setZNear ( fp32_hf  zNear)
virtual

Set the Z near clip distance.

Parameters
zNearThe near clip distance.

Definition at line 237 of file Camera.cpp.

◆ update()

void Camera::update ( fp32_hf  dt)
virtual

This method should be called by the game loop once for every iteration of the game loop, immediately before rendering takes place.

Parameters
dtElapsed time since last update

Definition at line 40 of file Camera.cpp.


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