ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

transform_tools.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 
00024 #include "graphics/transform_tools.h"
00025 #include "common/math.h"
00026 #include <math.h>
00027 
00028 namespace Graphics {
00029 
00030 FloatPoint TransformTools::transformPoint(FloatPoint point, const float rotate, const Common::Point &zoom, const bool mirrorX, const bool mirrorY) {
00031     float rotateRad = Common::deg2rad<float>(rotate);
00032     float x = point.x;
00033     float y = point.y;
00034     x = (x * zoom.x) / kDefaultZoomX;
00035     y = (y * zoom.y) / kDefaultZoomY;
00036 #if 0
00037     // TODO: Mirroring should be done before rotation, but the blitting
00038     // code does the inverse, so we match that for now.
00039     if (mirrorX)
00040         x *= -1;
00041     if (mirrorY)
00042         y *= -1;
00043 #endif
00044     FloatPoint newPoint;
00045     newPoint.x = x * cos(rotateRad) - y * sin(rotateRad);
00046     newPoint.y = x * sin(rotateRad) + y * cos(rotateRad);
00047     if (mirrorX) {
00048         newPoint.x *= -1;
00049     }
00050     if (mirrorY) {
00051         newPoint.y *= -1;
00052     }
00053     return newPoint;
00054 }
00055 
00056 Common::Rect TransformTools::newRect(const Common::Rect &oldRect, const TransformStruct &transform, Common::Point *newHotspot) {
00057     Common::Point nw(oldRect.left, oldRect.top);
00058     Common::Point ne(oldRect.right, oldRect.top);
00059     Common::Point sw(oldRect.left, oldRect.bottom);
00060     Common::Point se(oldRect.right, oldRect.bottom);
00061 
00062     FloatPoint nw1, ne1, sw1, se1;
00063 
00064     nw1 = transformPoint(nw - transform._hotspot, transform._angle, transform._zoom);
00065     ne1 = transformPoint(ne - transform._hotspot, transform._angle, transform._zoom);
00066     sw1 = transformPoint(sw - transform._hotspot, transform._angle, transform._zoom);
00067     se1 = transformPoint(se - transform._hotspot, transform._angle, transform._zoom);
00068 
00069     float top = MIN(nw1.y, MIN(ne1.y, MIN(sw1.y, se1.y)));
00070     float bottom = MAX(nw1.y, MAX(ne1.y, MAX(sw1.y, se1.y)));
00071     float left = MIN(nw1.x, MIN(ne1.x, MIN(sw1.x, se1.x)));
00072     float right = MAX(nw1.x, MAX(ne1.x, MAX(sw1.x, se1.x)));
00073 
00074     if (newHotspot) {
00075         newHotspot->y = (uint32)(-floor(top));
00076         newHotspot->x = (uint32)(-floor(left));
00077     }
00078 
00079     Common::Rect res;
00080     res.top = (int32)(floor(top)) + transform._hotspot.y;
00081     res.bottom = (int32)(ceil(bottom)) + transform._hotspot.y;
00082     res.left = (int32)(floor(left)) + transform._hotspot.x;
00083     res.right = (int32)(ceil(right)) + transform._hotspot.x;
00084 
00085     return res;
00086 }
00087 
00088 } // End of namespace Graphics


Generated on Sat Mar 23 2019 05:02:19 for ResidualVM by doxygen 1.7.1
curved edge   curved edge