CUGL 2.0
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cugl::Affine2 Class Reference

#include <CUAffine2.h>

Public Member Functions

 Affine2 ()
 
 Affine2 (float m11, float m12, float m21, float m22, float tx, float ty)
 
 Affine2 (const float *mat)
 
 Affine2 (const Affine2 &copy)
 
 Affine2 (Affine2 &&copy)
 
 ~Affine2 ()
 
Affine2operator= (const Affine2 &mat)
 
Affine2operator= (Affine2 &&mat)
 
Affine2operator= (const float *array)
 
Affine2set (float m11, float m12, float m21, float m22, float tx, float ty)
 
Affine2set (const float *mat)
 
Affine2set (const float *mat, size_t stride)
 
Affine2set (const Affine2 &mat)
 
Affine2setIdentity ()
 
Affine2setZero ()
 
Affine2multiply (const Mat4 &m1, const Affine2 &m2, Affine2 *dst)
 
Affine2add (const Vec2 v)
 
Affine2subtract (const Vec2 v)
 
Affine2multiply (float scalar)
 
Affine2multiply (const Affine2 &aff)
 
Affine2multiply (const Mat4 &mat)
 
Affine2invert ()
 
Affine2 getInverse () const
 
Affine2operator+= (const Vec2 v)
 
Affine2operator-= (const Vec2 v)
 
Affine2operator*= (float scalar)
 
Affine2operator*= (const Mat4 &mat)
 
Affine2operator*= (const Affine2 &aff)
 
Affine2 operator+ (const Vec2 v) const
 
Affine2 operator- (const Vec2 v) const
 
Affine2 operator* (float scalar) const
 
Affine2 operator* (const Affine2 &aff) const
 
Affine2 operator* (const Mat4 &mat) const
 
bool isExactly (const Affine2 &aff) const
 
bool equals (const Affine2 &mat, float variance=CU_MATH_EPSILON) const
 
bool operator== (const Affine2 &aff) const
 
bool operator!= (const Affine2 &aff) const
 
float * get3x3 (float *array) const
 
float * get3x4 (float *array) const
 
float * get4x4 (float *array) const
 
float * get (float *array, size_t stride=2) const
 
bool isIdentity (float variance=0.0f) const
 
bool isInvertible (float variance=CU_MATH_EPSILON) const
 
float getDeterminant () const
 
Vec2 getScale () const
 
float getRotation () const
 
Vec2 getTranslation () const
 
Vec2 transform (const Vec2 point) const
 
Rect transform (const Rect rect) const
 
Affine2rotate (float angle)
 
Affine2scale (float value)
 
Affine2scale (const Vec2 s)
 
Affine2scale (float sx, float sy)
 
Affine2translate (const Vec2 t)
 
Affine2translate (float tx, float ty)
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Mat4 () const
 
 Affine2 (const Mat4 &mat)
 
Affine2operator= (const Mat4 &mat)
 
Affine2set (const Mat4 &mat)
 

Static Public Member Functions

static Affine2 createScale (float scale)
 
static Affine2createScale (float scale, Affine2 *dst)
 
static Affine2 createScale (float sx, float sy)
 
static Affine2createScale (float sx, float sy, Affine2 *dst)
 
static Affine2 createScale (const Vec2 scale)
 
static Affine2createScale (const Vec2 scale, Affine2 *dst)
 
static Affine2 createRotation (float angle)
 
static Affine2createRotation (float angle, Affine2 *dst)
 
static Affine2 createTranslation (const Vec2 trans)
 
static Affine2createTranslation (const Vec2 trans, Affine2 *dst)
 
static Affine2 createTranslation (float tx, float ty)
 
static Affine2createTranslation (float tx, float ty, Affine2 *dst)
 
static Affine2add (const Affine2 &m, const Vec2 v, Affine2 *dst)
 
static float * add (const float *m, const Vec2 v, float *dst, size_t stride=2)
 
static Affine2subtract (const Affine2 &m1, const Vec2 v, Affine2 *dst)
 
static float * subtract (const float *m1, const Vec2 v, float *dst, size_t stride=2)
 
static Affine2multiply (const Affine2 &mat, float scalar, Affine2 *dst)
 
static float * multiply (const float *mat, float scalar, float *dst, size_t stride=2)
 
static Affine2multiply (const Affine2 &m1, const Affine2 &m2, Affine2 *dst)
 
static Affine2multiply (const Affine2 &m1, const Mat4 &m2, Affine2 *dst)
 
static float * multiply (const float *m1, const float *m2, float *dst, size_t stride=2)
 
static Affine2invert (const Affine2 &m1, Affine2 *dst)
 
static float * invert (const float *m1, float *dst, size_t stride=2)
 
static Vec2transform (const Affine2 &aff, const Vec2 point, Vec2 *dst)
 
static float * transform (const Affine2 &aff, float const *input, float *output, size_t size)
 
static Recttransform (const Affine2 &aff, const Rect rect, Rect *dst)
 
static Affine2identify (float *dst, size_t stride=2)
 
