]> git.localhorst.tv Git - space.git/blobdiff - src/graphics/Camera.h
move to SDL2
[space.git] / src / graphics / Camera.h
index 10699f097e2f5e6d9ca38892bd5d78a3aa5bff7e..815b4b047fdf1e107b3190034ac8ffe02b4a9071 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef SPACE_CAMERA_H_
 #define SPACE_CAMERA_H_
 
-#include "../math/Vector.h"
+#include "Vector.h"
 
 
 namespace space {
@@ -9,18 +9,49 @@ namespace space {
 class Camera {
 
 public:
-       Camera(int w, int h, const Vector<float> &);
+       Camera(Vector<int> size, const Vector<float> &);
 
 public:
-       void Resize(int w, int h);
+       void SetTarget(const Vector<float> &t) { target = &t; }
+       void SetZoom(float z) { zoom = z; }
 
-       Vector<float> Offset() {
-               return -(*target - offset);
+       Vector<int> ScreenSize() const { return size; }
+       float Zoom() const { return zoom; }
+
+       void Resize(int w, int h) { Resize(Vector<int>(w, h)); }
+       void Resize(Vector<int>);
+       void Update(float deltaT);
+
+       void StartZoom();
+       void StopZoom();
+       void StartShrink();
+       void StopShrink();
+
+       /// transform v from world coords to screen coords
+       Vector<int> ToScreen(Vector<float> v) const {
+               return Vector<int>(ToScale(v - *target)) + offset;
+       }
+       /// scale v to current zoom level
+       Vector<float> ToScale(Vector<float> v) const {
+               return v * zoom;
+       }
+
+       /// transform v from screen coords to world coords
+       Vector<float> FromScreen(Vector<int> v) const {
+               return FromScale(v - offset) + *target;
+       }
+       /// scale v back from current zoom level
+       Vector<float> FromScale(Vector<float> v) const {
+               return v / zoom;
        }
 
 private:
        const Vector<float> *target;
-       Vector<float> offset;
+       Vector<int> size;
+       Vector<int> offset;
+
+       float zoom;
+       int zoomAcc;
 
 };