FYP  1.0.0
Final Year Project -- Alexander Meuer
Camera Class Reference

Follow camera that can target an Actor. More...

#include <Camera.hpp>

Inheritance diagram for Camera:
Inheritance graph
Collaboration diagram for Camera:
Collaboration graph

Public Member Functions

 Camera (sf::Vector2f const &viewportSize, sf::Vector2f const &boundingArea=sf::Vector2f(FLT_MAX, FLT_MAX))
 
 Camera (sf::Vector2f const &viewportSize, sf::Vector2f const &boundingArea, std::shared_ptr< Actor > const &target)
 
void setTarget (std::shared_ptr< Actor > target)
 
std::weak_ptr< ActorgetTarget () const
 
void clearTarget ()
 
sf::Vector2f getDisplacement () const
 Gets the top left corner of the camera. More...
 
void update (float deltaSeconds)
 Updates camera's center to where the target is. Clamps camera edges to stay inside of bounding area. More...
 
void lock ()
 Locks the camera to its current position or target. Does nothing if already locked.
 
void unlock ()
 Unlocks the camera, allowing the player to move it. Does nothing if already unlocked.
 
void toggleLock ()
 
void setBoundingArea (sf::Vector2f const &bounds)
 
void doMouseMove (sf::Vector2f mousePos)
 Moves the camera if the mouse is close to the screen edge. Assumes that the mouse position is NOT translated from screen to game coordinates. More...
 
sf::Vector2f screenPositionToGamePosition (const int x, const int y) const
 

Static Public Member Functions

static Camera const & getDefaultCamera ()
 

Private Member Functions

void calculateScalingFactor ()
 
void setClampedCenter (sf::Vector2f newCenter)
 Sets the center of the view, accounting for bounds. Also sets sf::Listener position.
 

Static Private Member Functions

static void clamp (sf::Vector2f &value, sf::Vector2f const &min, sf::Vector2f const &max)
 Clamps a vector2f to a min and max value.
 

Private Attributes

std::weak_ptr< ActormTarget
 
sf::Vector2f mBoundingArea
 Edges of camera cannot go beyond this area (starting at 0,0) regardless of target position.
 
bool mLocked
 True if the camera cannot be moved by the player.
 
const float mEdgeMoveThreshold
 How close the mouse needs to be to the edge of the viewport before the camera moves.
 
const float mMoveSpeed
 
sf::Vector2f mMoveDirection
 
sf::Vector2f mScalingFactor
 Used to convert a point from screen coords to game coords.
 

Detailed Description

Follow camera that can target an Actor.

Member Function Documentation

void Camera::doMouseMove ( sf::Vector2f  mousePos)

Moves the camera if the mouse is close to the screen edge. Assumes that the mouse position is NOT translated from screen to game coordinates.

Parameters
mousePosThe position of the mouse
sf::Vector2f Camera::getDisplacement ( ) const

Gets the top left corner of the camera.

Returns
The top left corner of the camera in world space.
void Camera::update ( float  deltaSeconds)

Updates camera's center to where the target is. Clamps camera edges to stay inside of bounding area.

See also
clamp()

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