-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreeform_grid.cpp
78 lines (62 loc) · 2.3 KB
/
freeform_grid.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
// freeform_grid.cpp
/*
This file is part of L-Echo.
L-Echo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
L-Echo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with L-Echo. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include "echo_error.h"
#include "freeform_grid.h"
#include "echo_math.h"
#include "grid.h"
/// Initializes an empty freeform grid sloping right and up
freeform_grid::freeform_grid() : grid()
{
init(NULL, NULL, NULL, new vector3f(0.5f, 0.5f, 0), new vector3f(0, 0, 0.5f));
}
/// Initialize the freeform grid with the info, neighbors, and side vectors
freeform_grid::freeform_grid(grid_info_t* my_info, grid* my_prev, grid* my_next, vector3f* my_dir, vector3f* my_width) : grid()
{
init(my_info, my_prev, my_next, my_dir, my_width);
}
/// Re-Initialize the freeform grid with the info, neighbors, and side vectors
void freeform_grid::init(grid_info_t* my_info, grid* my_prev, grid* my_next, vector3f* my_dir, vector3f* my_width)
{
dir = my_dir;
width = my_width;
grid::init(my_info, my_prev, my_next);
}
/// Makes the side vectors null
void freeform_grid::init_to_null()
{
grid::init_to_null();
dir = NULL;
width = NULL;
}
/// Generate points that makes the grid shaped like a parallelogram
vector3f** freeform_grid::generate_points(grid_info_t* my_info)
{
vector3f** ret = new vector3f*[4];
vector3f* pos = my_info->pos;
ret[0] = new vector3f(pos->x + dir->x + width->x
, pos->y + dir->y + width->y
, pos->z + dir->z + width->z);
ret[1] = new vector3f(pos->x - dir->x + width->x
, pos->y - dir->y + width->y
, pos->z - dir->z + width->z);
ret[2] = new vector3f(pos->x - dir->x - width->x
, pos->y - dir->y - width->y
, pos->z - dir->z - width->z);
ret[3] = new vector3f(pos->x + dir->x - width->x
, pos->y + dir->y - width->y
, pos->z + dir->z - width->z);
return(ret);
}