-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhypercube.cpp
More file actions
68 lines (59 loc) · 1.76 KB
/
hypercube.cpp
File metadata and controls
68 lines (59 loc) · 1.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
#include <iostream>
using namespace std;
#include <glm/glm.hpp>
void outputEdge(int axis, glm::vec4 p, glm::ivec4 cs, glm::ivec4 ce, int step)
{
double d = 1.0/step;
glm::vec4 v(0,0,0,0);
v[axis] = 1;
for (int i=-step; i<=step; i++) {
glm::vec4 w = ((float) d*i)*v + p;
glm::ivec4 c = (cs*(step-i) + ce*(i+step))/(2*step);
cout << w[0] << " " << w[1] << " " << w[2] << " " << w[3] << " "
<< c[0] << " " << c[1] << " " << c[2] << " " << c[3] << endl;
}
}
int main()
{
int c[4][2][4] =
{ { { 255, 0, 0 } , { 255, 255, 0} },
{ { 0, 255, 0 }, { 0, 255, 255} },
{ { 0, 0, 255 }, {255, 0, 255} },
{ { 128, 128, 0}, {0, 128, 128} } };
int step=50;
int numpoints = (2*step+1)*8*4;
cout << "ply" << endl
<< "format ascii 1.0" << endl
<< "element vertex "
<< numpoints << endl
<< "property float x" << endl
<< "property float y" << endl
<< "property float z" << endl
<< "property float w" << endl
<< "property uchar red" << endl
<< "property uchar green" << endl
<< "property uchar blue" << endl
<< "property uchar alpha" << endl
<< "element face 0" << endl
<< "property list uchar int vertex_indices" << endl
<< "end_header" << endl;
glm::ivec4 cs, ce;
for (int i=0; i<4; i++) {
cs = glm::ivec4(c[i][0][0], c[i][0][1], c[i][0][2], c[i][0][3]);
ce = glm::ivec4(c[i][1][0], c[i][1][1], c[i][1][2], c[i][1][3]);
glm::vec4 v;
for (int j=0; j<16; j++) {
if ( (j >> i) & 1) {
for (int k=0; k<4; k++) {
if (k==i) {
v[k]=0;
} else {
v[k] = 2*( (j >> k) & 1 ) - 1;
}
}
cerr << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << endl;
outputEdge(i, v, cs, ce, step);
}
}
}
}