]> git.localhorst.tv Git - orbi.git/blob - src/graphics/Camera.h
7e8ba2f9c86183b3cb35d5c43e1f4cd57894f958
[orbi.git] / src / graphics / Camera.h
1 #ifndef ORBI_CAMERA_H_
2 #define ORBI_CAMERA_H_
3
4 #include "Vector.h"
5
6
7 namespace orbi {
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 SetScale(Vector<float> s) { scale = s; }
17
18         Vector<int> ScreenSize() const { return size; }
19
20         void Resize(int w, int h) { Resize(Vector<int>(w, h)); }
21         void Resize(Vector<int>);
22         void Update(float deltaT) { } // unused
23
24         /// transform v from world coords to screen coords
25         Vector<int> ToScreen(Vector<float> v) const {
26                 return ToScale(v - *target) + offset;
27         }
28         /// scale v from world to screen
29         Vector<int> ToScale(Vector<float> v) const {
30                 return Vector<int>(v * scale);
31         }
32
33         /// transform v from screen coords to world coords
34         Vector<float> FromScreen(Vector<int> v) const {
35                 return FromScale(v - offset) + *target;
36         }
37         /// scale v from screen to world
38         Vector<float> FromScale(Vector<int> v) const {
39                 return Vector<float>(v) / scale;
40         }
41
42 private:
43         const Vector<float> *target;
44         Vector<float> scale;
45         Vector<int> size;
46         Vector<int> offset;
47
48 };
49
50 }
51
52 #endif