From 1d8a3cc0ba1086683e979d20c8f0814bfe57e3e4 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 5 Dec 2016 23:19:58 +0100 Subject: [PATCH] Updated doc --- docs/_camera_8cpp_source.html | 2 +- docs/_camera_8h_source.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_camera_8cpp_source.html b/docs/_camera_8cpp_source.html index fdd402b..e22f57a 100644 --- a/docs/_camera_8cpp_source.html +++ b/docs/_camera_8cpp_source.html @@ -68,7 +68,7 @@
Camera.cpp
-Go to the documentation of this file.
1 #include "Camera.h"
2 
3 namespace flat2d
4 {
5  void Camera::setMapDimensions(int w, int h)
6  {
7  mapWidth = w;
8  mapHeight = h;
9  }
10 
12  {
13  return mapHeight;
14  }
15 
17  {
18  return mapWidth;
19  }
20 
21  SDL_Rect Camera::getBox()
22  {
23  SDL_Rect box = { x, y, w, h};
24  return box;
25  }
26 
27  void Camera::centerOn(int x, int y) {
28  x = x - (w/2);
29  y = y - (h/2);
30 
31  if (x > mapWidth - w) {
32  x = mapWidth - w;
33  } else if (x < 0) {
34  x = 0;
35  }
36  if (y > mapHeight - h) {
37  y = mapHeight - h;
38  } else if (y < 0) {
39  y = 0;
40  }
41  }
42 
43  bool Camera::isVisibleOnCamera(const SDL_Rect& box, int depth)
44  {
45  int bx = getScreenXposFor(box.x, depth);
46  int by = getScreenYposFor(box.y, depth);
47 
48  if (bx > w) {
49  return false;
50  } else if (bx + box.w < 0) {
51  return false;
52  } else if (by > h) {
53  return false;
54  } else if (by + box.h < 0) {
55  return false;
56  }
57  return true;
58  }
59 
60  bool Camera::isOutOfMapBounds(const SDL_Rect& rect)
61  {
62  return rect.x + rect.w < 0
63  || rect.y + rect.h < 0
64  || rect.y > mapHeight
65  || rect.x > mapWidth;
66  }
67 
68  int Camera::getScreenXposFor(int xpos, int depth) const
69  {
70  if (depth > 0) {
71  return xpos - (x / (1.5 * depth));
72  }
73  return xpos - x;
74  }
75 
76  int Camera::getScreenYposFor(int ypos, int depth) const
77  {
78  if (depth > 0) {
79  return ypos - (y / (5 * depth));
80  }
81  return ypos - y;
82  }
83 } // namespace flat2d
bool isVisibleOnCamera(const SDL_Rect &box, int depth=0)
Definition: Camera.cpp:43
+Go to the documentation of this file.
1 #include "Camera.h"
2 
3 namespace flat2d
4 {
5  void Camera::setMapDimensions(int w, int h)
6  {
7  mapWidth = w;
8  mapHeight = h;
9  }
10 
12  {
13  return mapHeight;
14  }
15 
17  {
18  return mapWidth;
19  }
20 
21  SDL_Rect Camera::getBox()
22  {
23  SDL_Rect box = { x, y, w, h};
24  return box;
25  }
26 
27  void Camera::centerOn(int xpos, int ypos) {
28  x = xpos - (w/2);
29  y = ypos - (h/2);
30 
31  if (x > mapWidth - w) {
32  x = mapWidth - w;
33  } else if (x < 0) {
34  x = 0;
35  }
36  if (y > mapHeight - h) {
37  y = mapHeight - h;
38  } else if (y < 0) {
39  y = 0;
40  }
41  }
42 
43  bool Camera::isVisibleOnCamera(const SDL_Rect& box, int depth)
44  {
45  int bx = getScreenXposFor(box.x, depth);
46  int by = getScreenYposFor(box.y, depth);
47 
48  if (bx > w) {
49  return false;
50  } else if (bx + box.w < 0) {
51  return false;
52  } else if (by > h) {
53  return false;
54  } else if (by + box.h < 0) {
55  return false;
56  }
57  return true;
58  }
59 
60  bool Camera::isOutOfMapBounds(const SDL_Rect& rect)
61  {
62  return rect.x + rect.w < 0
63  || rect.y + rect.h < 0
64  || rect.y > mapHeight
65  || rect.x > mapWidth;
66  }
67 
68  int Camera::getScreenXposFor(int xpos, int depth) const
69  {
70  if (depth > 0) {
71  return xpos - (x / (1.5 * depth));
72  }
73  return xpos - x;
74  }
75 
76  int Camera::getScreenYposFor(int ypos, int depth) const
77  {
78  if (depth > 0) {
79  return ypos - (y / (5 * depth));
80  }
81  return ypos - y;
82  }
83 } // namespace flat2d
bool isVisibleOnCamera(const SDL_Rect &box, int depth=0)
Definition: Camera.cpp:43
bool isOutOfMapBounds(const SDL_Rect &rect)
Definition: Camera.cpp:60
diff --git a/docs/_camera_8h_source.html b/docs/_camera_8h_source.html index 17acfc9..de6f03c 100644 --- a/docs/_camera_8h_source.html +++ b/docs/_camera_8h_source.html @@ -68,7 +68,7 @@
Camera.h
-Go to the documentation of this file.
1 #ifndef CAMERA_H_
2 #define CAMERA_H_
3 
4 #include <SDL2/SDL.h>
5 #include "Square.h"
6 
7 namespace flat2d
8 {
17  class Camera : public Square
18  {
19  private:
20  int mapWidth, mapHeight;
21 
22  public:
23  Camera(int width, int height) :
24  Square(0, 0, width, height),
25  mapWidth(1920),
26  mapHeight(1080) { }
27 
28  virtual ~Camera() { };
29 
35  void setMapDimensions(int, int);
36 
41  int getMapHeight();
42 
47  int getMapWidth();
48 
53  SDL_Rect getBox();
54 
60  void centerOn(int x, int y);
61 
68  bool isVisibleOnCamera(const SDL_Rect& box, int depth = 0);
69 
75  bool isOutOfMapBounds(const SDL_Rect& rect);
76 
83  int getScreenXposFor(int x, int depth = 0) const;
84 
91  int getScreenYposFor(int y, int depth = 0) const;
92  };
93 } // namespace flat2d
94 
95 #endif // CAMERA_H_
bool isVisibleOnCamera(const SDL_Rect &box, int depth=0)
Definition: Camera.cpp:43
+Go to the documentation of this file.
1 #ifndef CAMERA_H_
2 #define CAMERA_H_
3 
4 #include <SDL2/SDL.h>
5 #include "Square.h"
6 
7 namespace flat2d
8 {
17  class Camera : public Square
18  {
19  private:
20  int mapWidth, mapHeight;
21 
22  public:
23  Camera(int width, int height) :
24  Square(0, 0, width, height),
25  mapWidth(1920),
26  mapHeight(1080) { }
27 
28  virtual ~Camera() { }
29 
35  void setMapDimensions(int, int);
36 
41  int getMapHeight();
42 
47  int getMapWidth();
48 
53  SDL_Rect getBox();
54 
60  void centerOn(int x, int y);
61 
68  bool isVisibleOnCamera(const SDL_Rect& box, int depth = 0);
69 
75  bool isOutOfMapBounds(const SDL_Rect& rect);
76 
83  int getScreenXposFor(int x, int depth = 0) const;
84 
91  int getScreenYposFor(int y, int depth = 0) const;
92  };
93 } // namespace flat2d
94 
95 #endif // CAMERA_H_
bool isVisibleOnCamera(const SDL_Rect &box, int depth=0)
Definition: Camera.cpp:43
bool isOutOfMapBounds(const SDL_Rect &rect)
Definition: Camera.cpp:60