GameKit  0.0.1a
C++ gamedev tools
Transform.cpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Transform.cpp
5  *
6  * Description:
7  *
8  * Created: 11/11/2018 17:39:55
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #define GLM_FORCE_RADIANS
15 #include <glm/gtc/matrix_transform.hpp>
16 
17 #include "gk/gl/Transform.hpp"
18 
19 namespace gk {
20 
21 const Transform Transform::Identity;
22 
24  m_matrix *= transform.m_matrix;
25  return *this;
26 }
27 
28 Transform& Transform::translate(float x, float y, float z) {
29  m_matrix = glm::translate(m_matrix, {x, y, z});
30  return *this;
31 }
32 
33 Transform& Transform::rotate(float angle, const Vector3f& axis) {
34  float rotationAngle = angle * RADIANS_PER_DEGREES;
35  m_matrix = glm::rotate(m_matrix, rotationAngle, {axis.x, axis.y, axis.z});
36  return *this;
37 }
38 
39 Transform& Transform::scale(float scaleX, float scaleY, float scaleZ) {
40  m_matrix = glm::scale(m_matrix, {scaleX, scaleY, scaleZ});
41  return *this;
42 }
43 
44 Transform operator*(const Transform& left, const Transform &right) {
45  return Transform(left).combine(right);
46 }
47 
48 Transform& operator*=(Transform &left, const Transform &right) {
49  return left.combine(right);
50 }
51 
52 }
53 
Transform & translate(float x, float y, float z=0)
Definition: Transform.cpp:28
Vector2< T > operator*(T n, Vector2< T > &vector2)
Definition: Vector2.hpp:65
static const Transform Identity
Definition: Transform.hpp:50
Transform & combine(const Transform &transform)
Definition: Transform.cpp:23
Transform & rotate(float angle)
Definition: Transform.hpp:38
Transform & scale(float scaleX, float scaleY, float scaleZ=1)
Definition: Transform.cpp:39
glm::mat4 m_matrix
Definition: Transform.hpp:53
Transform()=default
Transform & operator*=(Transform &left, const Transform &right)
Definition: Transform.cpp:48
#define RADIANS_PER_DEGREES
Definition: Transform.hpp:23