TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Graphics::Camera Class Reference

#include <tb_camera.h>

Public Types

enum  IntensityLevel { kNoShaking, kLightShaking, kMediumShaking, kHeavyShaking }
 

Public Member Functions

 Camera (void)
 
virtual ~Camera (void)
 
void SetPosition (const tbMath::Vector2 &cameraPosition)
 
const tbMath::Vector2GetPosition (void) const
 
tbMath::Vector2 GetPositionWithShake (void) const
 
void Update (const float deltaTime)
 
void ShakeCamera (const IntensityLevel &shakeIntensity, const float shakeDuration=-1.0f)
 
void SetRotation (const float cameraRotation)
 
float GetRotation (void) const
 

Detailed Description

Defines what the camera object can do and how it does it. The camera can move around in the world by using SetPosition(), and CameraShake can be applied using ShakeCamera().

Member Enumeration Documentation

Provides different camera shaking intensity levels.

Enumerator
kNoShaking 

A shake intensity level that cancels out any current shaking effects.

kLightShaking 

A shake intensity level like some slight vibration from movement.

kMediumShaking 

A shake intensity level like a small explosion.

kHeavyShaking 

A shake intensity level like an earthquake is happening.

Constructor & Destructor Documentation

TurtleBrains::Graphics::Camera::Camera ( void  )

Creates a camera object that places the top-left of the screen at 0,0 with no shake started.

virtual TurtleBrains::Graphics::Camera::~Camera ( void  )
virtual

Cleans up after the camera object, which doesn't actually have any resources to clean.

Member Function Documentation

const tbMath::Vector2& TurtleBrains::Graphics::Camera::GetPosition ( void  ) const

Returns the current position of the camera in world-space coordinates, representing the top-left (0,0) position of the screen if there is no shake, but if there is shake the screen (0,0) will move around slightly based on shake intensity.

tbMath::Vector2 TurtleBrains::Graphics::Camera::GetPositionWithShake ( void  ) const

Returns the current position of the camera in world-space coordinates, representing the top-left (0,0) position of the screen including the added shake offset which gets randomly set each frame. This is the position of the screen (0,0) if the camera is shaking or not.

float TurtleBrains::Graphics::Camera::GetRotation ( void  ) const

Retrieves the current rotation value of the camera. This is completely experimental and may be removed from the interface completely.

Note
: Use this at your own risk, as it is not fully supported and may get removed from future versions.
void TurtleBrains::Graphics::Camera::SetPosition ( const tbMath::Vector2 cameraPosition)

Change the position of the camera, which moves the top-left (0,0) of the screen, to some other coordinate in the world based on the supplied cameraPosition parameter.

Parameters
cameraPositionThe world-space position where the top-left of the screen will be placed.
void TurtleBrains::Graphics::Camera::SetRotation ( const float  cameraRotation)

Sets the rotation value of the camera so that the scene can rotate. This is completely experimental and may be removed from the interface completely. The camera will rotate the screen around the center of the screen, useful if you want the player to always face a single direction.

Parameters
cameraRotationThe amount of rotation to apply, in degrees. Positive values spins the camera clockwise, this will cause the screen to spin counter clockwise.
Note
: Use this at your own risk, as it is not fully supported and may get removed from future versions.
void TurtleBrains::Graphics::Camera::ShakeCamera ( const IntensityLevel shakeIntensity,
const float  shakeDuration = -1.0f 
)

Based on the shakeIntensity supplied the camera will start shaking various amounts and for different durations. Light and quick, to heavy and long.

Parameters
shakeIntensityHow vigorously the camera is shaking, slight rumble to earthquake rumbles.
shakeDurationHow long the camera will shake for, if less-than or equal-to 0, a default internal value will be used for duration. If shakeIntensity is kNoShaking the shakeDuration will have no effect.
void TurtleBrains::Graphics::Camera::Update ( const float  deltaTime)

This must be called once per frame, every frame, and only once during the frame to update the camera shake and other camera features. When using tbGame::GameScene this is automatically called by the game scene loop update.