OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4DrawTransform Class Reference

#include <C4Facet.h>

Inheritance diagram for C4DrawTransform:
[legend]
Collaboration diagram for C4DrawTransform:
[legend]

Public Member Functions

 C4DrawTransform (C4DrawTransform &rCopy, float iOffX, float iOffY)
 
 C4DrawTransform ()
 
 C4DrawTransform (int32_t iFlipDir)
 
 ~C4DrawTransform ()=default
 
void SetTransformAt (C4DrawTransform &rCopy, float iOffX, float iOffY)
 
void Set (float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
 
void SetFlipDir (int32_t iNewFlipDir)
 
bool IsIdentity () const
 
bool operator== (const C4DrawTransform &rCmp) const
 
C4DrawTransformoperator& ()
 
void CompileFunc (StdCompiler *pComp)
 
int32_t GetXOffset () const
 
int32_t GetYOffset () const
 
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

int32_t FlipDir
 
float mat [9]
 

Detailed Description

Definition at line 47 of file C4Facet.h.

Constructor & Destructor Documentation

C4DrawTransform::C4DrawTransform ( C4DrawTransform rCopy,
float  iOffX,
float  iOffY 
)
inline

Definition at line 52 of file C4Facet.h.

References SetTransformAt().

53  {
54  SetTransformAt(rCopy, iOffX, iOffY);
55  }
void SetTransformAt(C4DrawTransform &rCopy, float iOffX, float iOffY)
Definition: C4Facet.cpp:541

Here is the call graph for this function:

C4DrawTransform::C4DrawTransform ( )
inline

Definition at line 57 of file C4Facet.h.

58  {
59  // ctor without matrix initialization
60  FlipDir = 1;
61  }
int32_t FlipDir
Definition: C4Facet.h:50
C4DrawTransform::C4DrawTransform ( int32_t  iFlipDir)
inline

Definition at line 63 of file C4Facet.h.

References Set().

64  {
65  // ctor setting flipdir only
66  FlipDir = iFlipDir;
67  // set identity
68  Set(1,0,0,0,1,0,0,0,1);
69  }
int32_t FlipDir
Definition: C4Facet.h:50
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
Definition: C4Facet.h:76

Here is the call graph for this function:

C4DrawTransform::~C4DrawTransform ( )
default

Member Function Documentation

void C4DrawTransform::CompileFunc ( StdCompiler pComp)

Definition at line 482 of file C4Facet.cpp.

References StdStrBuf::Append(), StdStrBuf::AppendChar(), FlipDir, StdStrBuf::Format(), StdStrBuf::getData(), StdStrBuf::getMData(), StdCompiler::hasNaming(), StdCompiler::isDeserializer(), C4BltTransform::mat, mkParAdapt(), StdCompiler::RCT_Idtf, StdCompiler::SEP_PART, StdCompiler::Separator(), StdStrBuf::SetLength(), and StdCompiler::Value().

483 {
484  bool deserializing = pComp->isDeserializer();
485  int i;
486  // hacky. StdCompiler doesn't allow floats to be safed directly.
487  for (i = 0; i < 6; i++)
488  {
489  if (i) pComp->Separator();
490  StdStrBuf val;
491  if (!deserializing)
492  {
493 #ifdef WITH_GLIB
494  val.SetLength(G_ASCII_DTOSTR_BUF_SIZE);
495  // g_ascii_dtostr is locale-independent which printf is not.
496  g_ascii_dtostr(val.getMData(), G_ASCII_DTOSTR_BUF_SIZE, mat[i]);
497 #else
498  val.Format("%g", mat[i]);
499 #endif
500  }
501  pComp->Value(mkParAdapt(val, StdCompiler::RCT_Idtf));
502  if (deserializing && pComp->hasNaming())
503  if (pComp->Separator(StdCompiler::SEP_PART))
504  {
505  StdStrBuf val2;
506  pComp->Value(mkParAdapt(val2, StdCompiler::RCT_Idtf));
507  val.AppendChar('.'); val.Append(val2);
508  }
509 #ifdef WITH_GLIB
510  mat[i] = g_ascii_strtod (val.getData(), nullptr);
511 #else
512  if (deserializing) sscanf(val.getData(), "%g", &mat[i]);
513 #endif
514  }
515  pComp->Separator();
516  pComp->Value(FlipDir);
517  if (!deserializing && mat[6] == 0 && mat[7] == 0 && mat[8] == 1) return;
518  // because of backwards-compatibility, the last row comes after flipdir
519  for (i = 6; i < 9; ++i)
520  {
521  if (!pComp->Separator())
522  {
523  mat[i] = (i == 8) ? 1.0f : 0.0f;
524  }
525  else
526  {
527  StdStrBuf val; if (!deserializing) val.Format("%g", mat[i]);
528  pComp->Value(mkParAdapt(val, StdCompiler::RCT_Idtf));
529  if (deserializing && pComp->hasNaming())
530  if (pComp->Separator(StdCompiler::SEP_PART))
531  {
532  StdStrBuf val2;
533  pComp->Value(mkParAdapt(val2, StdCompiler::RCT_Idtf));
534  val.AppendChar('.'); val.Append(val2);
535  }
536  if (deserializing) sscanf(val.getData(), "%g", &mat[i]);
537  }
538  }
539 }
const char * getData() const
Definition: StdBuf.h:442
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
virtual bool hasNaming()
Definition: StdCompiler.h:58
int32_t FlipDir
Definition: C4Facet.h:50
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
char * getMData()
Definition: StdBuf.h:443
void AppendChar(char cChar)
Definition: StdBuf.h:588
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
void SetLength(size_t iLength)
Definition: StdBuf.h:509

Here is the call graph for this function:

int32_t C4DrawTransform::GetXOffset ( ) const
inline

Definition at line 109 of file C4Facet.h.

References C4BltTransform::mat.

Referenced by C4GraphicsOverlay::Draw().

109 { return static_cast<int32_t>(mat[2]); }

Here is the caller graph for this function:

int32_t C4DrawTransform::GetYOffset ( ) const
inline

Definition at line 110 of file C4Facet.h.

References C4BltTransform::mat.

Referenced by C4GraphicsOverlay::Draw().

110 { return static_cast<int32_t>(mat[5]); }

Here is the caller graph for this function:

bool C4DrawTransform::IsIdentity ( ) const
inline

Definition at line 90 of file C4Facet.h.

References C4BltTransform::mat.

Referenced by C4Object::UpdateFlipDir().

91  {
92  return (mat[0]==1.0f) && (mat[1]==0.0f) && (mat[2]==0.0f)
93  && (mat[3]==0.0f) && (mat[4]==1.0f) && (mat[5]==0.0f)
94  && (mat[6]==0.0f) && (mat[7]==0.0f) && (mat[8]==1.0f)
95  && (FlipDir==1); // flipdir must be 1, because otherwise matrices flipped by action+script would be removed
96  }
int32_t FlipDir
Definition: C4Facet.h:50

Here is the caller graph for this function:

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

Definition at line 43 of file C4BltTransform.h.

References C4BltTransform::SetMoveScale().

Referenced by C4BltTransform::ScaleAt().

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)

