ScreenProjection::ScreenProjection() : _PanLat(MapWindow::GetPanLatitude()), _PanLon(MapWindow::GetPanLongitude()), _Zoom(MapWindow::GetDrawScale()), _Angle(MapWindow::GetDisplayAngle()), _Origin(MapWindow::GetOrigScreen()), _CosAngle(ifastcosine(MapWindow::GetDisplayAngle())), _SinAngle(ifastsine(MapWindow::GetDisplayAngle())) { }
void protateshift(POINT &pin, const double &angle, const int &xs, const int &ys) { int x= pin.x; int y= pin.y; static double lastangle = 0; static int cost=1024,sint=0; if(angle != lastangle) { lastangle = angle; cost = ifastcosine(angle); sint = ifastsine(angle); } pin.x = (x*cost - y*sint + 512 + (xs*1024))/1024; pin.y = (y*cost + x*sint + 512 + (ys*1024))/1024; }
void irotate(int &xin, int &yin, const double &angle) { int x= xin; int y= yin; static double lastangle = 0; static int cost=1024,sint=0; if(angle != lastangle) { lastangle = angle; cost = ifastcosine(angle); sint = ifastsine(angle); } xin = (x*cost - y*sint + 512)/1024; yin = (y*cost + x*sint + 512)/1024; }
void irotatescale(int &xin, int &yin, const double &angle, const double &scale, double &x, double &y) { static double lastangle = 0; static double lastscale = 0; static int cost=1024,sint=0; if((angle != lastangle)||(scale != lastscale)) { lastscale = scale/1024; lastangle = angle; cost = ifastcosine(angle); sint = ifastsine(angle); } x = (xin*cost - yin*sint + 512)*lastscale; y = (yin*cost + xin*sint + 512)*lastscale; }
void threadsafePolygonRotateShift(POINT* poly, const int n, const int xs, const int ys, const double angle) { const int cost = ifastcosine(angle)*ScreenScale; const int sint = ifastsine(angle)*ScreenScale; const int xxs = xs*1024+512; const int yys = ys*1024+512; POINT *p = poly; const POINT *pe = poly+n; while (p<pe) { int x= p->x; int y= p->y; p->x = (x*cost - y*sint + xxs)/1024; p->y = (y*cost + x*sint + yys)/1024; p++; } }
void protate(POINT &pin, const double &angle) { int x= pin.x; int y= pin.y; static double lastangle = 0; static int cost=1024,sint=0; if(angle != lastangle) { lastangle = angle; cost = ifastcosine(angle); sint = ifastsine(angle); } pin.x = (x*cost - y*sint + 512 )/1024; pin.y = (y*cost + x*sint + 512 )/1024; // round (x/b) = (x+b/2)/b; // b = 2; x = 10 -> (10+1)/2=5 // b = 2; x = 11 -> (11+1)/2=6 // b = 2; x = -10 -> (-10+1)/2=4 }
// // This function must be reinitialised on resolution change // THIS FUNCTION IS NOT THREAD SAFE AND CANNOT BE USED OUTSIDE DRAW THREAD // void PolygonRotateShift(POINT* poly, const int n, const int xs, const int ys, const double angle) { static double lastangle = -1; static int cost=1024, sint=0; if(angle != lastangle) { lastangle = angle; cost = ifastcosine(angle)*ScreenScale; sint = ifastsine(angle)*ScreenScale; } const int xxs = xs*1024+512; const int yys = ys*1024+512; POINT *p = poly; const POINT *pe = poly+n; while (p<pe) { int x= p->x; int y= p->y; p->x = (x*cost - y*sint + xxs)/1024; p->y = (y*cost + x*sint + yys)/1024; p++; } }