Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Camera Class Reference

#include <Camera.hxx>

+ Inheritance diagram for Camera:
+ Collaboration diagram for Camera:

Public Member Functions

void centerScreenOnPoint (const Point &isoCoordinates)
 Centers camera on given isometric coordinates. More...
 
void centerScreenOnMapCenter ()
 Centers camera on the middle of the map. More...
 
void increaseZoomLevel ()
 Increases the zoom level of the camera. More...
 
void decreaseZoomLevel ()
 Decreases the zoom level of the camera. More...
 
void changeZoomLevel (bool inc)
 
void setPinchDistance (float pinchDistance, int isoX, int isoY)
 Sets the pinch distance for touch screens. More...
 
void moveCamera (int xOffset, int yOffset)
 Move the camera in the given direction. More...
 
void canMove (bool move)
 
const SDL_Point & cameraOffset () const noexcept
 
const double & zoomLevel () const noexcept
 
const SDL_Point & tileSize () const noexcept
 
void canScale (bool value)
 

Private Member Functions

 Camera ()=default
 
 ~Camera ()=default
 

Private Attributes

friend Singleton
 
float m_PinchDistance = 0.f
 
SDL_Point m_TileSize {32, 16}
 
SDL_Point m_CameraOffset {0, 0}
 
double m_ZoomLevel = 1.0
 the current zoom level of the camera More...
 
bool m_canScale = true
 
bool m_canMove = true
 
Point m_CenterIsoCoordinates
 

Additional Inherited Members

- Static Public Member Functions inherited from Singleton< Camera >
static Camerainstance (void)
 Get an instance of the singleton. More...
 
- Protected Member Functions inherited from Singleton< Camera >
 Singleton () noexcept=default
 
 ~Singleton () noexcept=default
 

Detailed Description

Definition at line 9 of file Camera.hxx.

Constructor & Destructor Documentation

◆ Camera()

Camera::Camera ( )
privatedefault

◆ ~Camera()

Camera::~Camera ( )
privatedefault

Member Function Documentation

◆ cameraOffset()

const SDL_Point & Camera::cameraOffset ( ) const
noexcept

Definition at line 95 of file Camera.cxx.

95 { return m_CameraOffset; }
+ Here is the caller graph for this function:

◆ canMove()

void Camera::canMove ( bool  move)
inline

Definition at line 49 of file Camera.hxx.

49 { m_canMove = move; }
+ Here is the caller graph for this function:

◆ canScale()

void Camera::canScale ( bool  value)
inline

Definition at line 55 of file Camera.hxx.

55 { m_canScale = value; }
+ Here is the caller graph for this function:

◆ centerScreenOnMapCenter()

void Camera::centerScreenOnMapCenter ( )

Centers camera on the middle of the map.

Definition at line 75 of file Camera.cxx.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ centerScreenOnPoint()

void Camera::centerScreenOnPoint ( const Point isoCoordinates)

Centers camera on given isometric coordinates.

Parameters
isoCoordinatescoordinates to center the camera on

Definition at line 56 of file Camera.cxx.

