YAPOG  0.0.1
Yet Another Pokemon Online Game
Camera.cpp
Go to the documentation of this file.
2 
3 namespace yap
4 {
5  Camera::Camera (const Vector2& position, const Vector2& size)
6  : spatialInfo_ (position, size)
7  , view_ (spatialInfo_.GetRectangle ())
8  {
9  }
10 
12  {
13  }
14 
15  const Vector2& Camera::GetPosition () const
16  {
17  return spatialInfo_.GetPosition ();
18  }
19 
20  const Vector2& Camera::GetSize () const
21  {
22  return spatialInfo_.GetSize ();
23  }
24 
25  const Vector2& Camera::GetTopLeft () const
26  {
27  return spatialInfo_.GetTopLeft ();
28  }
29 
31  {
32  return spatialInfo_.GetBottomRight ();
33  }
34 
35  const Vector2& Camera::GetCenter () const
36  {
37  return spatialInfo_.GetCenter ();
38  }
39 
41  {
42  return spatialInfo_.GetRectangle ();
43  }
44 
45  void Camera::Move (const Vector2& offset)
46  {
47  spatialInfo_.SetPosition (GetPosition () + offset);
48 
49  view_.move (offset);
50 
51  OnMoved (*this, offset);
52  }
53 
54  void Camera::Scale (const Vector2& factor)
55  {
57  Vector2 (
58  GetSize ().x * factor.x,
59  GetSize ().y * factor.y));
60 
61  view_.reset (GetRectangle ());
62  }
63 
64  void Camera::SetPosition (const Vector2& position)
65  {
66  Move (position - GetPosition ());
67  }
68 
69  void Camera::SetSize (const Vector2& size)
70  {
71  Scale (
72  Vector2 (
73  size.x / GetSize ().x,
74  size.y / GetSize ().y));
75  }
76 
77  bool Camera::IsInView (const Vector2& point) const
78  {
79  return IsInView (point, DEFAULT_SIZE);
80  }
81 
82  bool Camera::IsInView (const Vector2& point, const Vector2& size) const
83  {
84  return HandleIsInView (point, size);
85  }
86 
87  Vector2 Camera::ToLocal (const Vector2& globalPoint) const
88  {
89  return HandleToLocal (globalPoint);
90  }
91 
92  Vector2 Camera::ToGlobal (const Vector2& localPoint) const
93  {
94  return HandleToGlobal (localPoint);
95  }
96 
97  const sf::View& Camera::GetInnerView () const
98  {
99  return view_;
100  }
101 
103  {
104  return OnMoved;
105  }
106 
107  bool Camera::HandleIsInView (const Vector2& point, const Vector2& size) const
108  {
109  return GetRectangle ().intersects (sf::FloatRect (point, size));
110  }
111 
112  Vector2 Camera::HandleToLocal (const Vector2& globalPoint) const
113  {
114  return globalPoint - GetPosition ();
115  }
116 
117  Vector2 Camera::HandleToGlobal (const Vector2& localPoint) const
118  {
119  return localPoint + GetPosition ();
120  }
121 } // namespace yap