]> git.localhorst.tv Git - space.git/blob - src/graphics/Camera.h
simple zoom
[space.git] / src / graphics / Camera.h
1 #ifndef SPACE_CAMERA_H_
2 #define SPACE_CAMERA_H_
3
4 #include "../math/Vector.h"
5
6
7 namespace space {
8
9 class Camera {
10
11 public:
12         Camera(int w, int h, const Vector<float> &);
13
14 public:
15         void SetTarget(const Vector<float> &t) { target = &t; }
16         void SetZoom(float z) { zoom = z; }
17
18         void Resize(int w, int h);
19         void Update(float deltaT);
20
21         void DoubleZoom();
22         void HalfZoom();
23
24         Vector<int> ToScreen(Vector<float> v) const {
25                 return Vector<int>(OffsetOf(v));
26         }
27         Vector<float> OffsetOf(Vector<float> v) const {
28                 return ToScale(v - *target) + offset;
29         }
30         Vector<float> ToScale(Vector<float> v) const {
31                 if (zoom == 0) {
32                         return v;
33                 } else if (zoom > 0) {
34                         return v * float(1 << zoom);
35                 } else {
36                         return v / float(1 << -zoom);
37                 }
38         }
39
40 private:
41         const Vector<float> *target;
42         Vector<float> offset;
43
44         int zoom;
45
46 };
47
48 }
49
50 #endif