static Affine2rotate (const Affine2 &aff, float angle, Affine2 *dst)
 
static float * rotate (const float *aff, float angle, float *dst, size_t stride=2)
 
static Affine2scale (const Affine2 &aff, float value, Affine2 *dst)
 
static float * scale (const float *aff, float value, float *dst, size_t stride=2)
 
static Affine2scale (const Affine2 &aff, const Vec2 s, Affine2 *dst)
 
static float * scale (const float *aff, const Vec2 s, float *dst, size_t stride=2)
 
static Affine2scale (const Affine2 &aff, float sx, float sy, Affine2 *dst)
 
static float * scale (const float *aff, float sx, float sy, float *dst, size_t stride=2)
 
static Affine2translate (const Affine2 &aff, const Vec2 t, Affine2 *dst)
 
static float * translate (const float *aff, const Vec2 t, float *dst, size_t stride=2)
 
static Affine2translate (const Affine2 &aff, float tx, float ty, Affine2 *dst)
 
static float * translate (const float *aff, float tx, float ty, float *dst, size_t stride=2)
 
static bool decompose (const Affine2 &mat, Vec2 *scale, float *rot, Vec2 *trans)
 

Public Attributes

float m [6]
 

Static Public Attributes

static const Affine2 ZERO
 
static const Affine2 ONE
 
static const Affine2 IDENTITY
 

Detailed Description

This class defines an affine transform on 2D space.

In the case where you are only manipulating 2D points, this class may be faster than Mat4, even with the vectorization support. For an affine transform in 3d space, use Mat4.

An affine transform is represeted by 3x2 matrix in column major order, keeping with the convention of Mat4. The last column is the translation offset. In addition, we assume that all operations are multiplied on the right.

Because of OpenGL alignment issues, an affine transform typically needs to be converted to a 3x3 matrix (for Shader or a 3x4 matrix (for a UniformBuffer). For that reason this class contains several static methods for processing float arrays of different strides. These methods interpret stride pairwise. For example, a stride of 4 corresponds to a 3x4 matrix with the first two elements at position 0 and 1, the next two at 4 and 5, and the last two at 8 and 9.

While an affine transform corresponds to a 3x3 matrix in homongeneous coordinates, this class is not an arbitrary Mat3 class. It enforces that its contents are always an affine transform.

Constructor & Destructor Documentation

◆ Affine2() [1/6]

cugl::Affine2::Affine2 ( )

Creates the identity transform.

1  0  0
0  1  0

◆ Affine2() [2/6]

cugl::Affine2::Affine2 ( float  m11,
float  m12,
float  m21,
float  m22,
float  tx,
float  ty 
)

Constructs a matrix initialized to the specified values.

Parameters
m11The first element of the first row.
m12The second element of the first row.
m21The first element of the second row.
m22The second element of the second row.
txThe translation offset for the x-coordinate.
tyThe translation offset for the y-coordinate.

◆ Affine2() [3/6]

cugl::Affine2::Affine2 ( const float *  mat)

Creates a matrix initialized to the specified column-major array.

The passed-in array is six elements in column-major order, with the last two elements being the translation offset. Hence the memory layout of the array is as follows:

0   2   4
1   3   5
Parameters
matAn array containing 6 elements in column-major order.

◆ Affine2() [4/6]

cugl::Affine2::Affine2 ( const Affine2 copy)

Constructs a new transform that is the copy of the specified one.

Parameters
copyThe transform to copy.

◆ Affine2() [5/6]

cugl::Affine2::Affine2 ( Affine2 &&  copy)

Constructs a new transform that contains the resources of the specified one.

Parameters
copyThe transform contributing resources.

◆ ~Affine2()

cugl::Affine2::~Affine2 ( )
inline

Destroys this transform, releasing all resources.

◆ Affine2() [6/6]

cugl::Affine2::Affine2 ( const Mat4 mat)
explicit

Creates an affine transform from the given matrix.

The z values are all uniformly ignored. However, it the final element of the matrix is not 1 (e.g. the translation has a w value of 1), then it divides the entire matrix before creating the affine transform

Parameters
matThe matrix to convert

Member Function Documentation

◆ add() [1/3]

static Affine2* cugl::Affine2::add ( const Affine2 m,
const Vec2  v,
Affine2 dst 
)
static

Adds the specified offset to the given and stores the result in dst.

Addition is applied to the offset only; the core matrix is unchanged.

Parameters
mThe initial transform.
vThe offset to add.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ add() [2/3]

static float* cugl::Affine2::add ( const float *  m,
const Vec2  v,
float *  dst,
size_t  stride = 2 
)
static

Adds the specified offset to the given and stores the result in dst.

Addition is applied to the offset only; the core matrix is unchanged. Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

Parameters
mThe initial transform in column major order
vThe offset to add.
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ add() [3/3]

Affine2& cugl::Affine2::add ( const Vec2  v)
inline

Adds the specified offset to this transform.

Addition is applied to the offset only; the core matrix is unchanged.

Parameters
vThe offset to add.
Returns
A reference to the Affine2 after addition.

◆ createRotation() [1/2]

static Affine2 cugl::Affine2::createRotation ( float  angle)
inlinestatic

Returns a rotation transform for the given angle.

The angle measurement is in radians. The rotation is counter clockwise about the z-axis.

Parameters
angleThe angle (in radians).
Returns
a rotation transform for the given angle.

◆ createRotation() [2/2]

static Affine2* cugl::Affine2::createRotation ( float  angle,
Affine2 dst 
)
static

Creates a rotation transform for the given angle, putting it in dst.

The angle measurement is in radians. The rotation is counter clockwise about the z-axis.

Parameters
angleThe angle (in radians).
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ createScale() [1/6]

static Affine2 cugl::Affine2::createScale ( const Vec2  scale)
inlinestatic

Returns a nonuniform scale transform from the given vector.

Parameters
scaleThe nonuniform scale value.
Returns
a nonuniform scale transform from the given vector.

◆ createScale() [2/6]

static Affine2* cugl::Affine2::createScale ( const Vec2  scale,
Affine2 dst 
)
static

Creates a nonuniform scale transform from the given vector, putting it in dst.

Parameters
scaleThe nonuniform scale value.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ createScale() [3/6]

static Affine2 cugl::Affine2::createScale ( float  scale)
inlinestatic

Returns a uniform scale transform.

Parameters
scaleThe amount to scale.
Returns
a uniform scale transform.

◆ createScale() [4/6]

static Affine2* cugl::Affine2::createScale ( float  scale,
Affine2 dst 
)
static

Creates a uniform scale transform, putting it in dst.

Parameters
scaleThe amount to scale.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ createScale() [5/6]

static Affine2 cugl::Affine2::createScale ( float  sx,
float  sy 
)
inlinestatic

Returns a nonuniform scale transform.

Parameters
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
Returns
a nonuniform scale transform.

◆ createScale() [6/6]

static Affine2* cugl::Affine2::createScale ( float  sx,
float  sy,
Affine2 dst 
)
static

Creates a nonuniform scale transform, putting it in dst.

Parameters
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ createTranslation() [1/4]

static Affine2 cugl::Affine2::createTranslation ( const Vec2  trans)
inlinestatic

Returns a translation transform from the given offset

Parameters
transThe translation offset.
Returns
a translation transform from the given offset

◆ createTranslation() [2/4]

static Affine2* cugl::Affine2::createTranslation ( const Vec2  trans,
Affine2 dst 
)
static

Creates a translation transform from the given offset, putting it in dst.

Parameters
transThe translation offset.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ createTranslation() [3/4]

static Affine2 cugl::Affine2::createTranslation ( float  tx,
float  ty 
)
inlinestatic

Returns a translation transform from the given parameters.

Parameters
txThe translation on the x-axis.
tyThe translation on the y-axis.
Returns
a translation transform from the given parameters.

◆ createTranslation() [4/4]

static Affine2* cugl::Affine2::createTranslation ( float  tx,
float  ty,
Affine2 dst 
)
static

Creates a translation transform from the given parameters, putting it in dst.

Parameters
txThe translation on the x-axis.
tyThe translation on the y-axis.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ decompose()

static bool cugl::Affine2::decompose ( const Affine2 mat,
Vec2 scale,
float *  rot,
Vec2 trans 
)
static

Decomposes the scale, rotation and translation components of the given matrix.

To work properly, the matrix must have been constructed in the following order: scale, then rotate, then translation. While the rotation matrix will always be correct, the scale and translation are not guaranteed to be correct if this is violated.

If any pointer is null, the method simply does not assign that result. However, it will still continue to compute the component with non-null vectors to store the result.

If the scale component is too small, then it may be impossible to extract the rotation. In that case, if the rotation pointer is not null, this method will return false.

Parameters
matThe transform to decompose.
scaleThe scale component.
rotThe rotation component.
transThe translation component.
Returns
true if all requested components were properly extracted

◆ equals()

bool cugl::Affine2::equals ( const Affine2 mat,
float  variance = CU_MATH_EPSILON 
) const

Returns true if the transforms are within tolerance of each other.

The tolerance is applied to each element of the transform individually.

Parameters
matThe transform to compare against.
varianceThe comparison tolerance.
Returns
true if the transforms are within tolerance of each other.

◆ get()

float* cugl::Affine2::get ( float *  array,
size_t  stride = 2 
) const

Reads the affine transform as an array with the given stride

The float array should have at least 6-elements where each of the three pairs have the given stride. Postions outside of the 6 element core are left untouched.

Parameters
arrayThe array to store the values
strideThe pairwise data stride
Returns
a reference to the array for chaining

◆ get3x3()

float* cugl::Affine2::get3x3 ( float *  array) const

Reads the affine transform as a 3x3 matrix into the given array.

The array should contain at least 9 elements. The transform is read in column major order as a 3x3 matrix in homogenous coordinates. That is, the z values are all 0, except for the translation component which is 1.

Parameters
arrayThe array to store the values
Returns
a reference to the array for chaining

◆ get3x4()

float* cugl::Affine2::get3x4 ( float *  array) const

Reads the affine transform as a 3x4 matrix into the given array.

The array should contain at least 12 elements. The transform is read in column major order as a 3x4 matrix in homogenous coordinates. That is, the z and w values are all 0, except for the translation z component which is 1.

Parameters
arrayThe array to store the values
Returns
a reference to the array for chaining

◆ get4x4()

float* cugl::Affine2::get4x4 ( float *  array) const

Reads the affine transform as a 4x4 matrix into the given array.

The array should contain at least 16 elements. The transform is read in column major order as a 4x4 matrix in homogenous coordinates. The z and w values are all 0, except for the translation w component which is 1.

Parameters
arrayThe array to store the values
Returns
a reference to the array for chaining

◆ getDeterminant()

float cugl::Affine2::getDeterminant ( ) const
inline

Returns the determinant of this transform.

The determinant is a feature of the core matrix. The offset is ignored.

Returns
the determinant of this transform.

◆ getInverse()

Affine2 cugl::Affine2::getInverse ( ) const
inline

Returns a copy of the inverse of this transform.

If the transform cannot be inverted, this method returns the zero transform.

Note: This does not modify the transform.

Returns
a copy of the inverse of this transform.

◆ getRotation()

float cugl::Affine2::getRotation ( ) const
inline

Returns the rotational angle of this transform.

If the scale component is too close to zero, we cannot extract the rotation. In that case, we return the zero angle. (

Returns
the rotational angle of this transform.

◆ getScale()

Vec2 cugl::Affine2::getScale ( ) const
inline

Returns the scale component of this transform.

If the scale component of this matrix has negative parts, it is not possible to always extract the exact scalar component. In that case, a scale vector that is mathematically equivalent to the original scale vector is extracted and returned.

Returns
the scale component of this transform.

◆ getTranslation()

Vec2 cugl::Affine2::getTranslation ( ) const
inline

Returns the translational component of this transform.

Returns
the translational component of this transform.

◆ identify()

static Affine2* cugl::Affine2::identify ( float *  dst,
size_t  stride = 2 
)
static

Sets the float array to be an identity affine transform.

The float arrays should have at least 6-elements where each of the three pairs have the given stride. Positions outside of the 6 core elements are untouched.

Parameters
dstThe affine to reset in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ invert() [1/3]

Affine2& cugl::Affine2::invert ( )
inline

Inverts this transform in place.

If the transform cannot be inverted, this method sets it to the zero transform.

Returns
A reference to the Affine2 after the inversion.

◆ invert() [2/3]

static Affine2* cugl::Affine2::invert ( const Affine2 m1,
Affine2 dst 
)
static

Inverts m1 and stores the result in dst.

If the transform cannot be inverted, this method stores the zero transform in dst.

Parameters
m1The transform to negate.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ invert() [3/3]

static float* cugl::Affine2::invert ( const float *  m1,
float *  dst,
size_t  stride = 2 
)
static

Inverts m1 and stores the result in dst.

If the transform cannot be inverted, this method stores the zero transform in dst. Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride. When converting a matrix to the zero transform, positions outside of the 6 core elements are ignored.

Parameters
m1The transform to negate in column major order
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ isExactly()

bool cugl::Affine2::isExactly ( const Affine2 aff) const

Returns true if the transforms are exactly equal to each other.

This method may be unreliable given that the elements are floats. It should only be used to compared transform that have not undergone a lot of manipulation.

Parameters
affThe transform to compare against.
Returns
true if the transforms are exactly equal to each other.

◆ isIdentity()

bool cugl::Affine2::isIdentity ( float  variance = 0.0f) const

Returns true if this transform is equal to the identity transform.

The optional comparison tolerance takes into accout that elements are floats and this may not be exact. The tolerance is applied to each element individually. By default, the match must be exact.

Parameters
varianceThe comparison tolerance
Returns
true if this transform is equal to the identity transform.

◆ isInvertible()

bool cugl::Affine2::isInvertible ( float  variance = CU_MATH_EPSILON) const
inline

Returns true if this transform is invertible.

The optional comparison tolerance takes into accout that elements are floats and this may not be exact. The tolerance is applied to the determinant of the core matrix.

Returns
true if this transform is invertible.

◆ multiply() [1/9]

Affine2& cugl::Affine2::multiply ( const Affine2 aff)
inline

Multiplies this matrix by the specified one.

Transform multiplication is defined as standard function composition. The transform m2 is on the right. This means that it corresponds to an subsequent transform; transforms are applied left-to-right.

Parameters
affThe transform to multiply.
Returns
A reference to the Affine2 after multiplication.

◆ multiply() [2/9]

static Affine2* cugl::Affine2::multiply ( const Affine2 m1,
const Affine2 m2,
Affine2 dst 
)
static

Multiplies m1 by the transform m2 and stores the result in dst.

Transform multiplication is defined as standard function composition. The transform m2 is on the right. This means that it corresponds to an subsequent transform; transforms are applied left-to-right.

Parameters
m1The first transform to multiply.
m2The second transform to multiply.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ multiply() [3/9]

static Affine2* cugl::Affine2::multiply ( const Affine2 m1,
const Mat4 m2,
Affine2 dst 
)
static

Multiplies m1 by the matrix m2 and stores the result in dst.

The matrix m2 is on the right. This means that it corresponds to a subsequent transform, when looking at the order of transforms. The z component of m2 is ignored.

Parameters
m1The first transform to multiply.
m2The second transform to multiply.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ multiply() [4/9]

static Affine2* cugl::Affine2::multiply ( const Affine2 mat,
float  scalar,
Affine2 dst 
)
static

Multiplies the specified transform by a scalar and stores the result in dst.

The scalar is applied to BOTH the core matrix and the offset.

Parameters
matThe transform.
scalarThe scalar value.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ multiply() [5/9]

static float* cugl::Affine2::multiply ( const float *  m1,
const float *  m2,
float *  dst,
size_t  stride = 2 
)
static

Multiplies m1 by the transform m2 and stores the result in dst.

Transform multiplication is defined as standard function composition. The transform m2 is on the right. This means that it corresponds to an subsequent transform; transforms are applied left-to-right.

Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

Parameters
m1The first transform to multiply in column major order
m2The second transform to multiply in column major order
dstA matrix to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ multiply() [6/9]

static float* cugl::Affine2::multiply ( const float *  mat,
float  scalar,
float *  dst,
size_t  stride = 2 
)
static

Multiplies the specified transform by a scalar and stores the result in dst.

The scalar is applied to BOTH the core matrix and the offset. Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

Parameters
matThe transform in column major order
scalarThe scalar value.
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ multiply() [7/9]

Affine2* cugl::Affine2::multiply ( const Mat4 m1,
const Affine2 m2,
Affine2 dst 
)

Multiplies m1 by the matrix m2 and stores the result in dst.

The matrix m2 is on the right. This means that it corresponds to a subsequent transform, when looking at the order of transforms. The z component of m2 is ignored.

Parameters
m1The first transform to multiply.
m2The second transform to multiply.
dstA matrix to store the result in.
Returns
A reference to dst for chaining

◆ multiply() [8/9]

Affine2& cugl::Affine2::multiply ( const Mat4 mat)
inline

Multiplies this matrix by the specified one.

The matrix mat is on the right. This means that it corresponds to a subsequent transform, when looking at the order of transforms. The z compoent of mat is ignored.

Parameters
matThe transform to multiply.
Returns
A reference to the Affine2 after multiplication.

◆ multiply() [9/9]

Affine2& cugl::Affine2::multiply ( float  scalar)
inline

Multiplies the components of this transform by the specified scalar.

The scalar is applied to BOTH the core matrix and the offset.

Parameters
scalarThe scalar value.
Returns
A reference to the Affine2 after multiplication.

◆ operator Mat4()

cugl::Affine2::operator Mat4 ( ) const

Cast from Affine2 to a Mat4.

◆ operator std::string()

cugl::Affine2::operator std::string ( ) const
inline

Cast from Vec4 to a string.

◆ operator!=()

bool cugl::Affine2::operator!= ( const Affine2 aff) const
inline

Returns true if this transform is not equal to the given transform.

Comparison is exact, which may be unreliable given that the elements are floats.

Parameters
affThe transform to compare against.
Returns
true if this transform is not equal to the given transform.

◆ operator*() [1/3]

Affine2 cugl::Affine2::operator* ( const Affine2 aff) const
inline

Returns the matrix product of this matrix with the given matrix.

Transform multiplication is defined as standard function composition. The transform aff is on the right. This means that it corresponds to an subsequent transform; transforms are applied left-to-right.

Note: This does not modify the matrix.

Parameters
affThe transform to multiply by.
Returns
the matrix product of this matrix with the given matrix.

◆ operator*() [2/3]

Affine2 cugl::Affine2::operator* ( const Mat4 mat) const
inline

Returns the matrix product of this matrix with the given matrix.

Transform multiplication is defined as standard function composition. The transform aff is on the right. This means that it corresponds to an subsequent transform; transforms are applied left-to-right.

Note: This does not modify the matrix.

Parameters
matThe transform to multiply by.
Returns
the matrix product of this matrix with the given matrix.

◆ operator*() [3/3]

Affine2 cugl::Affine2::operator* ( float  scalar) const
inline

Returns a copy of this matrix with all elements multiplied by the scalar.

The scalar is applied to BOTH the core matrix and the offset.

Note: This does not modify the matrix.

Parameters
scalarThe scalar value.
Returns
the product of this transform with the given scalar.

◆ operator*=() [1/3]

Affine2& cugl::Affine2::operator*= ( const Affine2 aff)
inline

Right-multiplies this transform by the given transform.

Transform multiplication is defined as standard function composition. The transform aff is on the right. This means that it corresponds to an subsequent transform; transforms are applied left-to-right.

Parameters
affThe transform to multiply by.
Returns
A reference to this (modified) Affine2 for chaining.

◆ operator*=() [2/3]

Affine2& cugl::Affine2::operator*= ( const Mat4 mat)
inline

Right-multiplies this transform by the given matrix.

The matrix mat is on the right. This means that it corresponds to a subsequent transform, when looking at the order of transforms. The z compoent of mat is ignored.

Parameters
matThe matrix to multiply by.
Returns
A reference to this (modified) Affine2 for chaining.

◆ operator*=() [3/3]

Affine2& cugl::Affine2::operator*= ( float  scalar)
inline

Multiplies the components of this transform by the specified scalar.

The scalar is applied to BOTH the core matrix and the offset.

Parameters
scalarThe scalar value.
Returns
A reference to this (modified) Affine2 for chaining.

◆ operator+()

Affine2 cugl::Affine2::operator+ ( const Vec2  v) const
inline

Returns the sum of this transform with the given offset.

Addition is applied to the offset only; the core matrix is unchanged.

Note: This does not modify the transform.

Parameters
vThe offset to add.
Returns
the sum of this transform with the given offset.

◆ operator+=()

Affine2& cugl::Affine2::operator+= ( const Vec2  v)
inline

Adds the given offset to this transform in place.

Addition is applied to the offset only; the core matrix is unchanged.

Parameters
vThe offset to add
Returns
A reference to this (modified) Affine2 for chaining.

◆ operator-()

Affine2 cugl::Affine2::operator- ( const Vec2  v) const
inline

Returns the difference of this matrix with the given offset.

Subtraction is applied to the offset only; the core matrix is unchanged.

Note: This does not modify the transform.

Parameters
vThe offset to subtract.
Returns
the difference of this transform and the given offset.

◆ operator-=()

Affine2& cugl::Affine2::operator-= ( const Vec2  v)
inline

Subtracts the given offset from this transform in place.

Subtraction is applied to the offset only; the core matrix is unchanged.

Parameters
vThe offset to subtract
Returns
A reference to this (modified) Affine2 for chaining.

◆ operator=() [1/4]

Affine2& cugl::Affine2::operator= ( Affine2 &&  mat)
inline

Sets the elements of this matrix to those in the specified one.

Parameters
matThe matrix to take resources from.
Returns
A reference to this (modified) Mat4 for chaining.

◆ operator=() [2/4]

Affine2& cugl::Affine2::operator= ( const Affine2 mat)
inline

Sets the elements of this transform to those in the specified transform.

Parameters
matThe transform to copy.
Returns
A reference to this (modified) Affine2 for chaining.

◆ operator=() [3/4]

Affine2& cugl::Affine2::operator= ( const float *  array)
inline

Sets the values of this transform to those in the specified column-major array.

The passed-in array is six elements in column-major order, with the last two elements being the translation offset. Hence the memory layout of the array is as follows:

0   2   4
1   3   5
Parameters
arrayAn array containing 6 elements in column-major order.
Returns
A reference to this (modified) Affine2 for chaining.

◆ operator=() [4/4]

Affine2& cugl::Affine2::operator= ( const Mat4 mat)

Sets the elements of this transform to those of the given matrix.

The z values are all uniformly ignored. However, it the final element of the matrix is not 1 (e.g. the translation has a w value of 1), then it divides the entire matrix before creating the affine transform

Parameters
matThe matrix to convert
Returns
A reference to this (modified) Affine2 for chaining.

◆ operator==()

bool cugl::Affine2::operator== ( const Affine2 aff) const
inline

Returns true if this transform is equal to the given transform.

Comparison is exact, which may be unreliable given that the elements are floats. It should only be used to compared transform that have not undergone a lot of manipulation.

Parameters
affThe transform to compare against.
Returns
true if this transform is equal to the given transform.

◆ rotate() [1/3]

static Affine2* cugl::Affine2::rotate ( const Affine2 aff,
float  angle,
Affine2 dst 
)
static

Applies a rotation to the given transform and stores the result in dst.

The rotation is in radians, counter-clockwise about the z-axis.

The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to rotate.
angleThe angle (in radians).
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ rotate() [2/3]

static float* cugl::Affine2::rotate ( const float *  aff,
float  angle,
float *  dst,
size_t  stride = 2 
)
static

Applies a rotation to the given transform and stores the result in dst.

The rotation is in radians, counter-clockwise about the z-axis. Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to rotate in column major order
angleThe angle (in radians).
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ rotate() [3/3]

Affine2& cugl::Affine2::rotate ( float  angle)
inline

Applies a rotation to this transform.

The rotation is in radians, counter-clockwise about the given axis.

The rotation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
angleThe angle (in radians).
Returns
This transform, after rotation.

◆ scale() [1/9]

static Affine2* cugl::Affine2::scale ( const Affine2 aff,
const Vec2  s,
Affine2 dst 
)
static

Applies a non-uniform scale to the given transform and stores the result in dst.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to scale.
sThe vector storing the individual scaling factors
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ scale() [2/9]

static Affine2* cugl::Affine2::scale ( const Affine2 aff,
float  sx,
float  sy,
Affine2 dst 
)
static

Applies a non-uniform scale to the given transform and stores the result in dst.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to scale.
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ scale() [3/9]

static Affine2* cugl::Affine2::scale ( const Affine2 aff,
float  value,
Affine2 dst 
)
static

Applies a uniform scale to the given transform and stores the result in dst.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to scale.
valueThe scalar to multiply by.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ scale() [4/9]

static float* cugl::Affine2::scale ( const float *  aff,
const Vec2  s,
float *  dst,
size_t  stride = 2 
)
static

Applies a non-uniform scale to the given transform and stores the result in dst.

Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to scale in column major order
sThe vector storing the individual scaling factors
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ scale() [5/9]

static float* cugl::Affine2::scale ( const float *  aff,
float  sx,
float  sy,
float *  dst,
size_t  stride = 2 
)
static

Applies a non-uniform scale to the given transform and stores the result in dst.

Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to scale in column major order
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ scale() [6/9]

static float* cugl::Affine2::scale ( const float *  aff,
float  value,
float *  dst,
size_t  stride = 2 
)
static

Applies a uniform scale to the given transform and stores the result in dst.

Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to scale in column major order
valueThe scalar to multiply by.
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ scale() [7/9]

Affine2& cugl::Affine2::scale ( const Vec2  s)
inline

Applies a non-uniform scale to this transform.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
sThe vector storing the individual scaling factors
Returns
This transform, after scaling.

◆ scale() [8/9]

Affine2& cugl::Affine2::scale ( float  sx,
float  sy 
)
inline

Applies a non-uniform scale to this transform.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
sxThe amount to scale along the x-axis.
syThe amount to scale along the y-axis.
Returns
This transform, after scaling.

◆ scale() [9/9]

Affine2& cugl::Affine2::scale ( float  value)
inline

Applies a uniform scale to this transform.

The scaling operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
valueThe scalar to multiply by.
Returns
This transform, after scaling.

◆ set() [1/5]

Affine2& cugl::Affine2::set ( const Affine2 mat)

Sets the elements of this transform to those in the specified transform.

Parameters
matThe transform to copy.
Returns
A reference to this (modified) Affine2 for chaining.

◆ set() [2/5]

Affine2& cugl::Affine2::set ( const float *  mat)

Sets the values of this transform to those in the specified column-major array.

The passed-in array is six elements in column-major order, with the last two elements being the translation offset. Hence the memory layout of the array is as follows:

0   2   4
1   3   5
Parameters
matAn array containing 6 elements in column-major order.
Returns
A reference to this (modified) Affine2 for chaining.

◆ set() [3/5]

Affine2& cugl::Affine2::set ( const float *  mat,
size_t  stride 
)

Sets the values of this transform to those in the specified column-major array.

The passed-in array is six elements grouped in pairs, with each pair separated by a stride. For example, if stride is 4, then mat is a 12-element array with the first column at 0,1, the second column at 4,5 and the translation component at 8,9.

Parameters
matAn array containing elements in column-major order.
strideThe pairwise data stride
Returns
A reference to this (modified) Affine2 for chaining.

◆ set() [4/5]

Affine2& cugl::Affine2::set ( const Mat4 mat)

Sets the elements of this transform to those of the given matrix.

The z values are all uniformly ignored. However, it the final element of the matrix is not 1 (e.g. the translation has a w value of 1), then it divides the entire matrix before creating the affine transform

Parameters
matThe matrix to convert
Returns
A reference to this (modified) Affine2 for chaining.

◆ set() [5/5]

Affine2& cugl::Affine2::set ( float  m11,
float  m12,
float  m21,
float  m22,
float  tx,
float  ty 
)

Sets the individal values of this transform.

Parameters
m11The first element of the first row.
m12The second element of the first row.
m21The first element of the second row.
m22The second element of the second row.
txThe translation offset for the x-coordinate.
tyThe translation offset for the y-coordinate.
Returns
A reference to this (modified) Affine2 for chaining.

◆ setIdentity()

Affine2& cugl::Affine2::setIdentity ( )

Sets this transform to the identity transform.

Returns
A reference to this (modified) Affine2 for chaining.

◆ setZero()

Affine2& cugl::Affine2::setZero ( )

Sets all elements of the current transform to zero.

Returns
A reference to this (modified) Affine2 for chaining.

◆ subtract() [1/3]

static Affine2* cugl::Affine2::subtract ( const Affine2 m1,
const Vec2  v,
Affine2 dst 
)
static

Subtracts the offset v from m and stores the result in dst.

Subtraction is applied to the offset only; the core matrix is unchanged.

Parameters
m1The initial transform.
vThe offset to subtract.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ subtract() [2/3]

static float* cugl::Affine2::subtract ( const float *  m1,
const Vec2  v,
float *  dst,
size_t  stride = 2 
)
static

Subtracts the offset v from m and stores the result in dst.

Subtraction is applied to the offset only; the core matrix is unchanged. Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

Parameters
m1The initial transform in column major order
vThe offset to subtract.
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ subtract() [3/3]

Affine2& cugl::Affine2::subtract ( const Vec2  v)
inline

Subtracts the specified offset from the current transform.

Subtraction is applied to the offset only; the core matrix is unchanged.

Parameters
vThe offset to subtract.
Returns
A reference to the Affine2 after subtraction.

◆ toString()

std::string cugl::Affine2::toString ( bool  verbose = false) const

Returns a string representation of this transform for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this transform for debugging purposes.

◆ transform() [1/5]

static Rect* cugl::Affine2::transform ( const Affine2 aff,
const Rect  rect,
Rect dst 
)
static

Transforms the rectangle and stores the result in dst.

This method transforms the four defining points of the rectangle. It then computes the minimal bounding box storing these four points

Parameters
affThe affine transform.
rectThe rect to transform.
dstA rect to store the transformed rectangle in.
Returns
A reference to dst for chaining

◆ transform() [2/5]

static Vec2* cugl::Affine2::transform ( const Affine2 aff,
const Vec2  point,
Vec2 dst 
)
static

Transforms the point and stores the result in dst.

Parameters
affThe affine transform.
pointThe point to transform.
dstA vector to store the transformed point in.
Returns
A reference to dst for chaining

◆ transform() [3/5]

static float* cugl::Affine2::transform ( const Affine2 aff,
float const *  input,
float *  output,
size_t  size 
)
static

Transforms the vector array, and stores the result in dst.

The vector is array is treated as a list of 2 element vectors (

See also
Vec2). The transform is applied in order and written to the output array.
Parameters
affThe transform matrix.
inputThe array of vectors to transform.
outputThe array to store the transformed vectors.
sizeThe size of the two arrays.
Returns
A reference to dst for chaining

◆ transform() [4/5]

Rect cugl::Affine2::transform ( const Rect  rect) const

Returns a copy of the given rectangle transformed.

This method transforms the four defining points of the rectangle. It then computes the minimal bounding box storing these four points

Note: This does not modify the original rectangle. To transform a point in place, use the static method.

Parameters
rectThe rect to transform.
Returns
A reference to dst for chaining

◆ transform() [5/5]

Vec2 cugl::Affine2::transform ( const Vec2  point) const
inline

Returns a copy of the given point transformed.

Note: This does not modify the original point. To transform a point in place, use the static method (or the appropriate operator).

Parameters
pointThe point to transform.
Returns
a copy of this point transformed.

◆ translate() [1/6]

static Affine2* cugl::Affine2::translate ( const Affine2 aff,
const Vec2  t,
Affine2 dst 
)
static

Applies a translation to the given transform and stores the result in dst.

The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to translate.
tThe vector storing the individual translation offsets
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ translate() [2/6]

static Affine2* cugl::Affine2::translate ( const Affine2 aff,
float  tx,
float  ty,
Affine2 dst 
)
static

Applies a translation to the given transform and stores the result in dst.

The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to translate.
txThe translation offset for the x-axis.
tyThe translation offset for the y-axis.
dstA transform to store the result in.
Returns
A reference to dst for chaining

◆ translate() [3/6]

static float* cugl::Affine2::translate ( const float *  aff,
const Vec2  t,
float *  dst,
size_t  stride = 2 
)
static

Applies a translation to the given transform and stores the result in dst.

Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to translate in column major order
tThe vector storing the individual translation offsets
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ translate() [4/6]

static float* cugl::Affine2::translate ( const float *  aff,
float  tx,
float  ty,
float *  dst,
size_t  stride = 2 
)
static

Applies a translation to the given transform and stores the result in dst.

Both of the float arrays should have at least 6-elements where each of the three pairs have the given stride.

The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
affThe transform to translate in column major order
txThe translation offset for the x-axis.
tyThe translation offset for the y-axis.
dstA transform to store the result in column major order
strideThe pairwise data stride
Returns
A reference to dst for chaining

◆ translate() [5/6]

Affine2& cugl::Affine2::translate ( const Vec2  t)
inline

Applies a translation to this transform.

The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
tThe vector storing the individual translation offsets
Returns
This transform, after translation.

◆ translate() [6/6]

Affine2& cugl::Affine2::translate ( float  tx,
float  ty 
)
inline

Applies a translation to this transform.

The translation operation is applied on the right. Given our convention, that means that it takes place AFTER any previously applied transforms.

Parameters
txThe translation offset for the x-axis.
tyThe translation offset for the y-axis.
Returns
This transform, after translation.

Member Data Documentation

◆ IDENTITY

const Affine2 cugl::Affine2::IDENTITY
static

The identity transform (ones on the diagonal)

◆ m

float cugl::Affine2::m[6]

The condensed affine matrix

◆ ONE

const Affine2 cugl::Affine2::ONE
static

The transform with all ones

◆ ZERO

const Affine2 cugl::Affine2::ZERO
static

The transform with all zeroes


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