6 #include <glm/gtc/constants.hpp> 7 #include <glm/gtc/matrix_transform.hpp> 8 #include <glm/gtc/matrix_access.hpp> 19 : modelMatrix(modelMatrix_)
21 inverseMatrix = glm::inverse(modelMatrix_);
39 const glm::mat4 &trans_mat,
40 const glm::mat4 &invtrans_mat,
49 const glm::mat4 &new_trans_mat
92 const glm::vec3 &rot_axis
97 const glm::vec3 &trans_vec,
104 const glm::vec3 &scaling_vec,
111 const glm::mat4 &matrix
114 glm::mat4 modelMatrix;
115 glm::mat4 inverseMatrix;
125 return inverseMatrix;
130 return modelMatrix[3].xyz;
135 modelMatrix[3] = glm::vec4(location, 1.0f);
139 modelMatrix = new_trans_mat;
140 inverseMatrix = glm::inverse(modelMatrix);
144 const glm::mat4 &trans_mat,
145 const glm::mat4 &invtrans_mat,
148 if (mult_order ==
LEFT) {
149 modelMatrix = trans_mat * modelMatrix;
150 inverseMatrix = inverseMatrix * invtrans_mat;
153 modelMatrix = modelMatrix * trans_mat;
154 inverseMatrix = invtrans_mat * inverseMatrix;
161 glm::rotate(glm::mat4(), radians, glm::vec3(1.0f, 0.0f, 0.0f)),
162 glm::rotate(glm::mat4(), -radians, glm::vec3(1.0f, 0.0f, 0.0f)),
170 glm::rotate(glm::mat4(), radians, glm::vec3(0.0f, 1.0f, 0.0f)),
171 glm::rotate(glm::mat4(), -radians, glm::vec3(0.0f, 1.0f, 0.0f)),
179 glm::rotate(glm::mat4(), radians, glm::vec3(0.0f, 0.0f, 1.0f)),
180 glm::rotate(glm::mat4(), -radians, glm::vec3(0.0f, 0.0f, 1.0f)),
188 glm::rotate(glm::mat4(), radians, rot_axis),
189 glm::rotate(glm::mat4(), -radians, rot_axis),
197 glm::translate(glm::mat4(), trans_vec),
198 glm::translate(glm::mat4(), -trans_vec),
206 glm::scale(glm::mat4(), scaling_vec),
207 glm::scale(glm::mat4(), 1.0f / scaling_vec),
214 std::stringstream matStr;
216 for (
int row = 0; row < 4; ++row) {
217 for (
int col = 0; col < 4; ++col) {
218 matStr << matrix[col][row] <<
" ";
M_result = M * M_inc.
Definition: sceneobject.hpp:34
void scale(const glm::vec3 &scaling_vec, Order mult_order)
Applies a scale operation to the current transformation.
Definition: sceneobject.hpp:203
void setTransform(const glm::mat4 &new_trans_mat)
Replaces current matrix and sets its inverse.
Definition: sceneobject.hpp:138
void translate(const glm::vec3 &trans_vec, Order mult_order)
Applies a translation operation to the current transformation.
Definition: sceneobject.hpp:194
Order
enum specifying matrix multiplication order.
Definition: sceneobject.hpp:31
glm::vec3 getLocation() const
Returns the location of the SceneObject.
Definition: sceneobject.hpp:128
std::string matrixToString(const glm::mat4 &matrix)
Get a string to visualize the given matrix.
Definition: sceneobject.hpp:212
void rotateZ(float radians, Order mult_order)
Applies a Z axis rotation operation to the current transformation.
Definition: sceneobject.hpp:176
void setLocation(const glm::vec3 &location)
Set SceneObject's location: rightmost column of the model matrix.
Definition: sceneobject.hpp:133
M_result = M_inc * M.
Definition: sceneobject.hpp:33
const glm::mat4 & getInverseMatrix() const
Definition: sceneobject.hpp:123
void applyTransformation(const glm::mat4 &trans_mat, const glm::mat4 &invtrans_mat, Order mult_order)
Apply a transformation matrix to the current matrix.
Definition: sceneobject.hpp:143
A base class for all scene objects.
Definition: sceneobject.hpp:15
void rotateX(float radians, Order mult_order)
Applies an X axis rotation operation to the current transformation.
Definition: sceneobject.hpp:158
const glm::mat4 & getMatrix() const
Definition: sceneobject.hpp:118
void rotateY(float radians, Order mult_order)
Applies a Y axis rotation operation to the current transformation.
Definition: sceneobject.hpp:167
void rotate(float radians, Order mult_order, const glm::vec3 &rot_axis)
Applies a rotation around a given vector (= axis)
Definition: sceneobject.hpp:185