-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateCubeTriangles.c
43 lines (43 loc) · 1.82 KB
/
createCubeTriangles.c
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
#include <stdio.h>
#include <stdlib.h>
#include "structures.h"
void createCubeTriangles(double* center, double sideLen, facet* facetArray){//FIXME use integer offsets to avoid fp problems on large models (Do after octree working conversion)
//creation order is x-, x+, y-, y+, z-, z+
int facetIdx = 0;
double len = sideLen/2;
for(int dim = 0; dim < 3; dim++){//each direction
for(int mult = -1; mult <= 2; mult+=2){//positive and negative face
facetArray[facetIdx].p1[dim] = len*mult;//FIXME code duplication
facetArray[facetIdx].p2[dim] = len*mult;//we set all of the dim faces to their plane
facetArray[facetIdx].p3[dim] = len*mult;
facetArray[facetIdx+1].p1[dim] = len*mult;
facetArray[facetIdx+1].p2[dim] = len*mult;
facetArray[facetIdx+1].p3[dim] = len*mult;
int otherDim = 1;
facetArray[facetIdx].p1[(dim+otherDim)%3] = len;
facetArray[facetIdx].p2[(dim+otherDim)%3] = len;
facetArray[facetIdx].p3[(dim+otherDim)%3] = -len;
facetArray[facetIdx+1].p1[(dim+otherDim)%3] = -len;
facetArray[facetIdx+1].p2[(dim+otherDim)%3] = len;
facetArray[facetIdx+1].p3[(dim+otherDim)%3] = -len;
otherDim = 2;
facetArray[facetIdx].p1[(dim+otherDim)%3] = -len;
facetArray[facetIdx].p2[(dim+otherDim)%3] = len;
facetArray[facetIdx].p3[(dim+otherDim)%3] = -len;
facetArray[facetIdx+1].p1[(dim+otherDim)%3] = len;
facetArray[facetIdx+1].p2[(dim+otherDim)%3] = len;
facetArray[facetIdx+1].p3[(dim+otherDim)%3] = -len;
facetIdx+=2;
}
//The above code creates a cube centered on the origin. The below code translates that cube.
}
for(int tIdx = 0; tIdx < 12; tIdx++){
facetArray[tIdx].attr = 0;
for(int dim = 0; dim < 3; dim++){
facetArray[tIdx].vec[dim] = 0;
facetArray[tIdx].p1[dim]+= center[dim];
facetArray[tIdx].p2[dim]+= center[dim];
facetArray[tIdx].p3[dim]+= center[dim];
}
}
}