57 {
58  if (isoCoordinates.isWithinMapBoundaries())
59  {
60  m_CenterIsoCoordinates = isoCoordinates;
61  const SDL_Point screenCoordinates = convertIsoToScreenCoordinates(isoCoordinates, true);
62 
63  int x = static_cast<int>((screenCoordinates.x + (m_TileSize.x * m_ZoomLevel) * 0.5) - Settings::instance().screenWidth * 0.5);
64  int y =
65  static_cast<int>((screenCoordinates.y + (m_TileSize.y * m_ZoomLevel) * 0.25) - Settings::instance().screenHeight * 0.5);
66 
67  x -= static_cast<int>((m_TileSize.x * m_ZoomLevel) * 0.75);
68  y -= static_cast<int>(m_TileSize.y * m_ZoomLevel);
69 
70  m_CameraOffset = {x, y};
72  }
73 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ changeZoomLevel()

void Camera::changeZoomLevel ( bool  inc)
inline

Definition at line 35 of file Camera.hxx.

35 { inc ? increaseZoomLevel() : decreaseZoomLevel(); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decreaseZoomLevel()

void Camera::decreaseZoomLevel ( )

Decreases the zoom level of the camera.

Definition at line 19 of file Camera.cxx.

20 {
21  if (!m_canScale)
22  return;
23 
24  if (m_ZoomLevel > 0.5)
25  {
26  m_ZoomLevel -= 0.5;
29  }
30 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ increaseZoomLevel()

void Camera::increaseZoomLevel ( )

Increases the zoom level of the camera.

Definition at line 6 of file Camera.cxx.

7 {
8  if (!m_canScale)
9  return;
10 
11  if (m_ZoomLevel < 4.0)
12  {
13  m_ZoomLevel += 0.5;
16  }
17 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moveCamera()

void Camera::moveCamera ( int  xOffset,
int  yOffset 
)

Move the camera in the given direction.

Definition at line 82 of file Camera.cxx.

83 {
84  if (!m_canMove)
85  return;
86 
87  m_CameraOffset.x -= xOffset;
88  m_CameraOffset.y -= yOffset;
90  // update center coordinates
93 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPinchDistance()

void Camera::setPinchDistance ( float  pinchDistance,
int  isoX,
int  isoY 
)

Sets the pinch distance for touch screens.

Parameters
pinchDistancethe pinch distance
isoXthe x-center of the pinch
isoYthe y-center of the pinch

Definition at line 32 of file Camera.cxx.

33 {
34  m_PinchDistance += pinchDistance;
35 
36  if (m_PinchDistance > 0.25F)
37  {
38  m_PinchDistance = 0;
39  if (m_ZoomLevel < 4.0)
40  {
41  centerScreenOnPoint({isoX, isoY, 0, 0});
42  }
44  }
45  else if (m_PinchDistance < -0.25F)
46  {
47  m_PinchDistance = 0;
48  if (m_ZoomLevel > 0.5)
49  {
50  centerScreenOnPoint({isoX, isoY, 0, 0});
51  }
53  }
54 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tileSize()

const SDL_Point & Camera::tileSize ( ) const
noexcept

Definition at line 99 of file Camera.cxx.

99 { return m_TileSize; }
+ Here is the caller graph for this function:

◆ zoomLevel()

const double & Camera::zoomLevel ( ) const
noexcept

Definition at line 97 of file Camera.cxx.

97 { return m_ZoomLevel; }
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_CameraOffset

SDL_Point Camera::m_CameraOffset {0, 0}
private

Definition at line 63 of file Camera.hxx.

◆ m_canMove

bool Camera::m_canMove = true
private

Definition at line 66 of file Camera.hxx.

◆ m_canScale

bool Camera::m_canScale = true
private

Definition at line 65 of file Camera.hxx.

◆ m_CenterIsoCoordinates

Point Camera::m_CenterIsoCoordinates
private

Definition at line 67 of file Camera.hxx.

◆ m_PinchDistance

float Camera::m_PinchDistance = 0.f
private

Definition at line 61 of file Camera.hxx.

◆ m_TileSize

SDL_Point Camera::m_TileSize {32, 16}
private

Definition at line 62 of file Camera.hxx.

◆ m_ZoomLevel

double Camera::m_ZoomLevel = 1.0
private

the current zoom level of the camera

Definition at line 64 of file Camera.hxx.

◆ Singleton

friend Camera::Singleton
private

Definition at line 11 of file Camera.hxx.


The documentation for this class was generated from the following files:
Camera::m_canScale
bool m_canScale
Definition: Camera.hxx:65
Camera::m_ZoomLevel
double m_ZoomLevel
the current zoom level of the camera
Definition: Camera.hxx:64
Camera::m_PinchDistance
float m_PinchDistance
Definition: Camera.hxx:61
SettingsData::screenHeight
ScreenDimension screenHeight
the screen height
Definition: Settings.hxx:46
Camera::increaseZoomLevel
void increaseZoomLevel()
Increases the zoom level of the camera.
Definition: Camera.cxx:6
Camera::m_CameraOffset
SDL_Point m_CameraOffset
Definition: Camera.hxx:63
MapFunctions::refreshVisibleMap
void refreshVisibleMap()
Refresh the visible part of the map.
Definition: MapFunctions.cxx:764
Camera::decreaseZoomLevel
void decreaseZoomLevel()
Decreases the zoom level of the camera.
Definition: Camera.cxx:19
SettingsData::mapSize
int mapSize
the size of the map
Definition: Settings.hxx:34
convertScreenToIsoCoordinates
Point convertScreenToIsoCoordinates(const SDL_Point &screenCoordinates)
converts screen space coordinates to isometric space coordinates.
Definition: isoMath.cxx:49
Camera::m_TileSize
SDL_Point m_TileSize
Definition: Camera.hxx:62
SettingsData::screenWidth
ScreenDimension screenWidth
the screen width
Definition: Settings.hxx:40
Point::isWithinMapBoundaries
bool isWithinMapBoundaries() const
Definition: Point.hxx:37
Camera::m_CenterIsoCoordinates
Point m_CenterIsoCoordinates
Definition: Camera.hxx:67
Camera::centerScreenOnPoint
void centerScreenOnPoint(const Point &isoCoordinates)
Centers camera on given isometric coordinates.
Definition: Camera.cxx:56
Camera::m_canMove
bool m_canMove
Definition: Camera.hxx:66
Singleton< Settings >::instance
static Settings & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
convertIsoToScreenCoordinates
SDL_Point convertIsoToScreenCoordinates(const Point &isoCoordinates, bool calcWithoutOffset)
converts coordinates from isometric to screen space
Definition: isoMath.cxx:25