Here is the call graph for this function:

Here is the caller graph for this function:

C4DrawTransform* C4DrawTransform::operator& ( )
inline

Definition at line 105 of file C4Facet.h.

105 { return this; }
C4BltTransform& C4BltTransform::operator*= ( const C4BltTransform r)
inlineinherited

Definition at line 54 of file C4BltTransform.h.

References C4BltTransform::mat, and C4BltTransform::Set().

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)

Here is the call graph for this function:

bool C4DrawTransform::operator== ( const C4DrawTransform rCmp) const
inline

Definition at line 99 of file C4Facet.h.

References FlipDir, and C4BltTransform::mat.

100  {
101  return (mat[0]==rCmp.mat[0]) && (mat[1]==rCmp.mat[1]) && (mat[2]==rCmp.mat[2])
102  && (mat[3]==rCmp.mat[3]) && (mat[4]==rCmp.mat[4]) && (mat[5]==rCmp.mat[5])
103  && (mat[6]==rCmp.mat[6]) && (mat[7]==rCmp.mat[7]) && (mat[8]==rCmp.mat[8]) && (FlipDir == rCmp.FlipDir);
104  }
int32_t FlipDir
Definition: C4Facet.h:50
void C4BltTransform::Rotate ( float  Angle,
float  fOffX,
float  fOffY 
)
inlineinherited

Definition at line 31 of file C4BltTransform.h.

References C4BltTransform::SetRotate().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 49 of file C4BltTransform.h.

References C4BltTransform::MoveScale().

Referenced by C4GraphicsOverlay::Draw().

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)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 76 of file C4Facet.h.

References C4BltTransform::Set().

Referenced by C4DrawTransform(), and CStdFont::DrawText().

77  {
78  // set values; apply flipdir
79  C4BltTransform::Set(fA*FlipDir, fB, fC, fD, fE, fF, fG, fH, fI);
80  }
int32_t FlipDir
Definition: C4Facet.h:50
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4BltTransform::SetAsInv ( C4BltTransform rOfTransform)
inherited

Definition at line 42 of file C4BltTransform.cpp.

References C4BltTransform::mat, and C4BltTransform::Set().

Referenced by C4Draw::Blit8().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4DrawTransform::SetFlipDir ( int32_t  iNewFlipDir)
inline

Definition at line 82 of file C4Facet.h.

References C4BltTransform::mat.

Referenced by C4Object::UpdateFlipDir().

83  {
84  // no change?
85  if (iNewFlipDir == FlipDir) return;
86  // set and apply in matrix
87  FlipDir = iNewFlipDir; mat[0] = -mat[0];
88  }
int32_t FlipDir
Definition: C4Facet.h:50

Here is the caller graph for this function:

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

Definition at line 37 of file C4BltTransform.h.

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

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  }

Here is the caller graph for this function:

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

Definition at line 21 of file C4BltTransform.cpp.

References C4BltTransform::mat.

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

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 }

Here is the caller graph for this function:

void C4DrawTransform::SetTransformAt ( C4DrawTransform rCopy,
float  iOffX,
float  iOffY 
)

Definition at line 541 of file C4Facet.cpp.

References C4BltTransform::mat, and C4BltTransform::Set().

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

542 {
543  // Set matrix, so that r*(x,y,1)-(x,y,1)==this*(x+iOffX,y+iOffY,1)-(x+iOffX,y+iOffY,1)
544  float A = r.mat[0] + r.mat[6]*iOffX;
545  float B = r.mat[1] + r.mat[7]*iOffX;
546  float D = r.mat[3] + r.mat[6]*iOffY;
547  float E = r.mat[4] + r.mat[7]*iOffY;
549  A, B, r.mat[2] - A *iOffX - B *iOffY + r.mat[8]*iOffX,
550  D, E, r.mat[5] - D *iOffX - E *iOffY + r.mat[8]*iOffY,
551  r.mat[6], r.mat[7], r.mat[8] - r.mat[6]*iOffX - r.mat[7]*iOffY);
552 }
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 61 of file C4BltTransform.cpp.

References C4BltTransform::mat.

Referenced by C4Draw::Blit8().

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 }

Here is the caller graph for this function:

Member Data Documentation

int32_t C4DrawTransform::FlipDir

Definition at line 50 of file C4Facet.h.

Referenced by CompileFunc(), and operator==().


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