smk::Transformable Class Reference

#include <Transformable.hpp>

Inheritance diagram for smk::Transformable:

Description

A 2D Drawable object supporting several transformations:

Definition at line 64 of file Transformable.hpp.

Public Member Functions

void SetCenter (float center_x, float center_y)
 Set the center of the object. It is used as the rotation center. The center of the object will be drawn exactly on (0,0) on the screen (plus its potential translation if any) More...
 
void SetCenter (const glm::vec2 &center)
 Set the center of the object. It is used as the rotation center. The center of the object will be drawn exactly on (0,0) on the screen (plus its potential translation if any) More...
 
void Move (const glm::vec2 &move)
 
void Move (float x, float y)
 
void SetPosition (float x, float y)
 Set the position of the object to be drawn. More...
 
void SetPosition (const glm::vec2 &position)
 Set the position of the object to be drawn. More...
 
void Rotate (float rotation)
 Increase the rotation of the object to apply before drawing it. More...
 
void SetRotation (float rotation)
 Set the rotation to apply before drawing the object. More...
 
void SetScale (float scale)
 Increase or decrease the size of the object being drawn. More...
 
void SetScale (const glm::vec2 &scale)
 Increase or decrease the size of the object being drawn. More...
 
void SetScale (float scale_x, float scale_y)
 Increase or decrease the size of the object being drawn. More...
 
void SetScaleX (float scale_x)
 Increase or decrease the size of the object being drawn. More...
 
void SetScaleY (float scale_y)
 Increase or decrease the size of the object being drawn. More...
 
glm::mat4 transformation () const override
 Increase or decrease the size of the object being drawn. More...
 
 Transformable (Transformable &&) noexcept=default
 
 Transformable (const Transformable &)=default
 
Transformableoperator= (Transformable &&)=default
 
Transformableoperator= (const Transformable &)=default
 
void SetColor (const glm::vec4 &color)
 Color. More...
 
const glm::vec4 & color () const
 
void SetTexture (Texture texture)
 Set the object's texture. More...
 
const Texturetexture () const
 
void SetBlendMode (const BlendMode &)
 Set the blending mode to be used for drawing the object. More...
 
const BlendModeblend_mode () const
 
void SetVertexArray (VertexArray vertex_array)
 Set the object's shape. More...
 
const VertexArrayvertex_array () const
 
void Draw (RenderTarget &target, RenderState state) const override
 

Member Function Documentation

◆ blend_mode()

const BlendMode & smk::TransformableBase::blend_mode ( ) const
inlineinherited

Definition at line 36 of file Transformable.hpp.

36{ return blend_mode_; }

◆ color()

const glm::vec4 & smk::TransformableBase::color ( ) const
inlineinherited

Definition at line 28 of file Transformable.hpp.

28{ return color_; }

◆ Draw()

void smk::TransformableBase::Draw ( RenderTarget target,
RenderState  state 
) const
overridevirtualinherited

Draw the object on a RenderTarget.

Parameters
targetA RenderTarget to be drawn on.
stateThe RenderState to derive from.

Implements smk::Drawable.

Definition at line 147 of file Transformable.cpp.

147 {
148 state.color *= color();
149 state.texture = texture();
150 state.view *= transformation();
151 state.vertex_array = vertex_array();
152 state.blend_mode = blend_mode();
153 target.Draw(state);
154}

◆ Move() [1/2]

void smk::Transformable::Move ( const glm::vec2 &  move)

Increase the position of the object being drawn.

See also
smk::SetPosition
Parameters
moveThe increment of position (x,y)
Examples
texture_subrectangle.cpp.

Definition at line 44 of file Transformable.cpp.

44 {
45 position_ += move;
46}

◆ Move() [2/2]

void smk::Transformable::Move ( float  x,
float  y 
)

Increase the position of the object being drawn.

See also
smk::SetPosition
Parameters
xThe increment of position along the horizontal axis.
yThe increment of position along the vertical axis.

Definition at line 52 of file Transformable.cpp.

52 {
53 Move({x, y});
54}
void Move(const glm::vec2 &move)

◆ Rotate()

void smk::Transformable::Rotate ( float  rotation)

Increase the rotation of the object to apply before drawing it.

See also
Transformable::SetRotation.
Parameters
rotationThe delta of rotation to be added.

Definition at line 22 of file Transformable.cpp.

22 {
23 rotation_ += rotation;
24}

◆ SetBlendMode()

void smk::TransformableBase::SetBlendMode ( const BlendMode blend_mode)
inherited

Set the blending mode to be used for drawing the object.

Parameters
blend_modethe BlendMode to be used.

Definition at line 133 of file Transformable.cpp.

133 {
134 blend_mode_ = blend_mode;
135}

◆ SetCenter() [1/2]

void smk::Transformable::SetCenter ( const glm::vec2 &  center)

Set the center of the object. It is used as the rotation center. The center of the object will be drawn exactly on (0,0) on the screen (plus its potential translation if any)

Parameters
centerThe center position (x,y) in the object.

Definition at line 60 of file Transformable.cpp.

60 {
61 center_ = center;
62}

◆ SetCenter() [2/2]

void smk::Transformable::SetCenter ( float  x,
float  y 
)

Set the center of the object. It is used as the rotation center. The center of the object will be drawn exactly on (0,0) on the screen (plus its potential translation if any)

