Brenta Engine 1.2
Loading...
Searching...
No Matches
translation.cpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#include <brenta/translation.hpp>
7
8using namespace brenta::types;
9
11{
12 this->view = glm::mat4(1.0f);
13 this->projection = glm::mat4(1.0f);
14 this->model = glm::mat4(1.0f);
15}
16
17translation::translation(glm::mat4 view, glm::mat4 projection, glm::mat4 model)
18{
19 this->view = view;
20 this->projection = projection;
21 this->model = model;
22}
23
24void translation::set_view(glm::mat4 view)
25{
26 this->view = view;
27}
28
29void translation::set_projection(int window_width, int window_height,
30 float fov, float near, float far)
31{
32 this->projection = glm::perspective(
33 glm::radians(fov),
34 (float) window_width / (float) window_height, near, far);
35}
36
37void translation::set_projection(glm::mat4 projection)
38{
39 this->projection = projection;
40}
41
42void translation::set_model(glm::mat4 new_model)
43{
44 this->model = new_model;
45}
46
48{
49 this->model = glm::translate(this->model, translation);
50}
51
52// Note: the order of rotations is important
53void translation::rotate(glm::vec3 rotation)
54{
55 this->model = glm::rotate(this->model, glm::radians(rotation.x),
56 glm::vec3(1.0f, 0.0f, 0.0f));
57 this->model = glm::rotate(this->model, glm::radians(rotation.y),
58 glm::vec3(0.0f, 1.0f, 0.0f));
59 this->model = glm::rotate(this->model, glm::radians(rotation.z),
60 glm::vec3(0.0f, 0.0f, 1.0f));
61}
62
63void translation::scale(float scale)
64{
65 this->model = glm::scale(this->model, glm::vec3(scale));
66}
67
68bool translation::set_shader(types::shader_name_t shader_name)
69{
70 if (!shader::use(shader_name))
71 return false;
72
73 if (!shader::set_mat4(shader_name, "view", this->view) ||
74 !shader::set_mat4(shader_name, "projection", this->projection) ||
75 !shader::set_mat4(shader_name, "model", this->model))
76 return false;
77
78 return true;
79}
Model class.
Definition model.hpp:26
static bool set_mat4(types::shader_name_t shader_name, const GLchar *name, glm::mat4 value)
Set a 4x4 matrix in the shader.
Definition shader.cpp:114
static bool use(types::shader_name_t shader_name)
Use the shader.
Definition shader.cpp:24
Translation util class.
void set_projection(glm::mat4 projection)
Set the projection matrix.
glm::mat4 projection
Camera projection matrix.
glm::mat4 model
Object position matrix.
void set_model(glm::mat4 model)
Set the model matrix.
void set_view(glm::mat4 view)
Set the view matrix.
glm::mat4 view
Camera view matrix.
bool set_shader(types::shader_name_t shader_name)
Set the shader.
void translate(glm::vec3 translation)
Translate the object.
void scale(float scale)
Scale the object.
translation()
Translation constructor.
void rotate(glm::vec3 rotation)
Rotate the object.