CG-Project2
Loading...
Searching...
No Matches
Transform Class Reference

Component to store mesh position, rotation, scale data. More...

#include <Component.hpp>

Inheritance diagram for Transform:
Collaboration diagram for Transform:

Public Member Functions

bool isModelMatrixEnable () const
 Retrieves if the model matrix is enable.
void enableModelMatrix (const bool &flag)
 Enable/disable the model matrix.
const bool & isDirty () const
 This method is used to avoid regenerating model matrix if data aren't changed.
void setDirty (const bool &dirty)
 Sets the model matrix dirty flag.
const glm::vec3 & getPosition () const
 Retrieves the mesh position.
void setPosition (const glm::vec3 &pos)
 Sets the mesh position.
void addPosition (const glm::vec3 &offset)
 Adds an offset to the current position.
glm::vec3 getScale () const
 Retrieves the mesh position.
void setScale (const glm::vec3 &scale)
 Sets the mesh scale.
void addScale (const glm::vec3 &offset)
 Adds to the current scale the offset given.
glm::vec3 getRotation () const
 Retrieves the mesh position.
void setRotation (glm::vec3 rot)
 Sets the mesh rotation, it works using MAX_DEGREE_ANGLE to avoid angle value more then 360 or less than 0.
void addRotation (const glm::vec3 &offset)
 Adds to the current rotation value the given offset. It works with the same behaviour of Transform::setRotation(glm::vec3 rot).
 Transform ()
 Default constructor.
void updateModelMatrix ()
 This method updates the model matrix only if the dirty flag is activated.

Public Attributes

glm::vec3 position {}
 mesh position vector
glm::vec3 scale {1, 1, 1}
 mesh scale
glm::vec3 rotation {}
 mesh rotation
glm::quat quaternion {}
 mesh quaternion
glm::mat4 model {1}
 mesh model matrix
bool dirty = true
 model matrix dirty flag
bool enableModel = true
 model matrix enable flag
float MAX_DEGREE_ANGLE = 180

Detailed Description

Component to store mesh position, rotation, scale data.

Member Function Documentation

◆ addPosition()

void Transform::addPosition ( const glm::vec3 & offset)
inline

Adds an offset to the current position.

Parameters
offsetoffset to be added.
Note
It activate the dirty flag.

◆ addRotation()

void Transform::addRotation ( const glm::vec3 & offset)
inline

Adds to the current rotation value the given offset. It works with the same behaviour of Transform::setRotation(glm::vec3 rot).

Note
It activate the dirty flag.

◆ addScale()

void Transform::addScale ( const glm::vec3 & offset)
inline

Adds to the current scale the offset given.

Parameters
offsetoffset to be added
Note
It activate the dirty flag.

◆ enableModelMatrix()

void Transform::enableModelMatrix ( const bool & flag)
inline

Enable/disable the model matrix.

Parameters
flagbool flag to enable or disable model matrix.

◆ getPosition()

const glm::vec3 & Transform::getPosition ( ) const
inline

Retrieves the mesh position.

Returns
mesh position

◆ getRotation()

glm::vec3 Transform::getRotation ( ) const
inline

Retrieves the mesh position.

Returns
mesh position

◆ getScale()

glm::vec3 Transform::getScale ( ) const
inline

Retrieves the mesh position.

Returns
mesh position

◆ isDirty()

const bool & Transform::isDirty ( ) const
inline

This method is used to avoid regenerating model matrix if data aren't changed.

Returns
true if data changed and the model matrix is invalid
Note
The model matrix is invalid when position, scale or rotation are modified.

◆ isModelMatrixEnable()

bool Transform::isModelMatrixEnable ( ) const
inline

Retrieves if the model matrix is enable.

Returns
true if model matrix is enabled

◆ setDirty()

void Transform::setDirty ( const bool & dirty)
inline

Sets the model matrix dirty flag.

Parameters
dirtymodel matrix dirty flag
Note
Everytime the dirty flag is activated, model matrix should be updated.

◆ setPosition()

void Transform::setPosition ( const glm::vec3 & pos)
inline

Sets the mesh position.

Parameters
posmesh new position
Note
It activate the dirty flag.

◆ setRotation()

void Transform::setRotation ( glm::vec3 rot)
inline

Sets the mesh rotation, it works using MAX_DEGREE_ANGLE to avoid angle value more then 360 or less than 0.

Note
It activate the dirty flag.

◆ setScale()

void Transform::setScale ( const glm::vec3 & scale)
inline

Sets the mesh scale.

Parameters
scalemesh new scale
Note
It activate the dirty flag.

Member Data Documentation

◆ MAX_DEGREE_ANGLE

float Transform::MAX_DEGREE_ANGLE = 180
Note
[-180, 180] = 360

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