Brenta Engine 1.0
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::setView(glm::mat4 view)
46{
47 this->view = view;
48}
49
50void Translation::setProjection(float fov, float near, float far)
51{
52 this->projection = glm::perspective(
53 glm::radians(fov),
54 (float) Screen::GetWidth() / (float) Screen::GetHeight(), near, far);
55}
56
57void Translation::setProjection(glm::mat4 projection)
58{
59 this->projection = projection;
60}
61
62void Translation::setModel(glm::mat4 new_model)
63{
64 this->model = new_model;
65}
66
67void Translation::translate(glm::vec3 translation)
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::setShader(Types::ShaderName shader_name)
89{
90 Shader::Use(shader_name);
91
92 Shader::SetMat4(shader_name, "view", this->view);
93 Shader::SetMat4(shader_name, "projection", this->projection);
94 Shader::SetMat4(shader_name, "model", this->model);
95}
static int GetHeight()
Get the height of the window.
Definition screen.cpp:110
static int GetWidth()
Get the width of the window.
Definition screen.cpp:105
static void SetMat4(Types::ShaderName shader_name, const GLchar *name, glm::mat4 value)
Set a 4x4 matrix in the shader.
Definition shader.cpp:90
static void Use(Types::ShaderName shader_name)
Use the shader.
Definition shader.cpp:43
Translation()
Translation constructor.
void setProjection(glm::mat4 projection)
Set the projection matrix.
void setView(glm::mat4 view)
Set the view matrix.
void rotate(glm::vec3 rotation)
Rotate the object.
glm::mat4 view
Camera view matrix.
void translate(glm::vec3 translation)
Translate the object.
void setModel(glm::mat4 model)
Set the model matrix.
void setShader(Types::ShaderName shader_name)
Set the shader.
glm::mat4 model
Object position matrix.
void scale(float scale)
Scale the object.
glm::mat4 projection
Camera projection matrix.