Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -8,8 +8,10 @@ · 7 unmodified lines | ||
| 8 | 8 | |
| 9 | 9 | #include "VoxelSystem.h" |
| 10 | 10 | |
| 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 | + | |
| 13 | 15 | const int VERTICES_PER_VOXEL = 8; |
| 14 | 16 | const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL; |
| 15 | 17 | const int COLOR_VALUES_PER_VOXEL = 3 * VERTICES_PER_VOXEL; |
| @@ -50,7 +52,7 @@ void VoxelSystem::init(int numberOfRandomVoxels) { · 34 unmodified lines | ||
| 50 | 52 | // position / color are random for now |
| 51 | 53 | |
| 52 | 54 | voxelsRendered = numberOfRandomVoxels; |
| 53 | − | |
| 55 | + | |
| 54 | 56 | // there are 3 points for each vertices, 24 vertices in each cube |
| 55 | 57 | GLfloat *verticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * numberOfRandomVoxels]; |
| 56 | 58 | |
| @@ -65,24 +67,32 @@ void VoxelSystem::init(int numberOfRandomVoxels) { · 8 unmodified lines | ||
| 65 | 67 | |
| 66 | 68 | for (int n = 0; n < numberOfRandomVoxels; n++) { |
| 67 | 69 | // 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); | |
| 68 | 78 | 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) | |
| 72 | 82 | ); |
| 73 | 83 | |
| 74 | − // fill the vertices array | |
| 84 | + // fill the vertices array, and scale the voxels | |
| 75 | 85 | GLfloat *currentVerticesPos = verticesArray + (n * VERTEX_POINTS_PER_VOXEL); |
| 76 | − | |
| 77 | 86 | 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); | |
| 79 | 88 | } |
| 80 | 89 | |
| 81 | 90 | // fill the colors array |
| 91 | + const float MIN_BRIGHTNESS = 0.25; | |
| 82 | 92 | 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; | |
| 86 | 96 | |
| 87 | 97 | for (int c = 0; c < VERTICES_PER_VOXEL; c++) { |
| 88 | 98 | currentColorPos[0 + (c * 3)] = voxelR; |
| @@ -109,7 +119,7 @@ void VoxelSystem::init(int numberOfRandomVoxels) { · 20 unmodified lines | ||
| 109 | 119 | // VBO for colorsArray |
| 110 | 120 | glGenBuffers(1, &vboColorsID); |
| 111 | 121 | 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); | |
| 113 | 123 | |
| 114 | 124 | // VBO for the indicesArray |
| 115 | 125 | glGenBuffers(1, &vboIndicesID); |