#ifndef SPACE_CAMERA_H_
#define SPACE_CAMERA_H_
-#include "../math/Vector.h"
+#include "Vector.h"
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;
};