X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FCamera.h;h=815b4b047fdf1e107b3190034ac8ffe02b4a9071;hb=1129b8ac89f1e614f69793227ccec90157708aea;hp=10699f097e2f5e6d9ca38892bd5d78a3aa5bff7e;hpb=96ab5904b059e00e78b26a6527790c8dc951e324;p=space.git diff --git a/src/graphics/Camera.h b/src/graphics/Camera.h index 10699f0..815b4b0 100644 --- a/src/graphics/Camera.h +++ b/src/graphics/Camera.h @@ -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 &); + Camera(Vector size, const Vector &); public: - void Resize(int w, int h); + void SetTarget(const Vector &t) { target = &t; } + void SetZoom(float z) { zoom = z; } - Vector Offset() { - return -(*target - offset); + Vector ScreenSize() const { return size; } + float Zoom() const { return zoom; } + + void Resize(int w, int h) { Resize(Vector(w, h)); } + void Resize(Vector); + void Update(float deltaT); + + void StartZoom(); + void StopZoom(); + void StartShrink(); + void StopShrink(); + + /// transform v from world coords to screen coords + Vector ToScreen(Vector v) const { + return Vector(ToScale(v - *target)) + offset; + } + /// scale v to current zoom level + Vector ToScale(Vector v) const { + return v * zoom; + } + + /// transform v from screen coords to world coords + Vector FromScreen(Vector v) const { + return FromScale(v - offset) + *target; + } + /// scale v back from current zoom level + Vector FromScale(Vector v) const { + return v / zoom; } private: const Vector *target; - Vector offset; + Vector size; + Vector offset; + + float zoom; + int zoomAcc; };