ge211  2021.5.1
A student game engine
Transform Class Reference

Detailed Description

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

A Transform can be given to Sprite_set::add_sprite(const Sprite&, Posn<int>, int, const Transform&) to specify how a 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:

ge211::Transform my_transform =
.set_flip_h(true)
.set_flip_v(true)
.scale_x(2);

Definition at line 792 of file ge211_geometry.hxx.

Public Member Functions

Setters
Transformset_rotation (double)
 Modifies this transform to have the given rotation, in degrees.
 
Transformset_flip_h (bool)
 Modifies this transform to determine whether to flip horizontally.
 
Transformset_flip_v (bool)
 Modifies this transform to determine whether to flip vertically.
 
Transformset_scale (double)
 Modifies this transform to scale the sprite by the given amount in both dimensions. More...
 
Transformset_scale_x (double)
 Modifies this transform to scale the sprite horizontally. More...
 
Transformset_scale_y (double)
 Modifies this transform to scale the sprite vertically. More...
 
Getters
double get_rotation () const
 Returns the rotation that will be applied to the sprite.
 
bool get_flip_h () const
 Returns whether the sprite will be flipped horizontally.
 
bool get_flip_v () const
 Returns whether the sprite will be flipped vertically.
 
double get_scale_x () const
 Returns how much the sprite will be scaled horizontally.
 
double get_scale_y () const
 Returns how much the sprite will be scaled vertically.
 
Combining transforms
bool is_identity () const
 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 &other) const
 Composes two transforms to combine both of their effects.
 
Transform inverse () const
 Returns the inverse of this transform. More...
 
Comparing transforms
bool operator== (const Transform &other) const
 Equality for Transforms.
 
bool operator!= (const Transform &other) const
 Disequality for Transforms.
 

Constructor and factory functions

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

Member Function Documentation

◆ inverse()

Transform inverse ( ) const

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.cxx.

◆ is_identity()

bool is_identity ( ) const

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.cxx.

◆ set_scale()

Transform & set_scale ( double  scale)

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.cxx.

◆ set_scale_x()

Transform & set_scale_x ( double  scale_x)

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.cxx.

◆ set_scale_y()

Transform & set_scale_y ( double  scale_y)

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.cxx.


The documentation for this class was generated from the following files:
ge211::geometry::Transform::set_flip_h
Transform & set_flip_h(bool)
Modifies this transform to determine whether to flip horizontally.
Definition: ge211_geometry.cxx:51
ge211::geometry::Transform::set_flip_v
Transform & set_flip_v(bool)
Modifies this transform to determine whether to flip vertically.
Definition: ge211_geometry.cxx:57
ge211::geometry::Transform::scale_x
static Transform scale_x(double)
Constructs a transform that scales the sprite in the x dimension.
Definition: ge211_geometry.cxx:34
ge211::geometry::Transform
A rendering transformation, which can scale, flip, and rotate.
Definition: ge211_geometry.hxx:793