#pragma once #include "base.h" #include "point.h" // represents the point of view class Eye { public: Eye(); ~Eye() {} void ReadConfig(const char* spec, bool ring); void Init(const Point& p, double right, double down, double clockwise, double zoom); void RotateRight(double x); // spin right, in radians void RotateDown(double x); // spin down, in radians void Clockwise(double x); // spin clockwise, in radians void ShiftRight(int n); // shift the center right by n pixels void ShiftDown(int n); // shift the center down by n pixels void Center(const Point& p) { _m[3] = p; } // move the viewpoint to the center void Move(const Point& p) { _m[4] += p; } // move the viewpoint to p void AdjustZoom(double zoom) { _zoom *= zoom; } double GetZoom() { return _zoom; } Point Map(const Point& p); // map a point from the eye's perspective Point MapRing(const Point& p); // map a point from the eye's perspective, as a cross-section of a ring int MapX(const Point& p) { return _centerX + (int)(_zoom*(p._x/p._z)); } // x pixel to draw this point at int MapY(const Point& p) { return _centerY + (int)(_zoom*(p._y/p._z)); } // y pixel to draw this point at double MapRadius(double r, const Point& p) { return p._z > 0.0 ? _zoom * r / p._z : 0.0; } void SetWidth(int x) { _maxX = x; _centerX = x/2; } void SetHeight(int y) { _maxY = y; _centerY = y/2; } int Width() { return _maxX; } int Height() { return _maxY; } int CenterX() { return _centerX; } int CenterY() { return _centerY; } private: void Rotate(const double (&d)[3][3]); // rotate m[][] by d int _centerX; // center x pixel int _centerY; // center y pixel int _maxX; // total width of screen int _maxY; // total height of screen double _zoom; // magnification of image Point _m[5]; // [0][1][2] form the matrix of rotation, m[3] is prerotate offset, m[4] is postrotate offset };