1 /****************************************************************************** 2 * Warmux is a convivial mass murder game. 3 * Copyright (C) 2001-2011 Warmux Team. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 ****************************************************************************** 19 * 2D Affine Transformation. 20 *****************************************************************************/ 21 22 #ifndef AFFINE_TRANSFORM_2D 23 #define AFFINE_TRANSFORM_2D 24 25 #include <WARMUX_types.h> 26 #include <stdio.h> 27 #include <WARMUX_point.h> 28 29 class AffineTransform2D { 30 protected: 31 // The matrix 32 Double x1, x2, xt; 33 Double y1, y2, yt; 34 Double w1, w2, wt; 35 public: 36 AffineTransform2D(); 37 void Init(); 38 void Set(const AffineTransform2D &mat); 39 void SetRotation(Double rad_angle); 40 void SetTranslation(Double trans_x, Double trans_y); 41 void SetTranslation(const Point2i & position); 42 void SetTranslation(const Point2d & position); 43 void SetShrink(Double shrink_x, Double shrink_y); 44 void SetShear(Double shear_x, Double shear_y); 45 void SetTranslationAnimation(int start_time, int duration, int time, bool invert, const Point2d & start, const Point2d & end); 46 void SetRotationAnimation(int start_time, int duration, int time, bool invert, Double angle_start, Double angle_end = 0.0); 47 void SetShrinkAnimation(int start_time, int duration, int time, bool invert, Double shrink_x_start, Double shrink_y_start, 48 Double shrink_x_end = 1.0, Double shrink_y_end = 1.0); 49 void SetShearAnimation(int start_time, int duration, int time, bool invert, Double shear_tremor, 50 Double shear_x_start, Double shear_y_start, 51 Double shear_x_end = 0.0, Double shear_y_end = 0.0); 52 /* Matrix multiplication */ 53 AffineTransform2D operator*(const AffineTransform2D &mat) const; 54 Point2i operator*(const Point2i& p) const; 55 Point2d operator*(const Point2d& p) const; 56 // Creation of instance 57 static AffineTransform2D Rotate(Double rad_angle); 58 static AffineTransform2D Translate(Double trans_x, Double trans_y); 59 static AffineTransform2D Shrink(Double shrink_x, Double shrink_y); 60 static AffineTransform2D Shear(Double shear_x, Double shear_y); 61 }; 62 63 #endif /* AFFINE_TRANSFORM_2D */ 64