-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrizes.cpp
More file actions
175 lines (133 loc) · 4.76 KB
/
Copy pathMatrizes.cpp
File metadata and controls
175 lines (133 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <iostream>
#include <iomanip>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
void PrintMatrix(const glm::mat4& M){
for (int i = 0; i < 4; ++i){
for (int j = 0; j < 4; ++j){
std::cout
<< std::setw(10)
<< std::setprecision(4)
<< std::fixed
<< M[i][j] << " ";
}
std::cout << std::endl;
}
}
void TranslationMatrix(){
std::cout << std::endl;
std::cout << "==================" << std::endl;
std::cout << "Matriz de Translacao" << std::endl;
std::cout << "==================" << std::endl;
glm::vec4 Position{ 10, 10, 10, 1 };
glm::vec4 Direction{ 10, 10, 10, 0 };
glm::vec3 Translate{ 10, 10, 10 };
glm::mat4 Translation = glm::translate(glm::identity<glm::mat4>(), Translate);
PrintMatrix(Translation);
std::cout << std::endl;
Position = Translation * Position;
Direction = Translation * Direction;
std::cout << glm::to_string(Position) << std::endl;
std::cout << glm::to_string(Direction) << std::endl;
}
void RotationMatrix(){
std::cout << std::endl;
std::cout << "==================" << std::endl;
std::cout << "Matriz de Rotacao" << std::endl;
std::cout << "==================" << std::endl;
glm::vec4 Position{ 100, 0, 0, 1 };
glm::vec4 Direction{ 100, 0, 0, 0 };
glm::vec3 Axis{ 0, 0, 1 };
glm::mat4 Rotation = glm::rotate(glm::identity<glm::mat4>(), glm::radians(90.0f), Axis);
PrintMatrix(Rotation);
std::cout << std::endl;
Position = Rotation * Position;
Direction = Rotation * Direction;
std::cout << glm::to_string(Position) << std::endl;
std::cout << glm::to_string(Direction) << std::endl;
}
void ScaleMatrix(){
std::cout << std::endl;
std::cout << "==================" << std::endl;
std::cout << "Matriz de Escala" << std::endl;
std::cout << "==================" << std::endl;
glm::vec4 Position{ 100, 100, 0, 1 };
glm::vec4 Direction{ 100, 100, 0, 0 };
glm::vec3 ScaleAmount{ 2, 2, 2 };
glm::mat4 Scale = glm::scale(glm::identity<glm::mat4>(), ScaleAmount);
PrintMatrix(Scale);
std::cout << std::endl;
Position = Scale * Position;
Direction = Scale * Direction;
std::cout << glm::to_string(Position) << std::endl;
std::cout << glm::to_string(Direction) << std::endl;
}
void ComposedMatrix(){
std::cout << std::endl;
std::cout << "==================" << std::endl;
std::cout << "Composicao" << std::endl;
std::cout << "==================" << std::endl;
glm::vec4 Position{ 1, 1, 0, 1 };
glm::vec4 Direction{ 1, 1, 0, 0 };
glm::vec3 Translate{ 0, 10, 0 };
glm::mat4 Translation = glm::translate(glm::identity<glm::mat4>(), Translate);
glm::vec3 Axis{ 0, 0, 1 };
glm::mat4 Rotation = glm::rotate(glm::identity<glm::mat4>(), glm::radians(45.0f), Axis);
glm::vec3 ScaleAmount{ 2, 2, 0 };
glm::mat4 Scale = glm::scale(glm::identity<glm::mat4>(), ScaleAmount);
std::cout << "Translacao: " << std::endl;
PrintMatrix(Translation);
std::cout << std::endl;
std::cout << "Rotacao: " << std::endl;
PrintMatrix(Rotation);
std::cout << std::endl;
std::cout << "Escala: " << std::endl;
PrintMatrix(Scale);
std::cout << std::endl;
glm::mat4 Transform = Translation * Rotation * Scale;
std::cout << "Transformacao: " << std::endl;
PrintMatrix(Transform);
std::cout << std::endl;
Position = Transform * Position;
Direction = Transform * Direction;
std::cout << std::endl;
std::cout << glm::to_string(Position) << std::endl;
std::cout << glm::to_string(Direction) << std::endl;
}
void ModelViewProject() {
std::cout << std::endl;
std::cout << "==================" << std::endl;
std::cout << "Modelo de Projecao de Vista" << std::endl;
std::cout << "==================" << std::endl;
//Matriz Composta
glm::mat4 ModelMatrix = glm::identity<glm::mat4>();
//View
glm::vec3 VRP{0, 0, 10};
glm::vec3 PontoFocal{0, 0, 0};
glm::vec3 ViewUp{0, 1, 0};
glm::mat4 ViewMatrix = glm::lookAt(VRP, PontoFocal, ViewUp);
std::cout << "View" << std::endl;
PrintMatrix(ViewMatrix);
constexpr float angulo_de_visao = glm::radians(45.0f);
const float razao_aspecto = 800.0f / 600.0f;
const float near = 0.001f;
const float far = 1000.0f;
glm::mat4 ProjectionMatrix = glm::perspective(angulo_de_visao, razao_aspecto, near, far);
std::cout << "Projection" << std::endl;
PrintMatrix(ProjectionMatrix);
glm::mat4 ModelViewProjection = ProjectionMatrix * ViewMatrix * ModelMatrix;
std::cout << "ModelViewProjection" << std::endl;
PrintMatrix(ModelViewProjection);
glm::vec4 Position{ 0, 0 , 0, 1 };
Position = ModelViewProjection * Position;
Position - Position.w;
std::cout << glm::to_string(Position) << std::endl;
}
int main(){
TranslationMatrix();
RotationMatrix();
ScaleMatrix();
ComposedMatrix();
ModelViewProject();
return 0;
}