-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSolverGrid.cpp
143 lines (123 loc) · 3.01 KB
/
SolverGrid.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
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
#include "SolverGrid.h"
#include "glm/gtc/matrix_transform.hpp"
const float BOX_VERTICES[] = {
-0.5f, -0.5f, -0.5f, 1.0f,
0.5f, -0.5f, -0.5f, 1.0f,
0.5f, 0.5f, -0.5f, 1.0f,
-0.5f, 0.5f, -0.5f, 1.0f,
-0.5f, -0.5f, 0.5f, 1.0f,
0.5f, -0.5f, 0.5f, 1.0f,
0.5f, 0.5f, 0.5f, 1.0f,
-0.5f, 0.5f, 0.5f, 1.0f
};
const GLuint BOX_EDGES[] = {
0,1, 1,2, 2,3, 3,0,
4,5, 5,6, 6,7, 7,4,
0,4, 1,5, 2,6, 3,7
};
const float EMITTER_VERTICES[] = {
0.0f, 0.0f, 0.0f, 1.0f,
-0.5f, -1.0f, 0.0f, 1.0f,
-0.7f, -1.0f, -0.7f, 1.0f,
-0.7f, -1.0f, 0.7f, 1.0f
};
const int EMITTER_INDICES[] = {
0, 1,
0, 2,
0, 3
};
SolverGrid::SolverGrid()
{
// Setup drawable grid
vaBox.Create(sizeof(BOX_VERTICES) / (sizeof(float) * 4));
vaBox.SetArrayBuffer(0, GL_FLOAT, 4, BOX_VERTICES);
vaBox.SetElementBuffer(0, 12 * 3, BOX_EDGES);
// Setup drawable emitter
vaEmitter.Create(16);
vaEmitter.SetArrayBuffer(0, GL_FLOAT, 4, EMITTER_VERTICES);
vaEmitter.SetElementBuffer(0, 3 * 2, EMITTER_INDICES);
}
SolverGrid::~SolverGrid()
{
}
/** @brief Returns the transformation matrix of the grid
* @returns Transformation matrix
*/
glm::mat4 SolverGrid::getModelMatrix(void) const
{
return modelMX;
}
/** @brief Translates the grid by the given (x,y,z) translation
*/
void SolverGrid::translate(glm::vec3 translation)
{
modelMX = glm::translate(modelMX, translation);
}
/** @brief Translates the grid by the given x,y,z translation
*/
void SolverGrid::translate(float x, float y, float z)
{
this->translate(glm::vec3(x, y, z));
}
/** @brief Scales the grid by the given (x,y,z) translation
*/
void SolverGrid::scale(glm::vec3 scaling)
{
modelMX = glm::scale(modelMX, scaling);
}
/** @brief Returns the current set voxel length on the grid
*/
float SolverGrid::getVoxelLength(void) const
{
return voxelLength;
}
/** @brief Sets the current voxel length on the grid
*/
void SolverGrid::setVoxelLength(float size)
{
voxelLength = size;
}
/**
* @brief Returns the corner which the largest coordinates - aka TopRightBack
*/
glm::vec3 SolverGrid::getTopRightBack(void) const
{
glm::vec4 translated = this->modelMX * glm::vec4(topRightBack, 1.0f);
return glm::vec3(translated.x, translated.y, translated.z);
}
/**
* @brief Returns the corner which the smallest coordinates - aka BtmLeftFront
*/
glm::vec3 SolverGrid::getBtmLeftFront(void) const
{
glm::vec4 translated = this->modelMX * glm::vec4(btmLeftFront, 1.0f);
return glm::vec3(translated.x, translated.y, translated.z);
}
/**
* @brief Returns the size of the grid
*
*/
glm::vec3 SolverGrid::getGridSize(void) const
{
return glm::abs(getBtmLeftFront() - getTopRightBack());
}
/**
* @brief Returns the resolution - how many voxel per axis - for each axis
*
*/
glm::ivec3 SolverGrid::getGridResolution(void) const
{
return glm::ivec3(getGridSize() / getVoxelLength());
}
/** @brief Returns the emitters initial velocity
*/
glm::vec3 SolverGrid::getEmitterVelocity(void)
{
return emitterVelocity;
}
/** @brief Returns the emitter position
*/
glm::vec3 SolverGrid::getEmitterPosition(void)
{
return emitterPosition;
}