OpenClonk
C4BltTransform Class Reference

#include <C4BltTransform.h>

Inheritance diagram for C4BltTransform:
[legend]

Public Member Functions

 C4BltTransform ()=default
 
void Set (float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
 
void SetRotate (float iAngle, float fOffX, float fOffY)
 
bool SetAsInv (C4BltTransform &rOfTransform)
 
void Rotate (float Angle, float fOffX, float fOffY)
 
void SetMoveScale (float dx, float dy, float sx, float sy)
 
void MoveScale (float dx, float dy, float sx, float sy)
 
void ScaleAt (float sx, float sy, float tx, float ty)
 
C4BltTransformoperator*= (const C4BltTransform &r)
 
void TransformPoint (float &rX, float &rY) const
 

Public Attributes

float mat [9]
 

Detailed Description

Definition at line 21 of file C4BltTransform.h.

Constructor & Destructor Documentation

◆ C4BltTransform()

C4BltTransform::C4BltTransform ( )
default

Member Function Documentation

◆ MoveScale()

void C4BltTransform::MoveScale ( float  dx,
float  dy,
float  sx,
float  sy 
)
inline

Definition at line 43 of file C4BltTransform.h.

44  {
45  // multiply matrix by movescale matrix
46  C4BltTransform move; move.SetMoveScale(dx,dy,sx,sy);
47  (*this) *= move;
48  }
void SetMoveScale(float dx, float dy, float sx, float sy)

References SetMoveScale().

Referenced by ScaleAt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator*=()

C4BltTransform& C4BltTransform::operator*= ( const C4BltTransform r)
inline

Definition at line 54 of file C4BltTransform.h.

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  }
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)

References mat, and Set().

Here is the call graph for this function:

◆ Rotate()

void C4BltTransform::Rotate ( float  Angle,
float  fOffX,
float  fOffY 
)
inline

Definition at line 31 of file C4BltTransform.h.

32  {
33  // multiply matrix as seen in SetRotate by own matrix
34  C4BltTransform rot; rot.SetRotate(Angle, fOffX, fOffY);
35  (*this) *= rot;
36  }
int32_t Angle(int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2, int32_t iPrec)
Definition: Standard.cpp:37
void SetRotate(float iAngle, float fOffX, float fOffY)

References Angle(), and SetRotate().

Referenced by C4Object::DrawActionFace(), and C4Object::DrawFace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScaleAt()

void C4BltTransform::ScaleAt ( float  sx,
float  sy,
float  tx,
float  ty 
)
inline

Definition at line 49 of file C4BltTransform.h.

50  {
51  // scale and move back so tx and ty remain fixpoints
52  MoveScale(-tx*(sx-1), -ty*(sy-1), sx, sy);
53  }
void MoveScale(float dx, float dy, float sx, float sy)

References MoveScale().

Referenced by C4GraphicsOverlay::Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set()

void C4BltTransform::Set ( float  fA,
float  fB,
float  fC,
float  fD,
float  fE,
float  fF,
float  fG,
float  fH,
float  fI 
)
inline

Definition at line 27 of file C4BltTransform.h.

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; }

References mat.

Referenced by C4Draw::BlitUnscaled(), operator*=(), C4DrawTransform::Set(), SetAsInv(), and C4DrawTransform::SetTransformAt().

Here is the caller graph for this function:

◆ SetAsInv()

bool C4BltTransform::SetAsInv ( C4BltTransform rOfTransform)

Definition at line 42 of file C4BltTransform.cpp.

