]> git.localhorst.tv Git - space.git/blob - src/graphics/Camera.h
adjust cam speed to zoom level
[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         Vector<int> ScreenSize() const { return size; }
19         float Zoom() const { return zoom; }
20
21         void Resize(int w, int h);
22         void Update(float deltaT);
23
24         void StartZoom();
25         void StopZoom();
26         void StartShrink();
27         void StopShrink();
28
29         /// transform v from world coords to screen coords
30         Vector<int> ToScreen(Vector<float> v) const {
31                 return Vector<int>(ToScale(v - *target)) + offset;
32         }
33         /// scale v to current zoom level
34         Vector<float> ToScale(Vector<float> v) const {
35                 return v * zoom;
36         }
37
38         /// transform v from screen coords to world coords
39         Vector<float> FromScreen(Vector<int> v) const {
40                 return FromScale(v - offset) + *target;
41         }
42         /// scale v back from current zoom level
43         Vector<float> FromScale(Vector<float> v) const {
44                 return v / zoom;
45         }
46
47 private:
48         const Vector<float> *target;
49         Vector<int> size;
50         Vector<int> offset;
51
52         float zoom;
53         int zoomAcc;
54
55 };
56
57 }
58
59 #endif