]> git.localhorst.tv Git - space.git/blob - src/graphics/Camera.h
move to SDL2
[space.git] / src / graphics / Camera.h
1 #ifndef SPACE_CAMERA_H_
2 #define SPACE_CAMERA_H_
3
4 #include "Vector.h"
5
6
7 namespace space {
8
9 class Camera {
10
11 public:
12         Camera(Vector<int> size, const Vector<float> &);
13
14 public:
15         void SetTarget(const Vector<float> &t) { target = &t; }
16         void SetZoom(float z) { zoom = z; }
17
18         Vector<int> ScreenSize() const { return size; }
19         float Zoom() const { return zoom; }
20
21         void Resize(int w, int h) { Resize(Vector<int>(w, h)); }
22         void Resize(Vector<int>);
23         void Update(float deltaT);
24
25         void StartZoom();
26         void StopZoom();
27         void StartShrink();
28         void StopShrink();
29
30         /// transform v from world coords to screen coords
31         Vector<int> ToScreen(Vector<float> v) const {
32                 return Vector<int>(ToScale(v - *target)) + offset;
33         }
34         /// scale v to current zoom level
35         Vector<float> ToScale(Vector<float> v) const {
36                 return v * zoom;
37         }
38
39         /// transform v from screen coords to world coords
40         Vector<float> FromScreen(Vector<int> v) const {
41                 return FromScale(v - offset) + *target;
42         }
43         /// scale v back from current zoom level
44         Vector<float> FromScale(Vector<float> v) const {
45                 return v / zoom;
46         }
47
48 private:
49         const Vector<float> *target;
50         Vector<int> size;
51         Vector<int> offset;
52
53         float zoom;
54         int zoomAcc;
55
56 };
57
58 }
59
60 #endif