Brenta Engine 1.1
Loading...
Searching...
No Matches
translation.cpp
1/*
2 * MIT License
3 *
4 * Copyright (c) 2024 Giovanni Santini
5
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 */
26
27#include "translation.hpp"
28
29using namespace brenta::types;
30
32{
33 this->view = glm::mat4(1.0f);
34 this->projection = glm::mat4(1.0f);
35 this->model = glm::mat4(1.0f);
36}
37
38translation::translation(glm::mat4 view, glm::mat4 projection, glm::mat4 model)
39{
40 this->view = view;
41 this->projection = projection;
42 this->model = model;
43}
44
45void translation::set_view(glm::mat4 view)
46{
47 this->view = view;
48}
49
50void translation::set_projection(float fov, float near, float far)
51{
52 this->projection = glm::perspective(
53 glm::radians(fov),
54 (float) screen::get_width() / (float) screen::get_height(), near, far);
55}
56
57void translation::set_projection(glm::mat4 projection)
58{
59 this->projection = projection;
60}
61
62void translation::set_model(glm::mat4 new_model)
63{
64 this->model = new_model;
65}
66
68{
69 this->model = glm::translate(this->model, translation);
70}
71
72/* Note: the order of rotations is important */
73void translation::rotate(glm::vec3 rotation)
74{
75 this->model = glm::rotate(this->model, glm::radians(rotation.x),
76 glm::vec3(1.0f, 0.0f, 0.0f));
77 this->model = glm::rotate(this->model, glm::radians(rotation.y),
78 glm::vec3(0.0f, 1.0f, 0.0f));
79 this->model = glm::rotate(this->model, glm::radians(rotation.z),
80 glm::vec3(0.0f, 0.0f, 1.0f));
81}
82
83void translation::scale(float scale)
84{
85 this->model = glm::scale(this->model, glm::vec3(scale));
86}
87
88void translation::set_shader(types::shader_name_t shader_name)
89{
90 shader::use(shader_name);
91
92 shader::set_mat4(shader_name, "view", this->view);
93 shader::set_mat4(shader_name, "projection", this->projection);
94 shader::set_mat4(shader_name, "model", this->model);
95}
Model class.
Definition model.hpp:48
static int get_width()
Get the width of the window.
Definition screen.cpp:105
static int get_height()
Get the height of the window.
Definition screen.cpp:110
static void use(types::shader_name_t shader_name)
Use the shader.
Definition shader.cpp:43
static void set_mat4(types::shader_name_t shader_name, const GLchar *name, glm::mat4 value)
Set a 4x4 matrix in the shader.
Definition shader.cpp:88
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_shader(types::shader_name_t shader_name)
Set the shader.
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.
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.