]> git.localhorst.tv Git - space.git/blobdiff - src/graphics/Camera.h
move to SDL2
[space.git] / src / graphics / Camera.h
index 911f23601feacc59b287cf2734924470b20640c8..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,13 +9,17 @@ namespace space {
 class Camera {
 
 public:
-       Camera(int w, int h, const Vector<float> &);
+       Camera(Vector<int> size, const Vector<float> &);
 
 public:
        void SetTarget(const Vector<float> &t) { target = &t; }
        void SetZoom(float z) { zoom = z; }
 
-       void Resize(int w, int h);
+       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();
@@ -23,18 +27,27 @@ public:
        void StartShrink();
        void StopShrink();
 
+       /// transform v from world coords to screen coords
        Vector<int> ToScreen(Vector<float> v) const {
-               return Vector<int>(OffsetOf(v)) + offset;
-       }
-       Vector<float> OffsetOf(Vector<float> v) const {
-               return ToScale(v - *target);
+               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<int> size;
        Vector<int> offset;
 
        float zoom;