-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshaders.cpp
94 lines (80 loc) · 3.85 KB
/
shaders.cpp
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
#include "shaders.h"
#include <math.h>
#include <vector>
#include "RasterUtil.h"
#include "fwd.h"
/*
void ShaderUtil::PS_Color(VECTOR_2* v, VECTOR_2* a, VECTOR_2* b, VECTOR_2* c)
{
for (unsigned int i = 0; i < 3; i++)
{
if (v->col >> (i * 16) != 0)
{
v->col |= ((unsigned int)(RasterUtil::ImplicitLine(*b, *c, *v) /
ImplicitLine(*b, *c, *a) * (float)(255)) << 16); v->col |= ((unsigned
int)(RasterUtil::ImplicitLine(*a, *c, *v) / ImplicitLine(*a, *c, *b) *
(float)(255)) << 8); v->col |= ((unsigned int)(RasterUtil::ImplicitLine(*a, *b,
*v) / ImplicitLine(*a, *b, *c) * (float)(255)) << 0); break;
}
}
}
*/
void ShaderUtil::VS_Rotate(MATRIX& _matrix, unsigned int axis, float degrees) {
_matrix.DRotate(axis, degrees);
}
void ShaderUtil::MultVertByMatrix(VECTOR_3* vec, MATRIX* matrix) {
VECTOR_3 tempVec{0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
float* vals = matrix->GetMatrix();
tempVec.x = vec->x * vals[0] + vec->y * vals[4] + vec->z * vals[8] +
vec->w * vals[12];
tempVec.y = vec->x * vals[1] + vec->y * vals[5] + vec->z * vals[9] +
vec->w * vals[13];
tempVec.z = vec->x * vals[2] + vec->y * vals[6] + vec->z * vals[10] +
vec->w * vals[14];
tempVec.w = vec->x * vals[3] + vec->y * vals[7] + vec->z * vals[11] +
vec->w * vals[15];
vec->x = tempVec.x;
vec->y = tempVec.y;
vec->z = tempVec.z;
vec->w = tempVec.w;
}
void ShaderUtil::VS_ProjectEdges(MESH& _mesh, CAMERA* camera) {
for (unsigned int i = 0; i < _mesh.GetEdges().size(); i++) {
/* ---------------- MultBy by local matrix. --------------- */
MultVertByMatrix(_mesh.GetEdges()[i]->GetVertex(1), _mesh.GetLocalMatrix());
MultVertByMatrix(_mesh.GetEdges()[i]->GetVertex(2), _mesh.GetLocalMatrix());
/* ---------------- MultBy by world matrix. --------------- */
MultVertByMatrix(_mesh.GetEdges()[i]->GetVertex(1), _mesh.GetWorldMatrix());
MultVertByMatrix(_mesh.GetEdges()[i]->GetVertex(2), _mesh.GetWorldMatrix());
/* ---------------- MultBy by view matrix. ---------------- */
MultVertByMatrix(_mesh.GetEdges()[i]->GetVertex(1),
camera->GetViewMatrix());
MultVertByMatrix(_mesh.GetEdges()[i]->GetVertex(2),
camera->GetViewMatrix());
/* ------------- MultBy by projection matrix. ------------- */
MultVertByMatrix(_mesh.GetEdges()[i]->GetVertex(1),
camera->GetProjMatrix());
MultVertByMatrix(_mesh.GetEdges()[i]->GetVertex(2),
camera->GetProjMatrix());
}
}
void ShaderUtil::VS_ProjectFaces(MESH& _mesh, CAMERA* camera) {
for (unsigned int i = 0; i < _mesh.GetTris().size(); i++) {
/* ---------------- MultBy by local matrix. --------------- */
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(1), _mesh.GetLocalMatrix());
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(2), _mesh.GetLocalMatrix());
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(3), _mesh.GetLocalMatrix());
/* ---------------- MultBy by world matrix. --------------- */
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(1), _mesh.GetWorldMatrix());
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(2), _mesh.GetWorldMatrix());
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(3), _mesh.GetWorldMatrix());
/* ---------------- MultBy by view matrix. ---------------- */
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(1), camera->GetViewMatrix());
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(2), camera->GetViewMatrix());
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(3), camera->GetViewMatrix());
/* ------------- MultBy by projection matrix. ------------- */
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(1), camera->GetProjMatrix());
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(2), camera->GetProjMatrix());
MultVertByMatrix(_mesh.GetTris()[i]->GetVertex(3), camera->GetProjMatrix());
}
}