X-Git-Url: http://git.localhorst.tv/?p=space.git;a=blobdiff_plain;f=src%2Fgraphics%2FCamera.h;h=e40b051bc64d78c18479fdbcac6f276049a0e830;hp=10699f097e2f5e6d9ca38892bd5d78a3aa5bff7e;hb=2d0a41dc0a53915153ceccda914d59affd388864;hpb=3f4f8a92f64df08119a40da4d196b3e92ecdc637 diff --git a/src/graphics/Camera.h b/src/graphics/Camera.h index 10699f0..e40b051 100644 --- a/src/graphics/Camera.h +++ b/src/graphics/Camera.h @@ -12,16 +12,37 @@ public: Camera(int w, int h, const Vector &); public: + void SetTarget(const Vector &t) { target = &t; } + void SetZoom(float z) { zoom = z; } + void Resize(int w, int h); + void Update(float deltaT); + + void DoubleZoom(); + void HalfZoom(); - Vector Offset() { - return -(*target - offset); + Vector ToScreen(Vector v) const { + return Vector(OffsetOf(v)); + } + Vector OffsetOf(Vector v) const { + return ToScale(v - *target) + offset; + } + Vector ToScale(Vector v) const { + if (zoom == 0) { + return v; + } else if (zoom > 0) { + return v * float(1 << zoom); + } else { + return v / float(1 << -zoom); + } } private: const Vector *target; Vector offset; + int zoom; + }; }