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
8 8
9#include "VoxelSystem.h"9#include "VoxelSystem.h"
10 10
11const float MAX_UNIT_ANY_AXIS = 20.0f;11const float MAX_Y_AXIS = 2.0;
12const float CUBE_WIDTH = 0.01f;12const float MAX_X_AXIS = 20.0;
13const float MAX_Z_AXIS = 20.0;
14
13const int VERTICES_PER_VOXEL = 8;15const int VERTICES_PER_VOXEL = 8;
14const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL;16const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL;
15const int COLOR_VALUES_PER_VOXEL = 3 * VERTICES_PER_VOXEL;17const int COLOR_VALUES_PER_VOXEL = 3 * VERTICES_PER_VOXEL;
@@ -50,7 +52,7 @@ void VoxelSystem::init(int numberOfRandomVoxels) { · 34 unmodified lines
50 // position / color are random for now52 // position / color are random for now
51 53
52 voxelsRendered = numberOfRandomVoxels;54 voxelsRendered = numberOfRandomVoxels;
53 55
54 // there are 3 points for each vertices, 24 vertices in each cube56 // there are 3 points for each vertices, 24 vertices in each cube
55 GLfloat *verticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * numberOfRandomVoxels];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 for (int n = 0; n < numberOfRandomVoxels; n++) { 68 for (int n = 0; n < numberOfRandomVoxels; n++) {
67 // pick a random point for the center of the cube69 // 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 glm::vec3 position = glm::vec3(78 glm::vec3 position = glm::vec3(
69 randomFloat(MAX_UNIT_ANY_AXIS * 2) - MAX_UNIT_ANY_AXIS,79 radius * cosf(azimuth) * cosf(altitude),
70 randomFloat(MAX_UNIT_ANY_AXIS * 2) - MAX_UNIT_ANY_AXIS,80 radius * sinf(azimuth) * cosf(altitude),
71 randomFloat(MAX_UNIT_ANY_AXIS * 2) - MAX_UNIT_ANY_AXIS81 radius * sinf(altitude)
72 );82 );
73 83
74 // fill the vertices array84 // fill the vertices array, and scale the voxels
75 GLfloat *currentVerticesPos = verticesArray + (n * VERTEX_POINTS_PER_VOXEL);85 GLfloat *currentVerticesPos = verticesArray + (n * VERTEX_POINTS_PER_VOXEL);
76
77 for (int v = 0; v < VERTEX_POINTS_PER_VOXEL; v++) {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 // fill the colors array90 // fill the colors array
91 const float MIN_BRIGHTNESS = 0.25;
82 GLfloat *currentColorPos = colorsArray + (n * COLOR_VALUES_PER_VOXEL);92 GLfloat *currentColorPos = colorsArray + (n * COLOR_VALUES_PER_VOXEL);
83 float voxelR = randomFloat(1);93 float voxelR = MIN_BRIGHTNESS + randomFloat(1)*(1.0 - MIN_BRIGHTNESS);
84 float voxelG = randomFloat(1);94 float voxelG = voxelR;
85 float voxelB = randomFloat(1);95 float voxelB = voxelR;
86 96
87 for (int c = 0; c < VERTICES_PER_VOXEL; c++) {97 for (int c = 0; c < VERTICES_PER_VOXEL; c++) {
88 currentColorPos[0 + (c * 3)] = voxelR;98 currentColorPos[0 + (c * 3)] = voxelR;
@@ -109,7 +119,7 @@ void VoxelSystem::init(int numberOfRandomVoxels) { · 20 unmodified lines
109 // VBO for colorsArray119 // VBO for colorsArray
110 glGenBuffers(1, &vboColorsID);120 glGenBuffers(1, &vboColorsID);
111 glBindBuffer(GL_ARRAY_BUFFER, vboColorsID);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 // VBO for the indicesArray124 // VBO for the indicesArray
115 glGenBuffers(1, &vboIndicesID);125 glGenBuffers(1, &vboIndicesID);