Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -23,25 +23,27 @@ · 22 unmodified lines | |||
| 23 | 23 | ||
| 24 | const int MAX_VOXELS_PER_SYSTEM = 250000; | 24 | const int MAX_VOXELS_PER_SYSTEM = 250000; |
| 25 | 25 | ||
| 26 | const int VERTICES_PER_VOXEL = 8; | 26 | const int VERTICES_PER_VOXEL = 24; |
| 27 | const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL; | 27 | const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL; |
| 28 | const int INDICES_PER_VOXEL = 3 * 12; | 28 | const int INDICES_PER_VOXEL = 3 * 12; |
| 29 | 29 | ||
| 30 | float identityVertices[] = { 0, 0, 0, | 30 | float identityVertices[] = { 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1, |
| 31 | 1, 0, 0, | 31 | 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1, |
| 32 | 1, 1, 0, | 32 | 0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1 }; |
| 33 | 0, 1, 0, | 33 | |
| 34 | 0, 0, 1, | 34 | GLfloat identityNormals[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, |
| 35 | 1, 0, 1, | 35 | 0,0,+1, 0,0,+1, 0,0,+1, 0,0,+1, |
| 36 | 1, 1, 1, | 36 | 0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0, |
| 37 | 0, 1, 1 }; | 37 | 0,-1,0, 0,-1,0, 0,+1,0, 0,+1,0, |
| 38 | 38 | -1,0,0, +1,0,0, +1,0,0, -1,0,0, | |
| 39 | GLubyte identityIndices[] = { 0,1,2, 0,2,3, | 39 | -1,0,0, +1,0,0, +1,0,0, -1,0,0 }; |
| 40 | 0,1,5, 0,4,5, | 40 | |
| 41 | 0,3,7, 0,4,7, | 41 | GLubyte identityIndices[] = { 0,2,1, 0,3,2, // Z- . |
| 42 | 1,2,6, 1,5,6, | 42 | 8,9,13, 8,13,12, // Y- |
| 43 | 2,3,7, 2,6,7, | 43 | 16,23,19, 16,20,23, // X- |
| 44 | 4,5,6, 4,6,7 }; | 44 | 17,18,22, 17,22,21, // X+ |
| 45 | 10,11,15, 10,15,14, // Y+ | ||
| 46 | 4,5,6, 4,6,7 }; // Z+ . | ||
| 45 | 47 | ||
| 46 | VoxelSystem::VoxelSystem() { | 48 | VoxelSystem::VoxelSystem() { |
| 47 | voxelsRendered = 0; | 49 | voxelsRendered = 0; |
| @@ -49,7 +51,7 @@ VoxelSystem::VoxelSystem() { · 1 unmodified line | |||
| 49 | pthread_mutex_init(&bufferWriteLock, NULL); | 51 | pthread_mutex_init(&bufferWriteLock, NULL); |
| 50 | } | 52 | } |
| 51 | 53 | ||
| 52 | VoxelSystem::~VoxelSystem() { | 54 | VoxelSystem::~VoxelSystem() { |
| 53 | delete[] readVerticesArray; | 55 | delete[] readVerticesArray; |
| 54 | delete[] writeVerticesArray; | 56 | delete[] writeVerticesArray; |
| 55 | delete[] readColorsArray; | 57 | delete[] readColorsArray; |
| @@ -70,9 +72,9 @@ void VoxelSystem::setViewerHead(Head *newViewerHead) { · 14 unmodified lines | |||
| 70 | // Complaints: Brad :) | 72 | // Complaints: Brad :) |
| 71 | // To Do: Need to add color data to the file. | 73 | // To Do: Need to add color data to the file. |
| 72 | void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) { | 74 | void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) { |
| 73 | 75 | ||
| 74 | tree->loadVoxelsFile(fileName,wantColorRandomizer); | 76 | tree->loadVoxelsFile(fileName,wantColorRandomizer); |
| 75 | 77 | ||
| 76 | copyWrittenDataToReadArrays(); | 78 | copyWrittenDataToReadArrays(); |
| 77 | } | 79 | } |
| 78 | 80 | ||
| @@ -118,7 +120,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 39 unmodified lines | |||
| 118 | 120 | ||
| 119 | unsigned char command = *sourceBuffer; | 121 | unsigned char command = *sourceBuffer; |
| 120 | unsigned char *voxelData = sourceBuffer + 1; | 122 | unsigned char *voxelData = sourceBuffer + 1; |
| 121 | 123 | ||
| 122 | switch(command) { | 124 | switch(command) { |
| 123 | case PACKET_HEADER_VOXEL_DATA: | 125 | case PACKET_HEADER_VOXEL_DATA: |
| 124 | // ask the VoxelTree to read the bitstream into the tree | 126 | // ask the VoxelTree to read the bitstream into the tree |
| @@ -131,7 +133,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 6 unmodified lines | |||
| 131 | case PACKET_HEADER_Z_COMMAND: | 133 | case PACKET_HEADER_Z_COMMAND: |
| 132 | 134 | ||
| 133 | // the Z command is a special command that allows the sender to send high level semantic | 135 | // the Z command is a special command that allows the sender to send high level semantic |
| 134 | // requests, like erase all, or add sphere scene, different receivers may handle these | 136 | // requests, like erase all, or add sphere scene, different receivers may handle these |
| 135 | // messages differently | 137 | // messages differently |
| 136 | char* packetData = (char *)sourceBuffer; | 138 | char* packetData = (char *)sourceBuffer; |
| 137 | char* command = &packetData[1]; // start of the command | 139 | char* command = &packetData[1]; // start of the command |
| @@ -152,7 +154,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 14 unmodified lines | |||
| 152 | } | 154 | } |
| 153 | break; | 155 | break; |
| 154 | } | 156 | } |
| 155 | 157 | ||
| 156 | setupNewVoxelsForDrawing(); | 158 | setupNewVoxelsForDrawing(); |
| 157 | return numBytes; | 159 | return numBytes; |
| 158 | } | 160 | } |
| @@ -212,11 +214,11 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 53 unmodified lines | |||
| 212 | for (int i = 0; i < 8; i++) { | 214 | for (int i = 0; i < 8; i++) { |
| 213 | // check if there is a child here | 215 | // check if there is a child here |
| 214 | if (currentNode->children[i] != NULL) { | 216 | if (currentNode->children[i] != NULL) { |
| 215 | 217 | ||
| 216 | glm::vec3 childNodePosition; | 218 | glm::vec3 childNodePosition; |
| 217 | copyFirstVertexForCode(currentNode->children[i]->octalCode,(float*)&childNodePosition); | 219 | copyFirstVertexForCode(currentNode->children[i]->octalCode,(float*)&childNodePosition); |
| 218 | childNodePosition *= (float)TREE_SCALE; // scale it up | 220 | childNodePosition *= (float)TREE_SCALE; // scale it up |
| 219 | 221 | ||
| 220 | /**** disabled ************************************************************************************************ | 222 | /**** disabled ************************************************************************************************ |
| 221 | // Note: Stephen, I intentionally left this in so you would talk to me about it. Here's the deal, this code | 223 | // Note: Stephen, I intentionally left this in so you would talk to me about it. Here's the deal, this code |
| 222 | // doesn't seem to work correctly. It returns X and Z flipped and the values are negative. Since we use the | 224 | // doesn't seem to work correctly. It returns X and Z flipped and the values are negative. Since we use the |
| @@ -226,7 +228,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 3 unmodified lines | |||
| 226 | // calculate the child's position based on the parent position | 228 | // calculate the child's position based on the parent position |
| 227 | for (int j = 0; j < 3; j++) { | 229 | for (int j = 0; j < 3; j++) { |
| 228 | childNodePosition[j] = nodePosition[j]; | 230 | childNodePosition[j] = nodePosition[j]; |
| 229 | 231 | ||
| 230 | if (oneAtBit(branchIndexWithDescendant(currentNode->octalCode,currentNode->children[i]->octalCode),(7 - j))) { | 232 | if (oneAtBit(branchIndexWithDescendant(currentNode->octalCode,currentNode->children[i]->octalCode),(7 - j))) { |
| 231 | childNodePosition[j] -= (powf(0.5, *currentNode->children[i]->octalCode) * TREE_SCALE); | 233 | childNodePosition[j] -= (powf(0.5, *currentNode->children[i]->octalCode) * TREE_SCALE); |
| 232 | } | 234 | } |
| @@ -243,13 +245,13 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 10 unmodified lines | |||
| 243 | float startVertex[3]; | 245 | float startVertex[3]; |
| 244 | copyFirstVertexForCode(currentNode->octalCode,(float*)&startVertex); | 246 | copyFirstVertexForCode(currentNode->octalCode,(float*)&startVertex); |
| 245 | float voxelScale = 1 / powf(2, *currentNode->octalCode); | 247 | float voxelScale = 1 / powf(2, *currentNode->octalCode); |
| 246 | 248 | ||
| 247 | // populate the array with points for the 8 vertices | 249 | // populate the array with points for the 8 vertices |
| 248 | // and RGB color for each added vertex | 250 | // and RGB color for each added vertex |
| 249 | for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) { | 251 | for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) { |
| 250 | *writeVerticesEndPointer = startVertex[j % 3] + (identityVertices[j] * voxelScale); | 252 | *writeVerticesEndPointer = startVertex[j % 3] + (identityVertices[j] * voxelScale); |
| 251 | *(writeColorsArray + (writeVerticesEndPointer - writeVerticesArray)) = currentNode->getColor()[j % 3]; | 253 | *(writeColorsArray + (writeVerticesEndPointer - writeVerticesArray)) = currentNode->getColor()[j % 3]; |
| 252 | 254 | ||
| 253 | writeVerticesEndPointer++; | 255 | writeVerticesEndPointer++; |
| 254 | } | 256 | } |
| 255 | voxelsAdded++; | 257 | voxelsAdded++; |
| @@ -271,7 +273,7 @@ void VoxelSystem::init() { · 15 unmodified lines | |||
| 271 | readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 273 | readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 272 | 274 | ||
| 273 | GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 275 | GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 274 | 276 | ||
| 275 | // populate the indicesArray | 277 | // populate the indicesArray |
| 276 | // this will not change given new voxels, so we can set it all up now | 278 | // this will not change given new voxels, so we can set it all up now |
| 277 | for (int n = 0; n < MAX_VOXELS_PER_SYSTEM; n++) { | 279 | for (int n = 0; n < MAX_VOXELS_PER_SYSTEM; n++) { |
| @@ -279,84 +281,107 @@ void VoxelSystem::init() { · 1 unmodified line | |||
| 279 | int voxelIndexOffset = n * INDICES_PER_VOXEL; | 281 | int voxelIndexOffset = n * INDICES_PER_VOXEL; |
| 280 | GLuint *currentIndicesPos = indicesArray + voxelIndexOffset; | 282 | GLuint *currentIndicesPos = indicesArray + voxelIndexOffset; |
| 281 | int startIndex = (n * VERTICES_PER_VOXEL); | 283 | int startIndex = (n * VERTICES_PER_VOXEL); |
| 282 | 284 | ||
| 283 | for (int i = 0; i < INDICES_PER_VOXEL; i++) { | 285 | for (int i = 0; i < INDICES_PER_VOXEL; i++) { |
| 284 | // add indices for this side of the cube | 286 | // add indices for this side of the cube |
| 285 | currentIndicesPos[i] = startIndex + identityIndices[i]; | 287 | currentIndicesPos[i] = startIndex + identityIndices[i]; |
| 286 | } | 288 | } |
| 287 | } | 289 | } |
| 288 | 290 | ||
| 291 | GLfloat *normalsArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | ||
| 292 | GLfloat *normalsArrayEndPointer = normalsArray; | ||
| 293 | |||
| 294 | // populate the normalsArray | ||
| 295 | for (int n = 0; n < MAX_VOXELS_PER_SYSTEM; n++) { | ||
| 296 | for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) { | ||
| 297 | *(normalsArrayEndPointer++) = identityNormals[i]; | ||
| 298 | } | ||
| 299 | } | ||
| 300 | |||
| 289 | // VBO for the verticesArray | 301 | // VBO for the verticesArray |
| 290 | glGenBuffers(1, &vboVerticesID); | 302 | glGenBuffers(1, &vboVerticesID); |
| 291 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); | 303 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); |
| 292 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); | 304 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); |
| 293 | 305 | ||
| 306 | // VBO for the normalsArray | ||
| 307 | glGenBuffers(1, &vboNormalsID); | ||
| 308 | glBindBuffer(GL_ARRAY_BUFFER, vboNormalsID); | ||
| 309 | glBufferData(GL_ARRAY_BUFFER, | ||
| 310 | VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, | ||
| 311 | normalsArray, GL_STATIC_DRAW); | ||
| 312 | |||
| 294 | // VBO for colorsArray | 313 | // VBO for colorsArray |
| 295 | glGenBuffers(1, &vboColorsID); | 314 | glGenBuffers(1, &vboColorsID); |
| 296 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); | 315 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); |
| 297 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); | 316 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); |
| 298 | 317 | ||
| 299 | // VBO for the indicesArray | 318 | // VBO for the indicesArray |
| 300 | glGenBuffers(1, &vboIndicesID); | 319 | glGenBuffers(1, &vboIndicesID); |
| 301 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); | 320 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); |
| 302 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, | 321 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, |
| 303 | INDICES_PER_VOXEL * sizeof(GLuint) * MAX_VOXELS_PER_SYSTEM, | 322 | INDICES_PER_VOXEL * sizeof(GLuint) * MAX_VOXELS_PER_SYSTEM, |
| 304 | indicesArray, GL_STATIC_DRAW); | 323 | indicesArray, GL_STATIC_DRAW); |
| 305 | 324 | ||
| 306 | // delete the indices array that is no longer needed | 325 | // delete the indices and normals arrays that are no longer needed |
| 307 | delete[] indicesArray; | 326 | delete[] indicesArray; |
| 327 | delete[] normalsArray; | ||
| 308 | } | 328 | } |
| 309 | 329 | ||
| 310 | void VoxelSystem::render() { | 330 | void VoxelSystem::render() { |
| 311 | 331 | ||
| 312 | glPushMatrix(); | 332 | glPushMatrix(); |
| 313 | 333 | ||
| 314 | if (readVerticesEndPointer != readVerticesArray) { | 334 | if (readVerticesEndPointer != readVerticesArray) { |
| 315 | // try to lock on the buffer write | 335 | // try to lock on the buffer write |
| 316 | // just avoid pulling new data if it is currently being written | 336 | // just avoid pulling new data if it is currently being written |
| 317 | if (pthread_mutex_trylock(&bufferWriteLock) == 0) { | 337 | if (pthread_mutex_trylock(&bufferWriteLock) == 0) { |
| 318 | 338 | ||
| 319 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); | 339 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); |
| 320 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray); | 340 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray); |
| 321 | 341 | ||
| 322 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); | 342 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); |
| 323 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray); | 343 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray); |
| 324 | 344 | ||
| 325 | readVerticesEndPointer = readVerticesArray; | 345 | readVerticesEndPointer = readVerticesArray; |
| 326 | 346 | ||
| 327 | pthread_mutex_unlock(&bufferWriteLock); | 347 | pthread_mutex_unlock(&bufferWriteLock); |
| 328 | } | 348 | } |
| 329 | } | 349 | } |
| 330 | 350 | ||
| 331 | // tell OpenGL where to find vertex and color information | 351 | // tell OpenGL where to find vertex and color information |
| 332 | glEnableClientState(GL_VERTEX_ARRAY); | 352 | glEnableClientState(GL_VERTEX_ARRAY); |
| 353 | glEnableClientState(GL_NORMAL_ARRAY); | ||
| 333 | glEnableClientState(GL_COLOR_ARRAY); | 354 | glEnableClientState(GL_COLOR_ARRAY); |
| 334 | 355 | ||
| 335 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); | 356 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); |
| 336 | glVertexPointer(3, GL_FLOAT, 0, 0); | 357 | glVertexPointer(3, GL_FLOAT, 0, 0); |
| 337 | 358 | ||
| 359 | glBindBuffer(GL_ARRAY_BUFFER, vboNormalsID); | ||
| 360 | glNormalPointer(GL_FLOAT, 0, 0); | ||
| 361 | |||
| 338 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); | 362 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); |
| 339 | glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); | 363 | glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); |
| 340 | 364 | ||
| 341 | // draw the number of voxels we have | 365 | // draw the number of voxels we have |
| 342 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); | 366 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); |
| 343 | glScalef(10, 10, 10); | 367 | glScalef(10, 10, 10); |
| 344 | glDrawElements(GL_TRIANGLES, 36 * voxelsRendered, GL_UNSIGNED_INT, 0); | 368 | glDrawElements(GL_TRIANGLES, 36 * voxelsRendered, GL_UNSIGNED_INT, 0); |
| 345 | 369 | ||
| 346 | // deactivate vertex and color arrays after drawing | 370 | // deactivate vertex and color arrays after drawing |
| 347 | glDisableClientState(GL_VERTEX_ARRAY); | 371 | glDisableClientState(GL_VERTEX_ARRAY); |
| 372 | glDisableClientState(GL_NORMAL_ARRAY); | ||
| 348 | glDisableClientState(GL_COLOR_ARRAY); | 373 | glDisableClientState(GL_COLOR_ARRAY); |
| 349 | 374 | ||
| 350 | // bind with 0 to switch back to normal operation | 375 | // bind with 0 to switch back to normal operation |
| 351 | glBindBuffer(GL_ARRAY_BUFFER, 0); | 376 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 352 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 377 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 353 | 378 | ||
| 354 | // scale back down to 1 so heads aren't massive | 379 | // scale back down to 1 so heads aren't massive |
| 355 | glPopMatrix(); | 380 | glPopMatrix(); |
| 356 | } | 381 | } |
| 357 | 382 | ||
| 358 | void VoxelSystem::simulate(float deltaTime) { | 383 | void VoxelSystem::simulate(float deltaTime) { |
| 359 | 384 | ||
| 360 | } | 385 | } |
| 361 | 386 | ||
| 362 | int VoxelSystem::_nodeCount = 0; | 387 | int VoxelSystem::_nodeCount = 0; |
| @@ -367,7 +392,7 @@ bool VoxelSystem::randomColorOperation(VoxelNode* node, bool down, void* extraDa · 4 unmodified lines | |||
| 367 | if (down) { | 392 | if (down) { |
| 368 | return true; | 393 | return true; |
| 369 | } | 394 | } |
| 370 | 395 | ||
| 371 | _nodeCount++; | 396 | _nodeCount++; |
| 372 | if (node->isColored()) { | 397 | if (node->isColored()) { |
| 373 | nodeColor newColor = { 0,0,0,1 }; | 398 | nodeColor newColor = { 0,0,0,1 }; |
| @@ -398,9 +423,9 @@ bool VoxelSystem::falseColorizeRandomOperation(VoxelNode* node, bool down, void* · 24 unmodified lines | |||
| 398 | if (down) { | 423 | if (down) { |
| 399 | return true; | 424 | return true; |
| 400 | } | 425 | } |
| 401 | 426 | ||
| 402 | _nodeCount++; | 427 | _nodeCount++; |
| 403 | 428 | ||
| 404 | // always false colorize | 429 | // always false colorize |
| 405 | unsigned char newR = randomColorValue(150); | 430 | unsigned char newR = randomColorValue(150); |
| 406 | unsigned char newG = randomColorValue(150); | 431 | unsigned char newG = randomColorValue(150); |
| @@ -427,7 +452,7 @@ bool VoxelSystem::trueColorizeOperation(VoxelNode* node, bool down, void* extraD · 20 unmodified lines | |||
| 427 | if (down) { | 452 | if (down) { |
| 428 | return true; | 453 | return true; |
| 429 | } | 454 | } |
| 430 | 455 | ||
| 431 | _nodeCount++; | 456 | _nodeCount++; |
| 432 | node->setFalseColored(false); | 457 | node->setFalseColored(false); |
| 433 | //printf("setting true color for node %d\n",_nodeCount); | 458 | //printf("setting true color for node %d\n",_nodeCount); |
| @@ -448,23 +473,23 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, bool down, void* · 14 unmodified lines | |||
| 448 | if (down) { | 473 | if (down) { |
| 449 | return true; | 474 | return true; |
| 450 | } | 475 | } |
| 451 | 476 | ||
| 452 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; | 477 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; |
| 453 | 478 | ||
| 454 | _nodeCount++; | 479 | _nodeCount++; |
| 455 | 480 | ||
| 456 | // only do this for truely colored voxels... | 481 | // only do this for truely colored voxels... |
| 457 | if (node->isColored()) { | 482 | if (node->isColored()) { |
| 458 | // first calculate the AAbox for the voxel | 483 | // first calculate the AAbox for the voxel |
| 459 | AABox voxelBox; | 484 | AABox voxelBox; |
| 460 | node->getAABox(voxelBox); | 485 | node->getAABox(voxelBox); |
| 461 | 486 | ||
| 462 | voxelBox.scale(TREE_SCALE); | 487 | voxelBox.scale(TREE_SCALE); |
| 463 | 488 | ||
| 464 | printf("voxelBox corner=(%f,%f,%f) x=%f\n", | 489 | printf("voxelBox corner=(%f,%f,%f) x=%f\n", |
| 465 | voxelBox.getCorner().x, voxelBox.getCorner().y, voxelBox.getCorner().z, | 490 | voxelBox.getCorner().x, voxelBox.getCorner().y, voxelBox.getCorner().z, |
| 466 | voxelBox.getSize().x); | 491 | voxelBox.getSize().x); |
| 467 | 492 | ||
| 468 | // If the voxel is outside of the view frustum, then false color it red | 493 | // If the voxel is outside of the view frustum, then false color it red |
| 469 | if (ViewFrustum::OUTSIDE == viewFrustum->boxInFrustum(voxelBox)) { | 494 | if (ViewFrustum::OUTSIDE == viewFrustum->boxInFrustum(voxelBox)) { |
| 470 | // Out of view voxels are colored RED | 495 | // Out of view voxels are colored RED |
| @@ -481,7 +506,7 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, bool down, void* · 10 unmodified lines | |||
| 481 | } else { | 506 | } else { |
| 482 | printf("voxel not colored, don't consider it\n"); | 507 | printf("voxel not colored, don't consider it\n"); |
| 483 | } | 508 | } |
| 484 | 509 | ||
| 485 | return true; // keep going! | 510 | return true; // keep going! |
| 486 | } | 511 | } |
| 487 | 512 | ||
| @@ -503,7 +528,7 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, bool d · 15 unmodified lines | |||
| 503 | } | 528 | } |
| 504 | 529 | ||
| 505 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; | 530 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; |
| 506 | 531 | ||
| 507 | // only do this for truly colored voxels... | 532 | // only do this for truly colored voxels... |
| 508 | if (node->isColored()) { | 533 | if (node->isColored()) { |
| 509 | 534 | ||
| @@ -517,10 +542,10 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, bool d · 7 unmodified lines | |||
| 517 | 542 | ||
| 518 | // scale up the node position | 543 | // scale up the node position |
| 519 | nodePosition = nodePosition*(float)TREE_SCALE; | 544 | nodePosition = nodePosition*(float)TREE_SCALE; |
| 520 | 545 | ||
| 521 | float halfUnitForVoxel = powf(0.5, *node->octalCode) * (0.5 * TREE_SCALE); | 546 | float halfUnitForVoxel = powf(0.5, *node->octalCode) * (0.5 * TREE_SCALE); |
| 522 | glm::vec3 viewerPosition = viewFrustum->getPosition(); | 547 | glm::vec3 viewerPosition = viewFrustum->getPosition(); |
| 523 | 548 | ||
| 524 | //printf("halfUnitForVoxel=%f\n",halfUnitForVoxel); | 549 | //printf("halfUnitForVoxel=%f\n",halfUnitForVoxel); |
| 525 | //printf("viewer.x=%f y=%f z=%f \n", viewerPosition.x, viewerPosition.y, viewerPosition.z); | 550 | //printf("viewer.x=%f y=%f z=%f \n", viewerPosition.x, viewerPosition.y, viewerPosition.z); |
| 526 | //printf("node.x=%f y=%f z=%f \n", nodePosition.x, nodePosition.y, nodePosition.z); | 551 | //printf("node.x=%f y=%f z=%f \n", nodePosition.x, nodePosition.y, nodePosition.z); |
| @@ -533,7 +558,7 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, bool d · 6 unmodified lines | |||
| 533 | _nodeCount++; | 558 | _nodeCount++; |
| 534 | 559 | ||
| 535 | float distanceRatio = (_minDistance==_maxDistance) ? 1 : (distance - _minDistance)/(_maxDistance - _minDistance); | 560 | float distanceRatio = (_minDistance==_maxDistance) ? 1 : (distance - _minDistance)/(_maxDistance - _minDistance); |
| 536 | 561 | ||
| 537 | // We want to colorize this in 16 bug chunks of color | 562 | // We want to colorize this in 16 bug chunks of color |
| 538 | const unsigned char maxColor = 255; | 563 | const unsigned char maxColor = 255; |
| 539 | const unsigned char colorBands = 16; | 564 | const unsigned char colorBands = 16; |
| @@ -542,7 +567,7 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, bool d · 2 unmodified lines | |||
| 542 | unsigned char newR = (colorBand*(gradientOver/colorBands))+(maxColor-gradientOver); | 567 | unsigned char newR = (colorBand*(gradientOver/colorBands))+(maxColor-gradientOver); |
| 543 | unsigned char newG = 0; | 568 | unsigned char newG = 0; |
| 544 | unsigned char newB = 0; | 569 | unsigned char newB = 0; |
| 545 | //printf("Setting color down=%s distance=%f min=%f max=%f distanceRatio=%f color=%d \n", | 570 | //printf("Setting color down=%s distance=%f min=%f max=%f distanceRatio=%f color=%d \n", |
| 546 | // (down ? "TRUE" : "FALSE"), distance, _minDistance, _maxDistance, distanceRatio, (int)newR); | 571 | // (down ? "TRUE" : "FALSE"), distance, _minDistance, _maxDistance, distanceRatio, (int)newR); |
| 547 | 572 | ||
| 548 | node->setFalseColor(newR,newG,newB); | 573 | node->setFalseColor(newR,newG,newB); |
| @@ -568,7 +593,7 @@ bool VoxelSystem::getDistanceFromViewRangeOperation(VoxelNode* node, bool down, · 19 unmodified lines | |||
| 568 | //printf("getDistanceFromViewRangeOperation() down=%s\n",(down ? "TRUE" : "FALSE")); | 593 | //printf("getDistanceFromViewRangeOperation() down=%s\n",(down ? "TRUE" : "FALSE")); |
| 569 | 594 | ||
| 570 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; | 595 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; |
| 571 | 596 | ||
| 572 | // only do this for truly colored voxels... | 597 | // only do this for truly colored voxels... |
| 573 | if (node->isColored()) { | 598 | if (node->isColored()) { |
| 574 | 599 | ||
| @@ -614,7 +639,7 @@ void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) { · 39 unmodified lines | |||
| 614 | printf("determining distance range for %d nodes\n",_nodeCount); | 639 | printf("determining distance range for %d nodes\n",_nodeCount); |
| 615 | 640 | ||
| 616 | _nodeCount = 0; | 641 | _nodeCount = 0; |
| 617 | 642 | ||
| 618 | tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); | 643 | tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); |
| 619 | printf("setting in distance false color for %d nodes\n",_nodeCount); | 644 | printf("setting in distance false color for %d nodes\n",_nodeCount); |
| 620 | setupNewVoxelsForDrawing(); | 645 | setupNewVoxelsForDrawing(); |