Parameters
xThe center position along the horizontal axis.
yThe center position along the vertical axis.
Examples
sprite_move.cpp.

Definition at line 69 of file Transformable.cpp.

69 {
70 SetCenter({x, y});
71}
void SetCenter(float center_x, float center_y)
Set the center of the object. It is used as the rotation center. The center of the object will be dra...

◆ SetColor()

void smk::TransformableBase::SetColor ( const glm::vec4 &  color)
inherited

Color.

Modify the color of the object. The resulting pixel is the multiplication component wise in between this color and the original pixel color.

Parameters
colorThe color.
Examples
rounded_rectangle.cpp, and shape_2d.cpp.

Definition at line 127 of file Transformable.cpp.

127 {
128 color_ = color;
129}

◆ SetPosition() [1/2]

void smk::Transformable::SetPosition ( const glm::vec2 &  position)

Set the position of the object to be drawn.

See also
Transformable::Move.
Parameters
positionthe position (x,y) of the object.

Definition at line 29 of file Transformable.cpp.

29 {
30 position_ = position;
31}

◆ SetPosition() [2/2]

void smk::Transformable::SetPosition ( float  x,
float  y 
)

Set the position of the object to be drawn.

See also
Transformable::Move.
Parameters
xThe position along the horizontal axis.
yThe position along the vertical axis.
Examples
sprite_move.cpp.

Definition at line 37 of file Transformable.cpp.

37 {
38 position_ = {x, y};
39}

◆ SetRotation()

void smk::Transformable::SetRotation ( float  rotation)

Set the rotation to apply before drawing the object.

See also
Transformable::Rotate.
Parameters
rotationThe angle in radian.

Definition at line 15 of file Transformable.cpp.

15 {
16 rotation_ = rotation;
17}

◆ SetScale() [1/3]

void smk::Transformable::SetScale ( const glm::vec2 &  scale)

Increase or decrease the size of the object being drawn.

Parameters
scaleThe ratio of magnification.

Definition at line 81 of file Transformable.cpp.

81 {
82 scale_ = scale;
83}

◆ SetScale() [2/3]

void smk::Transformable::SetScale ( float  scale)

Increase or decrease the size of the object being drawn.

Parameters
scaleThe ratio of magnification.
Examples
sprite_move.cpp.

Definition at line 75 of file Transformable.cpp.

75 {
76 SetScale({scale, scale});
77}
void SetScale(float scale)
Increase or decrease the size of the object being drawn.

◆ SetScale() [3/3]

void smk::Transformable::SetScale ( float  scale_x,
float  scale_y 
)

Increase or decrease the size of the object being drawn.

Parameters
scale_xThe ratio of magnification along the horizontal axis.
scale_yThe ratio of magnification along the vertical axis.

Definition at line 88 of file Transformable.cpp.

88 {
89 scale_.x = scale_x;
90 scale_.y = scale_y;
91}

◆ SetScaleX()

void smk::Transformable::SetScaleX ( float  scale_x)

Increase or decrease the size of the object being drawn.

Parameters
scale_xThe ratio of magnification along the horizontal axis.

Definition at line 95 of file Transformable.cpp.

95 {
96 scale_.x = scale_x;
97}

◆ SetScaleY()

void smk::Transformable::SetScaleY ( float  scale_y)

Increase or decrease the size of the object being drawn.

Parameters
scale_yThe ratio of magnification along the vertical axis.

Definition at line 101 of file Transformable.cpp.

101 {
102 scale_.y = scale_y;
103}

◆ SetTexture()

void smk::TransformableBase::SetTexture ( Texture  texture)
inherited

Set the object's texture.

Definition at line 138 of file Transformable.cpp.

138 {
139 texture_ = std::move(texture);
140}

◆ SetVertexArray()

void smk::TransformableBase::SetVertexArray ( VertexArray  vertex_array)
inherited

Set the object's shape.

Definition at line 143 of file Transformable.cpp.

143 {
144 vertex_array_ = std::move(vertex_array);
145}

◆ texture()

const Texture & smk::TransformableBase::texture ( ) const
inlineinherited

Definition at line 32 of file Transformable.hpp.

32{ return texture_; }

◆ transformation()

glm::mat4 smk::Transformable::transformation ( ) const
overridevirtual

Increase or decrease the size of the object being drawn.

Returns
the transformation applied to the object. This is the result of applying the translation, rotation, center and scaling to the the object.

Implements smk::TransformableBase.

Definition at line 109 of file Transformable.cpp.

109 {
110 glm::mat4 ret = glm::mat4(1.0);
111 ret = glm::translate(ret, {position_.x, position_.y, 0.0});
112 if (rotation_ != 0.F) {
113 ret =
114 // NOLINTNEXTLINE
115 glm::rotate(ret, -rotation_ * (2.F * 3.1415F / 360.F), {0.0, 0.0, 1.0});
116 }
117 ret =
118 glm::translate(ret, {-center_.x * scale_.x, -center_.y * scale_.y, 0.F});
119 ret = glm::scale(ret, {scale_.x, scale_.y, 1.0});
120 return ret;
121}

◆ vertex_array()

const VertexArray & smk::TransformableBase::vertex_array ( ) const
inlineinherited

Definition at line 40 of file Transformable.hpp.

40{ return vertex_array_; }

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