43 {
44  // calc inverse of matrix
45  float det = r.mat[0]*r.mat[4]*r.mat[8] + r.mat[1]*r.mat[5]*r.mat[6]
46  + r.mat[2]*r.mat[3]*r.mat[7] - r.mat[2]*r.mat[4]*r.mat[6]
47  - r.mat[0]*r.mat[5]*r.mat[7] - r.mat[1]*r.mat[3]*r.mat[8];
48  if (!det) { Set(1,0,0,0,1,0,0,0,1); return false; }
49  mat[0] = (r.mat[4] * r.mat[8] - r.mat[5] * r.mat[7]) / det;
50  mat[1] = (r.mat[2] * r.mat[7] - r.mat[1] * r.mat[8]) / det;
51  mat[2] = (r.mat[1] * r.mat[5] - r.mat[2] * r.mat[4]) / det;
52  mat[3] = (r.mat[5] * r.mat[6] - r.mat[3] * r.mat[8]) / det;
53  mat[4] = (r.mat[0] * r.mat[8] - r.mat[2] * r.mat[6]) / det;
54  mat[5] = (r.mat[2] * r.mat[3] - r.mat[0] * r.mat[5]) / det;
55  mat[6] = (r.mat[3] * r.mat[7] - r.mat[4] * r.mat[6]) / det;
56  mat[7] = (r.mat[1] * r.mat[6] - r.mat[0] * r.mat[7]) / det;
57  mat[8] = (r.mat[0] * r.mat[4] - r.mat[1] * r.mat[3]) / det;
58  return true;
59 }

References mat, and Set().

Referenced by C4Draw::Blit8().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetMoveScale()

void C4BltTransform::SetMoveScale ( float  dx,
float  dy,
float  sx,
float  sy 
)
inline

Definition at line 37 of file C4BltTransform.h.

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  }

References mat.

Referenced by C4Draw::Blit8(), and MoveScale().

Here is the caller graph for this function:

◆ SetRotate()

void C4BltTransform::SetRotate ( float  iAngle,
float  fOffX,
float  fOffY 
)

Definition at line 21 of file C4BltTransform.cpp.

22 {
23  // iAngle is in degrees (cycling from 0 to 360)
24  // determine sine and cos of reversed angle in radians
25  // fAngle = -iAngle * pi/180 = iAngle * -pi/180
26  float fAngle = iAngle * -0.0174532925f;
27  float fsin = sinf(fAngle); float fcos = cosf(fAngle);
28  // set matrix values
29  mat[0] = +fcos; mat[1] = +fsin; mat[2] = (1-fcos)*fOffX - fsin*fOffY;
30  mat[3] = -fsin; mat[4] = +fcos; mat[5] = (1-fcos)*fOffY + fsin*fOffX;
31  mat[6] = 0; mat[7] = 0; mat[8] = 1;
32  /* calculation of rotation matrix:
33  x2 = fcos*(x1-fOffX) + fsin*(y1-fOffY) + fOffX
34  = fcos*x1 - fcos*fOffX + fsin*y1 - fsin*fOffY + fOffX
35  = x1*fcos + y1*fsin + (1-fcos)*fOffX - fsin*fOffY
36 
37  y2 = -fsin*(x1-fOffX) + fcos*(y1-fOffY) + fOffY
38  = x1*-fsin + fsin*fOffX + y1*fcos - fcos*fOffY + fOffY
39  = x1*-fsin + y1*fcos + fsin*fOffX + (1-fcos)*fOffY */
40 }

References mat.

Referenced by C4Object::DrawActionFace(), C4Object::DrawFace(), C4GUI::Element::DrawHBarByVGfx(), C4Facet::DrawXR(), and Rotate().

Here is the caller graph for this function:

◆ TransformPoint()

void C4BltTransform::TransformPoint ( float &  rX,
float &  rY 
) const

Definition at line 61 of file C4BltTransform.cpp.

62 {
63  // apply matrix
64  float fW = mat[6] * rX + mat[7] * rY + mat[8];
65  // store in temp, so original rX is used for calculation of rY
66  float fX = (mat[0] * rX + mat[1] * rY + mat[2]) / fW;
67  rY = (mat[3] * rX + mat[4] * rY + mat[5]) / fW;
68  rX = fX; // apply temp
69 }

References mat.

Referenced by C4Draw::Blit8().

Here is the caller graph for this function:

Member Data Documentation

◆ mat


The documentation for this class was generated from the following files: