ge211
Transform Class Reference

Detailed Description

A rendering transform, which can scale, flip, and rotate.

A Transform can be given to Sprite_set::add_sprite(const Sprite&, Position, int, const Transform&) to specify how a sprites::Sprite should be rendered.

To construct a transform that does just one thing, you can use one of the static factory functions:

It is also possible to modify a transform with the setter functions such as set_rotation(double) and set_scale(double). This can be used to configure a transform that does more than one thing:

Transform my_transform =
Transform{}.set_flip_h(true)
.set_flip_v(true)
.scale_x(2);

Definition at line 682 of file ge211_geometry.h.

Public Member Functions

Setters
Transformset_rotation (double) noexcept
 Modifies this transform to have the given rotation, in degrees degrees. More...
 
Transformset_flip_h (bool) noexcept
 Modifies this transform to determine whether to flip horizontally.
 
Transformset_flip_v (bool) noexcept
 Modifies this transform to determine whether to flip vertically.
 
Transformset_scale (double) noexcept
 Modifies this transform to scale the sprite by the given amount in both dimensions. More...
 
Transformset_scale_x (double) noexcept
 Modifies this transform to scale the sprite horizontally. More...
 
Transformset_scale_y (double) noexcept
 Modifies this transform to scale the sprite vertically. More...
 
Getters
double get_rotation () const noexcept
 Returns the rotation that will be applied to the sprite.
 
bool get_flip_h () const noexcept
 Returns whether the sprite will be flipped horizontally.
 
bool get_flip_v () const noexcept
 Returns whether the sprite will be flipped vertically.
 
double get_scale_x () const noexcept
 Returns how much the sprite will be scaled horizontally.
 
double get_scale_y () const noexcept
 Returns how much the sprite will be scaled vertically.
 
Combining transforms
bool is_identity () const noexcept
 Is this transformation the identity transformation that does nothing? Because floating point is approximate, this may answer false for transforms that are nearly the identity. More...
 
Transform operator* (const Transform &) const noexcept
 Composes two transforms to combine both of their effects.
 
Transform inverse () const noexcept
 Returns the inverse of this transform. More...
 

Constructor and factory functions

 Transform () noexcept
 Constructs the identity transform, which has no effect.
 
static Transform rotation (double) noexcept
 Constructs a rotating transform, given the rotation in degrees clockwise. More...
 
static Transform flip_h () noexcept
 Constructs a transform that flips the sprite horizontally.
 
static Transform flip_v () noexcept
 Constructs a transform that flips the sprite vertically.
 
static Transform scale (double) noexcept
 Constructs a transform that scales the sprite in both dimensions.
 
static Transform scale_x (double) noexcept
 Constructs a transform that scales the sprite in the x dimension.
 
static Transform scale_y (double) noexcept
 Constructs a transform that scales the sprite in the y dimension.
 

Member Function Documentation

◆ inverse()

Transform inverse ( ) const
noexcept

Returns the inverse of this transform.

Composing a transform with its inverse should result in the identity transformation, though because floating point is approximate, is_identity() const may not actually answer true.

Definition at line 123 of file ge211_geometry.cpp.

◆ is_identity()

bool is_identity ( ) const
noexcept

Is this transformation the identity transformation that does nothing? Because floating point is approximate, this may answer false for transforms that are nearly the identity.

But it should answer true for any transform constructed by the default constructor Transform().

Definition at line 107 of file ge211_geometry.cpp.

◆ rotation()

Transform rotation ( double  degrees)
staticnoexcept

Constructs a rotating transform, given the rotation in degrees clockwise.

Definition at line 14 of file ge211_geometry.cpp.

◆ set_rotation()

Transform & set_rotation ( double  rotation)
noexcept

Modifies this transform to have the given rotation, in degrees degrees.

Definition at line 44 of file ge211_geometry.cpp.

◆ set_scale()

Transform & set_scale ( double  scale)
noexcept

Modifies this transform to scale the sprite by the given amount in both dimensions.

This overwrites the effect of previous calls to set_scale_x(double) and set_scale_y(double).

Definition at line 63 of file ge211_geometry.cpp.

◆ set_scale_x()

Transform & set_scale_x ( double  scale_x)
noexcept

Modifies this transform to scale the sprite horizontally.

This overwrites the effect of previous calls to set_scale(double) as well as itself.

Definition at line 70 of file ge211_geometry.cpp.

◆ set_scale_y()

Transform & set_scale_y ( double  scale_y)
noexcept

Modifies this transform to scale the sprite vertically.

This overwrites the effect of previous calls to set_scale(double) as well as itself.

Definition at line 76 of file ge211_geometry.cpp.


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