-
Notifications
You must be signed in to change notification settings - Fork 0
/
VerletBuilders.cc
80 lines (73 loc) · 2.59 KB
/
VerletBuilders.cc
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
#include "include/Verlet.h"
#include "include/VerletEdge.h"
#include "include/Mesh.h"
#include <cstdio>
#include <cassert>
Mesh* mkLattice(int x, int y, int z, int linesize, double softness)
{
Mesh *mesh = new Mesh;
Verlet *verls[z][y][x];
int linesizesqrt2 = (int) (linesize * 1.414213562);
Verlet *verl;
for (int k = 0; k < z; k++)
{
for (int i = 0; i < y; i++) // i for rows
{
for (int j = 0; j < x; j++) // j for columns
{
verl = new Verlet(linesize * j, linesize * i, linesize * k);
verls[k][i][j] = verl;
mesh->verlets.push_back(verl);
if (i != 0)
{
mesh->edges.push_back(new VerletEdge(verls[k][i][j], verls[k][i-1][j], softness, linesize));
if (j != x - 1)
{
mesh->edges.push_back(new VerletEdge(verls[k][i][j], verls[k][i-1][j+1], softness, linesizesqrt2));
}
if (j != 0)
{
mesh->edges.push_back(new VerletEdge(verls[k][i][j], verls[k][i-1][j-1], softness, linesizesqrt2));
}
}
if (j != 0)
{
mesh->edges.push_back(new VerletEdge(verls[k][i][j], verls[k][i][j-1], softness, linesizesqrt2));
}
if (k != 0)
{
mesh->edges.push_back(new VerletEdge(verls[k][i][j], verls[k-1][i][j], softness, linesizesqrt2));
}
}
}
}
//printf("made mesh\n");
return mesh;
}
Mesh* mkTube(int x, int y, int linesize, double elast)
{
Verlet *verls[y][x];
Verlet *verl;
Mesh *mesh = new Mesh;
int linesizesqrt2 = (int) (linesize * 1.414213562);
for (int rowN = 0; rowN < y; rowN++)
{
for (int colN = 0; colN < x; colN++)
{
verl = new Verlet(x * linesize, y * linesize, 0);
verls[rowN][colN] = verl;
mesh->verlets.push_back(verl);
if (rowN != 0)
{
mesh->edges.push_back(new VerletEdge(verls[rowN][colN], verls[rowN - 1][colN], elast, linesize));
}
if (colN != 0)
{
mesh->edges.push_back(new VerletEdge(verls[rowN][colN], verls[rowN][colN - 1], elast, linesize));
}
}
mesh->edges.push_back(new VerletEdge(verls[rowN][x - 1], verls[rowN][0], elast, linesize));
}
printf("%d %d\n", mesh->edges.size(), mesh->verlets.size());
return mesh;
}