History

100,000 voxel death star with concentric shells

Philip Rosedale committed 13 years ago

Commit 26fd44f1 parent e7aa1422 files · +26 −15Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+23−13
@@ -8,8 +8,10 @@ · 7 unmodified lines
88
99 #include "VoxelSystem.h"
1010
11−const float MAX_UNIT_ANY_AXIS = 20.0f;
12−const float CUBE_WIDTH = 0.01f;
11+const float MAX_Y_AXIS = 2.0;
12+const float MAX_X_AXIS = 20.0;
13+const float MAX_Z_AXIS = 20.0;
14+
1315 const int VERTICES_PER_VOXEL = 8;
1416 const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL;
1517 const int COLOR_VALUES_PER_VOXEL = 3 * VERTICES_PER_VOXEL;
@@ -50,7 +52,7 @@ void VoxelSystem::init(int numberOfRandomVoxels) { · 34 unmodified lines
5052 // position / color are random for now
5153
5254 voxelsRendered = numberOfRandomVoxels;
53−
55+
5456 // there are 3 points for each vertices, 24 vertices in each cube
5557 GLfloat *verticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * numberOfRandomVoxels];
5658
@@ -65,24 +67,32 @@ void VoxelSystem::init(int numberOfRandomVoxels) { · 8 unmodified lines
6567
6668 for (int n = 0; n < numberOfRandomVoxels; n++) {
6769 // pick a random point for the center of the cube
70+ const float DEATH_STAR_RADIUS = 4.0;
71+ const float MAX_CUBE = 0.05;
72+ float azimuth = randFloat()*2*PI;
73+ float altitude = randFloat()*PI - PI/2;
74+ float radius = DEATH_STAR_RADIUS;
75+ float thisScale = MAX_CUBE*1/(float)(rand()%8 + 1);
76+ float radius_twiddle = (DEATH_STAR_RADIUS/100)*powf(2, (float)(rand()%8));
77+ radius += radius_twiddle + (randFloat()*DEATH_STAR_RADIUS/12 - DEATH_STAR_RADIUS/24);
6878 glm::vec3 position = glm::vec3(
69− randomFloat(MAX_UNIT_ANY_AXIS * 2) - MAX_UNIT_ANY_AXIS,
70− randomFloat(MAX_UNIT_ANY_AXIS * 2) - MAX_UNIT_ANY_AXIS,
71− randomFloat(MAX_UNIT_ANY_AXIS * 2) - MAX_UNIT_ANY_AXIS
79+ radius * cosf(azimuth) * cosf(altitude),
80+ radius * sinf(azimuth) * cosf(altitude),
81+ radius * sinf(altitude)
7282 );
7383
74− // fill the vertices array
84+ // fill the vertices array, and scale the voxels
7585 GLfloat *currentVerticesPos = verticesArray + (n * VERTEX_POINTS_PER_VOXEL);
76−
7786 for (int v = 0; v < VERTEX_POINTS_PER_VOXEL; v++) {
78− currentVerticesPos[v] = position[v % 3] + (identityVertices[v] * CUBE_WIDTH);
87+ currentVerticesPos[v] = position[v % 3] + (identityVertices[v] * thisScale);
7988 }
8089
8190 // fill the colors array
91+ const float MIN_BRIGHTNESS = 0.25;
8292 GLfloat *currentColorPos = colorsArray + (n * COLOR_VALUES_PER_VOXEL);
83− float voxelR = randomFloat(1);
84− float voxelG = randomFloat(1);
85− float voxelB = randomFloat(1);
93+ float voxelR = MIN_BRIGHTNESS + randomFloat(1)*(1.0 - MIN_BRIGHTNESS);
94+ float voxelG = voxelR;
95+ float voxelB = voxelR;
8696
8797 for (int c = 0; c < VERTICES_PER_VOXEL; c++) {
8898 currentColorPos[0 + (c * 3)] = voxelR;
@@ -109,7 +119,7 @@ void VoxelSystem::init(int numberOfRandomVoxels) { · 20 unmodified lines
109119 // VBO for colorsArray
110120 glGenBuffers(1, &vboColorsID);
111121 glBindBuffer(GL_ARRAY_BUFFER, vboColorsID);
112− glBufferData(GL_ARRAY_BUFFER, VERTICES_PER_VOXEL * sizeof(GLfloat) * numberOfRandomVoxels, colorsArray, GL_STATIC_DRAW);
122+ glBufferData(GL_ARRAY_BUFFER, COLOR_VALUES_PER_VOXEL * sizeof(GLfloat) * numberOfRandomVoxels, colorsArray, GL_STATIC_DRAW);
113123
114124 // VBO for the indicesArray
115125 glGenBuffers(1, &vboIndicesID);