OpenClonk
C4BltTransform.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 #ifndef INC_C4BltTransform
18 #define INC_C4BltTransform
19 
20 // rotation info class
22 {
23 public:
24  float mat[9]; // transformation matrix
25 public:
26  C4BltTransform() = default; // default: don't init fields
27  void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
28  { mat[0]=fA; mat[1]=fB; mat[2]=fC; mat[3]=fD; mat[4]=fE; mat[5]=fF; mat[6]=fG; mat[7]=fH; mat[8]=fI; }
29  void SetRotate(float iAngle, float fOffX, float fOffY); // set by angle and rotation offset
30  bool SetAsInv(C4BltTransform &rOfTransform);
31  void Rotate(float Angle, float fOffX, float fOffY) // rotate by angle around rotation offset
32  {
33  // multiply matrix as seen in SetRotate by own matrix
34  C4BltTransform rot; rot.SetRotate(Angle, fOffX, fOffY);
35  (*this) *= rot;
36  }
37  void SetMoveScale(float dx, float dy, float sx, float sy)
38  {
39  mat[0] = sx; mat[1] = 0; mat[2] = dx;
40  mat[3] = 0; mat[4] = sy; mat[5] = dy;
41  mat[6] = 0; mat[7] = 0; mat[8] = 1;
42  }
43  void MoveScale(float dx, float dy, float sx, float sy)
44  {
45  // multiply matrix by movescale matrix
46  C4BltTransform move; move.SetMoveScale(dx,dy,sx,sy);
47  (*this) *= move;
48  }
49  void ScaleAt(float sx, float sy, float tx, float ty)
50  {
51  // scale and move back so tx and ty remain fixpoints
52  MoveScale(-tx*(sx-1), -ty*(sy-1), sx, sy);
53  }
55  {
56  // transform transformation
57  Set(mat[0]*r.mat[0] + mat[3]*r.mat[1] + mat[6]*r.mat[2],
58  mat[1]*r.mat[0] + mat[4]*r.mat[1] + mat[7]*r.mat[2],
59  mat[2]*r.mat[0] + mat[5]*r.mat[1] + mat[8]*r.mat[2],
60  mat[0]*r.mat[3] + mat[3]*r.mat[4] + mat[6]*r.mat[5],
61  mat[1]*r.mat[3] + mat[4]*r.mat[4] + mat[7]*r.mat[5],
62  mat[2]*r.mat[3] + mat[5]*r.mat[4] + mat[8]*r.mat[5],
63  mat[0]*r.mat[6] + mat[3]*r.mat[7] + mat[6]*r.mat[8],
64  mat[1]*r.mat[6] + mat[4]*r.mat[7] + mat[7]*r.mat[8],
65  mat[2]*r.mat[6] + mat[5]*r.mat[7] + mat[8]*r.mat[8]);
66  return *this;
67  }
68  void TransformPoint(float &rX, float &rY) const; // rotate point by angle
69 };
70 
71 #endif
int32_t Angle(int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2, int32_t iPrec)
Definition: Standard.cpp:37
void SetMoveScale(float dx, float dy, float sx, float sy)
void ScaleAt(float sx, float sy, float tx, float ty)
bool SetAsInv(C4BltTransform &rOfTransform)
void SetRotate(float iAngle, float fOffX, float fOffY)
C4BltTransform & operator*=(const C4BltTransform &r)
C4BltTransform()=default
void MoveScale(float dx, float dy, float sx, float sy)
void Rotate(float Angle, float fOffX, float fOffY)
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
void TransformPoint(float &rX, float &rY) const