Botcraft 1.21.4
Loading...
Searching...
No Matches
Transformation.cpp
Go to the documentation of this file.
2
3#include <glm/glm.hpp>
4#include <glm/gtc/matrix_transform.hpp>
5#include <glm/gtc/type_ptr.hpp>
6
7namespace Botcraft
8{
9 namespace Renderer
10 {
11 //To avoid to include glm in header
12 struct IMatrix
13 {
14 IMatrix(const glm::mat4& m_ = glm::mat4(0.0f))
15 {
16 m = m_;
17 }
18
19 glm::mat4 m;
20 };
21
22 Translation::Translation(const float x_, const float y_, const float z_)
23 {
24 x = x_;
25 y = y_;
26 z = z_;
27 }
28
30 {
31 m.m = glm::translate(m.m, glm::vec3(x, y, z));
32 }
33
34 const std::string Translation::Print() const
35 {
36 std::string output = "Translation: ";
37 output += "(" + std::to_string(x) + ";" + std::to_string(y) + ";" + std::to_string(z) + ")";
38 return output;
39 }
40
41
42 Rotation::Rotation(const float axis_x_, const float axis_y_, const float axis_z_, const float deg_angle_)
43 {
44 axis_x = axis_x_;
45 axis_y = axis_y_;
46 axis_z = axis_z_;
47 deg_angle = deg_angle_;
48 }
49
51 {
52 m.m = glm::rotate(m.m, glm::radians(deg_angle), glm::vec3(axis_x, axis_y, axis_z));
53 }
54
55 const std::string Rotation::Print() const
56 {
57 std::string output = "Rotation: ";
58 output += "(" + std::to_string(axis_x) + ";" + std::to_string(axis_y) + ";" + std::to_string(axis_z) + ")";
59 output += " " + std::to_string(deg_angle);
60 return output;
61 }
62
63 Scale::Scale(const float axis_x_, const float axis_y_, const float axis_z_)
64 {
65 axis_x = axis_x_;
66 axis_y = axis_y_;
67 axis_z = axis_z_;
68 }
69
71 {
72 m.m = glm::scale(m.m, glm::vec3(axis_x, axis_y, axis_z));
73 }
74
75 const std::string Scale::Print() const
76 {
77 std::string output = "Scale: ";
78 output += "(" + std::to_string(axis_x) + ";" + std::to_string(axis_y) + ";" + std::to_string(axis_z) + ")";
79 return output;
80 }
81 } // Renderer
82} // Botcraft
virtual void ApplyTransformation(IMatrix &m) const override
virtual const std::string Print() const override
Rotation(const float axis_x_=0.0f, const float axis_y_=0.0f, const float axis_z_=0.0f, const float deg_angle_=0.0f)
Scale(const float axis_x_=1.0f, const float axis_y_=1.0f, const float axis_z_=1.0f)
virtual void ApplyTransformation(IMatrix &m) const override
virtual const std::string Print() const override
virtual void ApplyTransformation(IMatrix &m) const override
Translation(const float x_=0.0f, const float y_=0.0f, const float z_=0.0f)
virtual const std::string Print() const override
IMatrix(const glm::mat4 &m_=glm::mat4(0.0f))