21 #ifndef GF_TRANSFORM_H 22 #define GF_TRANSFORM_H 27 #include "Portability.h" 32 #ifndef DOXYGEN_SHOULD_SKIP_THIS 51 : cos(1.0f), sin(0.0f)
61 : cos(
std::cos(angle)), sin(
std::sin(angle))
71 cos = std::cos(angle);
72 sin = std::sin(angle);
81 return std::atan2(sin, cos);
96 rotation.
cos * point.x - rotation.
sin * point.y,
97 rotation.
sin * point.x + rotation.
cos * point.y
112 rotation.
cos * point.x + rotation.
sin * point.y,
113 -rotation.
sin * point.x + rotation.
cos * point.y
141 : offset(translationOffset)
174 return { point.x + translation.
offset.x, point.y + translation.
offset.y };
187 return { point.x - translation.
offset.x, point.y - translation.
offset.y };
220 : rotation(angle), translation(offset)
244 : translation(offset)
324 return { mat.xx * point.x + mat.xy * point.y + mat.xz, mat.yx * point.x + mat.yy * point.y + mat.yz };
347 return Matrix3f(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
360 1.0f, 0.0f, offset.x,
361 0.0f, 1.0f, offset.y,
384 float cos = std::cos(angle);
385 float sin = std::sin(angle);
403 float cos = std::cos(angle);
404 float sin = std::sin(angle);
406 cos, -sin, center.x * (1 - cos) + center.y * sin,
407 sin, cos, center.y * (1 - cos) - center.x * sin,
441 factor.x, 0.0f, 0.0f,
442 0.0f, factor.y, 0.0f,
458 factor.x, 0.0f, center.x * (1.0f - factor.x),
459 0.0f, factor.y, center.y * (1.0f - factor.y),
483 #ifndef DOXYGEN_SHOULD_SKIP_THIS 488 #endif // GF_TRANSFORM_H constexpr Vector2f inverseTransform(const Translation &translation, Vector2f point)
Apply an inverse translation to a 2D point.
Definition: Transform.h:186
Rotation(float angle)
Constructor with an angle.
Definition: Transform.h:60
void scale(Matrix3f &mat, Vector2f factor)
Combine the current transform with a scaling.
void setOffset(Vector2f newOffset) noexcept
Set the translation offset.
Definition: Transform.h:150
float getAngle() const
Get the rotation angle.
Definition: Transform.h:80
constexpr Vector2f transform(const Matrix3f &mat, Vector2f point)
Apply an affine transformation to a 2D point.
Definition: Transform.h:323
Vector2f offset
The offset of the translation.
Definition: Transform.h:123
Matrix3f scaling(Vector2f factor)
Get a scaling matrix.
Definition: Transform.h:439
Matrix< float, 3, 3 > Matrix3f
A float square matrix of size 3.
Definition: Matrix.h:630
constexpr Vector2f transform(const Rotation &rotation, Vector2f point)
Apply a rotation to a 2D point.
Definition: Transform.h:94
float sin
The sine of the rotation angle.
Definition: Transform.h:43
A translation.
Definition: Transform.h:122
constexpr Vector2f transform(const Translation &translation, Vector2f point)
Apply a translation to a 2D point.
Definition: Transform.h:173
Translation()
Default constructor.
Definition: Transform.h:130
Vector2f getOffset() const noexcept
Get the translation offset.
Definition: Transform.h:159
General purpose math matrix.
Definition: Matrix.h:60
Translation(Vector2f translationOffset)
Constructor with an offset.
Definition: Transform.h:140
The namespace for gf classes.
Definition: Action.h:35
Matrix3f rotation(float angle)
Get a rotation matrix.
Definition: Transform.h:383
float angle(Direction direction)
Get an angle from a direction.
void rotate(Matrix3f &mat, float angle)
Combine the current transform with a rotation.
Matrix3f translation(Vector2f offset)
Get a translation matrix.
Definition: Transform.h:358
void translate(Matrix3f &mat, Vector2f offset)
Combine the current transform with a translation.
constexpr Vector2f inverseTransform(const Rotation &rotation, Vector2f point)
Apply an inverse rotation to a 2D point.
Definition: Transform.h:110
void setAngle(float angle)
Set the rotation angle.
Definition: Transform.h:70
A rotation.
Definition: Transform.h:41
Rotation()
Default constructor.
Definition: Transform.h:50
constexpr Matrix3f identityTransform()
Identity transform.
Definition: Transform.h:346
float cos
The cosine of the rotation angle.
Definition: Transform.h:42