C++ Project 2016-2017: Arkanoid
transformation.cpp
Go to the documentation of this file.
1 
3 #include "transformation.h"
4 
5 #include <SFML/Graphics.hpp>
6 #include <iostream>
7 #include <memory>
8 
9 using namespace std;
10 
11 namespace arkanoidSFML {
12 
13  // Initialise singleton with nullptr at start
14  Transformation* Transformation::singleton = nullptr;
15 
16  Transformation::Transformation() {}
17 
18  Transformation::Transformation(double gridWidth, double gridHeight, double windowWidth, double windowHeight)
19  : widthScale(windowWidth/gridWidth), heightScale(windowHeight/gridHeight) {}
20 
22  if(!singleton) {
23  // Create instance
24  singleton = new Transformation;
25  }
26  return singleton;
27  }
28 
29  Transformation* Transformation::getInstance(double gridWidth, double gridHeight, double windowWidth, double windowHeight) {
30  if(!singleton) {
31  // Create instance
32  singleton = new Transformation(gridWidth, gridHeight, windowWidth, windowHeight);
33  }
34  return singleton;
35  }
36 
37  arkanoid::Vector2D Transformation::convertVector(const sf::Vector2f &vector) {
38  return arkanoid::Vector2D(vector.x / widthScale, vector.y / heightScale);
39  }
40 
41  double Transformation::convertX(double x) {
42  return x / widthScale;
43  }
44 
45  double Transformation::convertY(double y) {
46  return y / heightScale;
47  }
48 
49 }
static Transformation * getInstance()
Singleton: This class provides a method to convert screen pixels to their corresponding coordinates i...
All the game gui elements of the Arkanoid game.
Definition: ball_sfml.cpp:10
Representation of a vector.
Definition: vector2D.h:14
arkanoid::Vector2D convertVector(const sf::Vector2f &vector)