Showing the changes to interface/src/VoxelSystem.cpp (1 of 31 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; |
| @@ -58,8 +60,8 @@ VoxelSystem::~VoxelSystem() { · 2 unmodified lines | |||
| 58 | pthread_mutex_destroy(&bufferWriteLock); | 60 | pthread_mutex_destroy(&bufferWriteLock); |
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | void VoxelSystem::setViewerHead(Head *newViewerHead) { | 63 | void VoxelSystem::setViewerAvatar(Avatar *newViewerAvatar) { |
| 62 | viewerHead = newViewerHead; | 64 | viewerAvatar = newViewerAvatar; |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 65 | ////////////////////////////////////////////////////////////////////////////////////////// | 67 | ////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -70,9 +72,9 @@ void VoxelSystem::setViewerHead(Head *newViewerHead) { · 4 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 | ||
| @@ -119,7 +121,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 40 unmodified lines | |||
| 119 | 121 | ||
| 120 | unsigned char command = *sourceBuffer; | 122 | unsigned char command = *sourceBuffer; |
| 121 | unsigned char *voxelData = sourceBuffer + 1; | 123 | unsigned char *voxelData = sourceBuffer + 1; |
| 122 | 124 | ||
| 123 | switch(command) { | 125 | switch(command) { |
| 124 | case PACKET_HEADER_VOXEL_DATA: | 126 | case PACKET_HEADER_VOXEL_DATA: |
| 125 | { | 127 | { |
| @@ -204,7 +206,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 78 unmodified lines | |||
| 204 | case PACKET_HEADER_Z_COMMAND: | 206 | case PACKET_HEADER_Z_COMMAND: |
| 205 | 207 | ||
| 206 | // the Z command is a special command that allows the sender to send high level semantic | 208 | // the Z command is a special command that allows the sender to send high level semantic |
| 207 | // requests, like erase all, or add sphere scene, different receivers may handle these | 209 | // requests, like erase all, or add sphere scene, different receivers may handle these |
| 208 | // messages differently | 210 | // messages differently |
| 209 | char* packetData = (char *)sourceBuffer; | 211 | char* packetData = (char *)sourceBuffer; |
| 210 | char* command = &packetData[1]; // start of the command | 212 | char* command = &packetData[1]; // start of the command |
| @@ -225,7 +227,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 14 unmodified lines | |||
| 225 | } | 227 | } |
| 226 | break; | 228 | break; |
| 227 | } | 229 | } |
| 228 | 230 | ||
| 229 | setupNewVoxelsForDrawing(); | 231 | setupNewVoxelsForDrawing(); |
| 230 | return numBytes; | 232 | return numBytes; |
| 231 | } | 233 | } |
| @@ -258,7 +260,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 26 unmodified lines | |||
| 258 | int voxelsAdded = 0; | 260 | int voxelsAdded = 0; |
| 259 | 261 | ||
| 260 | float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE); | 262 | float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE); |
| 261 | glm::vec3 viewerPosition = viewerHead->getBodyPosition(); | 263 | glm::vec3 viewerPosition = viewerAvatar->getPosition(); |
| 262 | 264 | ||
| 263 | // debug LOD code | 265 | // debug LOD code |
| 264 | glm::vec3 debugNodePosition; | 266 | glm::vec3 debugNodePosition; |
| @@ -285,11 +287,11 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 20 unmodified lines | |||
| 285 | for (int i = 0; i < 8; i++) { | 287 | for (int i = 0; i < 8; i++) { |
| 286 | // check if there is a child here | 288 | // check if there is a child here |
| 287 | if (currentNode->children[i] != NULL) { | 289 | if (currentNode->children[i] != NULL) { |
| 288 | 290 | ||
| 289 | glm::vec3 childNodePosition; | 291 | glm::vec3 childNodePosition; |
| 290 | copyFirstVertexForCode(currentNode->children[i]->octalCode,(float*)&childNodePosition); | 292 | copyFirstVertexForCode(currentNode->children[i]->octalCode,(float*)&childNodePosition); |
| 291 | childNodePosition *= (float)TREE_SCALE; // scale it up | 293 | childNodePosition *= (float)TREE_SCALE; // scale it up |
| 292 | 294 | ||
| 293 | /**** disabled ************************************************************************************************ | 295 | /**** disabled ************************************************************************************************ |
| 294 | // Note: Stephen, I intentionally left this in so you would talk to me about it. Here's the deal, this code | 296 | // Note: Stephen, I intentionally left this in so you would talk to me about it. Here's the deal, this code |
| 295 | // doesn't seem to work correctly. It returns X and Z flipped and the values are negative. Since we use the | 297 | // doesn't seem to work correctly. It returns X and Z flipped and the values are negative. Since we use the |
| @@ -299,7 +301,7 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 3 unmodified lines | |||
| 299 | // calculate the child's position based on the parent position | 301 | // calculate the child's position based on the parent position |
| 300 | for (int j = 0; j < 3; j++) { | 302 | for (int j = 0; j < 3; j++) { |
| 301 | childNodePosition[j] = nodePosition[j]; | 303 | childNodePosition[j] = nodePosition[j]; |
| 302 | 304 | ||
| 303 | if (oneAtBit(branchIndexWithDescendant(currentNode->octalCode,currentNode->children[i]->octalCode),(7 - j))) { | 305 | if (oneAtBit(branchIndexWithDescendant(currentNode->octalCode,currentNode->children[i]->octalCode),(7 - j))) { |
| 304 | childNodePosition[j] -= (powf(0.5, *currentNode->children[i]->octalCode) * TREE_SCALE); | 306 | childNodePosition[j] -= (powf(0.5, *currentNode->children[i]->octalCode) * TREE_SCALE); |
| 305 | } | 307 | } |
| @@ -316,13 +318,13 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 10 unmodified lines | |||
| 316 | float startVertex[3]; | 318 | float startVertex[3]; |
| 317 | copyFirstVertexForCode(currentNode->octalCode,(float*)&startVertex); | 319 | copyFirstVertexForCode(currentNode->octalCode,(float*)&startVertex); |
| 318 | float voxelScale = 1 / powf(2, *currentNode->octalCode); | 320 | float voxelScale = 1 / powf(2, *currentNode->octalCode); |
| 319 | 321 | ||
| 320 | // populate the array with points for the 8 vertices | 322 | // populate the array with points for the 8 vertices |
| 321 | // and RGB color for each added vertex | 323 | // and RGB color for each added vertex |
| 322 | for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) { | 324 | for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) { |
| 323 | *writeVerticesEndPointer = startVertex[j % 3] + (identityVertices[j] * voxelScale); | 325 | *writeVerticesEndPointer = startVertex[j % 3] + (identityVertices[j] * voxelScale); |
| 324 | *(writeColorsArray + (writeVerticesEndPointer - writeVerticesArray)) = currentNode->getColor()[j % 3]; | 326 | *(writeColorsArray + (writeVerticesEndPointer - writeVerticesArray)) = currentNode->getColor()[j % 3]; |
| 325 | 327 | ||
| 326 | writeVerticesEndPointer++; | 328 | writeVerticesEndPointer++; |
| 327 | } | 329 | } |
| 328 | voxelsAdded++; | 330 | voxelsAdded++; |
| @@ -344,7 +346,7 @@ void VoxelSystem::init() { · 15 unmodified lines | |||
| 344 | readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 346 | readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 345 | 347 | ||
| 346 | GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | 348 | GLuint *indicesArray = new GLuint[INDICES_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; |
| 347 | 349 | ||
| 348 | // populate the indicesArray | 350 | // populate the indicesArray |
| 349 | // this will not change given new voxels, so we can set it all up now | 351 | // this will not change given new voxels, so we can set it all up now |
| 350 | for (int n = 0; n < MAX_VOXELS_PER_SYSTEM; n++) { | 352 | for (int n = 0; n < MAX_VOXELS_PER_SYSTEM; n++) { |
| @@ -352,84 +354,107 @@ void VoxelSystem::init() { · 1 unmodified line | |||
| 352 | int voxelIndexOffset = n * INDICES_PER_VOXEL; | 354 | int voxelIndexOffset = n * INDICES_PER_VOXEL; |
| 353 | GLuint *currentIndicesPos = indicesArray + voxelIndexOffset; | 355 | GLuint *currentIndicesPos = indicesArray + voxelIndexOffset; |
| 354 | int startIndex = (n * VERTICES_PER_VOXEL); | 356 | int startIndex = (n * VERTICES_PER_VOXEL); |
| 355 | 357 | ||
| 356 | for (int i = 0; i < INDICES_PER_VOXEL; i++) { | 358 | for (int i = 0; i < INDICES_PER_VOXEL; i++) { |
| 357 | // add indices for this side of the cube | 359 | // add indices for this side of the cube |
| 358 | currentIndicesPos[i] = startIndex + identityIndices[i]; | 360 | currentIndicesPos[i] = startIndex + identityIndices[i]; |
| 359 | } | 361 | } |
| 360 | } | 362 | } |
| 361 | 363 | ||
| 364 | GLfloat *normalsArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * MAX_VOXELS_PER_SYSTEM]; | ||
| 365 | GLfloat *normalsArrayEndPointer = normalsArray; | ||
| 366 | |||
| 367 | // populate the normalsArray | ||
| 368 | for (int n = 0; n < MAX_VOXELS_PER_SYSTEM; n++) { | ||
| 369 | for (int i = 0; i < VERTEX_POINTS_PER_VOXEL; i++) { | ||
| 370 | *(normalsArrayEndPointer++) = identityNormals[i]; | ||
| 371 | } | ||
| 372 | } | ||
| 373 | |||
| 362 | // VBO for the verticesArray | 374 | // VBO for the verticesArray |
| 363 | glGenBuffers(1, &vboVerticesID); | 375 | glGenBuffers(1, &vboVerticesID); |
| 364 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); | 376 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); |
| 365 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); | 377 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); |
| 366 | 378 | ||
| 379 | // VBO for the normalsArray | ||
| 380 | glGenBuffers(1, &vboNormalsID); | ||
| 381 | glBindBuffer(GL_ARRAY_BUFFER, vboNormalsID); | ||
| 382 | glBufferData(GL_ARRAY_BUFFER, | ||
| 383 | VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat) * MAX_VOXELS_PER_SYSTEM, | ||
| 384 | normalsArray, GL_STATIC_DRAW); | ||
| 385 | |||
| 367 | // VBO for colorsArray | 386 | // VBO for colorsArray |
| 368 | glGenBuffers(1, &vboColorsID); | 387 | glGenBuffers(1, &vboColorsID); |
| 369 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); | 388 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); |
| 370 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); | 389 | glBufferData(GL_ARRAY_BUFFER, VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte) * MAX_VOXELS_PER_SYSTEM, NULL, GL_DYNAMIC_DRAW); |
| 371 | 390 | ||
| 372 | // VBO for the indicesArray | 391 | // VBO for the indicesArray |
| 373 | glGenBuffers(1, &vboIndicesID); | 392 | glGenBuffers(1, &vboIndicesID); |
| 374 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); | 393 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); |
| 375 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, | 394 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, |
| 376 | INDICES_PER_VOXEL * sizeof(GLuint) * MAX_VOXELS_PER_SYSTEM, | 395 | INDICES_PER_VOXEL * sizeof(GLuint) * MAX_VOXELS_PER_SYSTEM, |
| 377 | indicesArray, GL_STATIC_DRAW); | 396 | indicesArray, GL_STATIC_DRAW); |
| 378 | 397 | ||
| 379 | // delete the indices array that is no longer needed | 398 | // delete the indices and normals arrays that are no longer needed |
| 380 | delete[] indicesArray; | 399 | delete[] indicesArray; |
| 400 | delete[] normalsArray; | ||
| 381 | } | 401 | } |
| 382 | 402 | ||
| 383 | void VoxelSystem::render() { | 403 | void VoxelSystem::render() { |
| 384 | 404 | ||
| 385 | glPushMatrix(); | 405 | glPushMatrix(); |
| 386 | 406 | ||
| 387 | if (readVerticesEndPointer != readVerticesArray) { | 407 | if (readVerticesEndPointer != readVerticesArray) { |
| 388 | // try to lock on the buffer write | 408 | // try to lock on the buffer write |
| 389 | // just avoid pulling new data if it is currently being written | 409 | // just avoid pulling new data if it is currently being written |
| 390 | if (pthread_mutex_trylock(&bufferWriteLock) == 0) { | 410 | if (pthread_mutex_trylock(&bufferWriteLock) == 0) { |
| 391 | 411 | ||
| 392 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); | 412 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); |
| 393 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray); | 413 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLfloat), readVerticesArray); |
| 394 | 414 | ||
| 395 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); | 415 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); |
| 396 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray); | 416 | glBufferSubData(GL_ARRAY_BUFFER, 0, (readVerticesEndPointer - readVerticesArray) * sizeof(GLubyte), readColorsArray); |
| 397 | 417 | ||
| 398 | readVerticesEndPointer = readVerticesArray; | 418 | readVerticesEndPointer = readVerticesArray; |
| 399 | 419 | ||
| 400 | pthread_mutex_unlock(&bufferWriteLock); | 420 | pthread_mutex_unlock(&bufferWriteLock); |
| 401 | } | 421 | } |
| 402 | } | 422 | } |
| 403 | 423 | ||
| 404 | // tell OpenGL where to find vertex and color information | 424 | // tell OpenGL where to find vertex and color information |
| 405 | glEnableClientState(GL_VERTEX_ARRAY); | 425 | glEnableClientState(GL_VERTEX_ARRAY); |
| 426 | glEnableClientState(GL_NORMAL_ARRAY); | ||
| 406 | glEnableClientState(GL_COLOR_ARRAY); | 427 | glEnableClientState(GL_COLOR_ARRAY); |
| 407 | 428 | ||
| 408 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); | 429 | glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID); |
| 409 | glVertexPointer(3, GL_FLOAT, 0, 0); | 430 | glVertexPointer(3, GL_FLOAT, 0, 0); |
| 410 | 431 | ||
| 432 | glBindBuffer(GL_ARRAY_BUFFER, vboNormalsID); | ||
| 433 | glNormalPointer(GL_FLOAT, 0, 0); | ||
| 434 | |||
| 411 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); | 435 | glBindBuffer(GL_ARRAY_BUFFER, vboColorsID); |
| 412 | glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); | 436 | glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); |
| 413 | 437 | ||
| 414 | // draw the number of voxels we have | 438 | // draw the number of voxels we have |
| 415 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); | 439 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); |
| 416 | glScalef(10, 10, 10); | 440 | glScalef(10, 10, 10); |
| 417 | glDrawElements(GL_TRIANGLES, 36 * voxelsRendered, GL_UNSIGNED_INT, 0); | 441 | glDrawElements(GL_TRIANGLES, 36 * voxelsRendered, GL_UNSIGNED_INT, 0); |
| 418 | 442 | ||
| 419 | // deactivate vertex and color arrays after drawing | 443 | // deactivate vertex and color arrays after drawing |
| 420 | glDisableClientState(GL_VERTEX_ARRAY); | 444 | glDisableClientState(GL_VERTEX_ARRAY); |
| 445 | glDisableClientState(GL_NORMAL_ARRAY); | ||
| 421 | glDisableClientState(GL_COLOR_ARRAY); | 446 | glDisableClientState(GL_COLOR_ARRAY); |
| 422 | 447 | ||
| 423 | // bind with 0 to switch back to normal operation | 448 | // bind with 0 to switch back to normal operation |
| 424 | glBindBuffer(GL_ARRAY_BUFFER, 0); | 449 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 425 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 450 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 426 | 451 | ||
| 427 | // scale back down to 1 so heads aren't massive | 452 | // scale back down to 1 so heads aren't massive |
| 428 | glPopMatrix(); | 453 | glPopMatrix(); |
| 429 | } | 454 | } |
| 430 | 455 | ||
| 431 | void VoxelSystem::simulate(float deltaTime) { | 456 | void VoxelSystem::simulate(float deltaTime) { |
| 432 | 457 | ||
| 433 | } | 458 | } |
| 434 | 459 | ||
| 435 | int VoxelSystem::_nodeCount = 0; | 460 | int VoxelSystem::_nodeCount = 0; |
| @@ -440,7 +465,7 @@ bool VoxelSystem::randomColorOperation(VoxelNode* node, bool down, void* extraDa · 4 unmodified lines | |||
| 440 | if (down) { | 465 | if (down) { |
| 441 | return true; | 466 | return true; |
| 442 | } | 467 | } |
| 443 | 468 | ||
| 444 | _nodeCount++; | 469 | _nodeCount++; |
| 445 | if (node->isColored()) { | 470 | if (node->isColored()) { |
| 446 | nodeColor newColor = { 0,0,0,1 }; | 471 | nodeColor newColor = { 0,0,0,1 }; |
| @@ -471,9 +496,9 @@ bool VoxelSystem::falseColorizeRandomOperation(VoxelNode* node, bool down, void* · 24 unmodified lines | |||
| 471 | if (down) { | 496 | if (down) { |
| 472 | return true; | 497 | return true; |
| 473 | } | 498 | } |
| 474 | 499 | ||
| 475 | _nodeCount++; | 500 | _nodeCount++; |
| 476 | 501 | ||
| 477 | // always false colorize | 502 | // always false colorize |
| 478 | unsigned char newR = randomColorValue(150); | 503 | unsigned char newR = randomColorValue(150); |
| 479 | unsigned char newG = randomColorValue(150); | 504 | unsigned char newG = randomColorValue(150); |
| @@ -500,7 +525,7 @@ bool VoxelSystem::trueColorizeOperation(VoxelNode* node, bool down, void* extraD · 20 unmodified lines | |||
| 500 | if (down) { | 525 | if (down) { |
| 501 | return true; | 526 | return true; |
| 502 | } | 527 | } |
| 503 | 528 | ||
| 504 | _nodeCount++; | 529 | _nodeCount++; |
| 505 | node->setFalseColored(false); | 530 | node->setFalseColored(false); |
| 506 | //printf("setting true color for node %d\n",_nodeCount); | 531 | //printf("setting true color for node %d\n",_nodeCount); |
| @@ -521,23 +546,23 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, bool down, void* · 14 unmodified lines | |||
| 521 | if (down) { | 546 | if (down) { |
| 522 | return true; | 547 | return true; |
| 523 | } | 548 | } |
| 524 | 549 | ||
| 525 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; | 550 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; |
| 526 | 551 | ||
| 527 | _nodeCount++; | 552 | _nodeCount++; |
| 528 | 553 | ||
| 529 | // only do this for truely colored voxels... | 554 | // only do this for truely colored voxels... |
| 530 | if (node->isColored()) { | 555 | if (node->isColored()) { |
| 531 | // first calculate the AAbox for the voxel | 556 | // first calculate the AAbox for the voxel |
| 532 | AABox voxelBox; | 557 | AABox voxelBox; |
| 533 | node->getAABox(voxelBox); | 558 | node->getAABox(voxelBox); |
| 534 | 559 | ||
| 535 | voxelBox.scale(TREE_SCALE); | 560 | voxelBox.scale(TREE_SCALE); |
| 536 | 561 | ||
| 537 | printf("voxelBox corner=(%f,%f,%f) x=%f\n", | 562 | printf("voxelBox corner=(%f,%f,%f) x=%f\n", |
| 538 | voxelBox.getCorner().x, voxelBox.getCorner().y, voxelBox.getCorner().z, | 563 | voxelBox.getCorner().x, voxelBox.getCorner().y, voxelBox.getCorner().z, |
| 539 | voxelBox.getSize().x); | 564 | voxelBox.getSize().x); |
| 540 | 565 | ||
| 541 | // If the voxel is outside of the view frustum, then false color it red | 566 | // If the voxel is outside of the view frustum, then false color it red |
| 542 | if (ViewFrustum::OUTSIDE == viewFrustum->boxInFrustum(voxelBox)) { | 567 | if (ViewFrustum::OUTSIDE == viewFrustum->boxInFrustum(voxelBox)) { |
| 543 | // Out of view voxels are colored RED | 568 | // Out of view voxels are colored RED |
| @@ -554,7 +579,7 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, bool down, void* · 10 unmodified lines | |||
| 554 | } else { | 579 | } else { |
| 555 | printf("voxel not colored, don't consider it\n"); | 580 | printf("voxel not colored, don't consider it\n"); |
| 556 | } | 581 | } |
| 557 | 582 | ||
| 558 | return true; // keep going! | 583 | return true; // keep going! |
| 559 | } | 584 | } |
| 560 | 585 | ||
| @@ -576,7 +601,7 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, bool d · 15 unmodified lines | |||
| 576 | } | 601 | } |
| 577 | 602 | ||
| 578 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; | 603 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; |
| 579 | 604 | ||
| 580 | // only do this for truly colored voxels... | 605 | // only do this for truly colored voxels... |
| 581 | if (node->isColored()) { | 606 | if (node->isColored()) { |
| 582 | 607 | ||
| @@ -590,10 +615,10 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, bool d · 7 unmodified lines | |||
| 590 | 615 | ||
| 591 | // scale up the node position | 616 | // scale up the node position |
| 592 | nodePosition = nodePosition*(float)TREE_SCALE; | 617 | nodePosition = nodePosition*(float)TREE_SCALE; |
| 593 | 618 | ||
| 594 | float halfUnitForVoxel = powf(0.5, *node->octalCode) * (0.5 * TREE_SCALE); | 619 | float halfUnitForVoxel = powf(0.5, *node->octalCode) * (0.5 * TREE_SCALE); |
| 595 | glm::vec3 viewerPosition = viewFrustum->getPosition(); | 620 | glm::vec3 viewerPosition = viewFrustum->getPosition(); |
| 596 | 621 | ||
| 597 | //printf("halfUnitForVoxel=%f\n",halfUnitForVoxel); | 622 | //printf("halfUnitForVoxel=%f\n",halfUnitForVoxel); |
| 598 | //printf("viewer.x=%f y=%f z=%f \n", viewerPosition.x, viewerPosition.y, viewerPosition.z); | 623 | //printf("viewer.x=%f y=%f z=%f \n", viewerPosition.x, viewerPosition.y, viewerPosition.z); |
| 599 | //printf("node.x=%f y=%f z=%f \n", nodePosition.x, nodePosition.y, nodePosition.z); | 624 | //printf("node.x=%f y=%f z=%f \n", nodePosition.x, nodePosition.y, nodePosition.z); |
| @@ -606,7 +631,7 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, bool d · 6 unmodified lines | |||
| 606 | _nodeCount++; | 631 | _nodeCount++; |
| 607 | 632 | ||
| 608 | float distanceRatio = (_minDistance==_maxDistance) ? 1 : (distance - _minDistance)/(_maxDistance - _minDistance); | 633 | float distanceRatio = (_minDistance==_maxDistance) ? 1 : (distance - _minDistance)/(_maxDistance - _minDistance); |
| 609 | 634 | ||
| 610 | // We want to colorize this in 16 bug chunks of color | 635 | // We want to colorize this in 16 bug chunks of color |
| 611 | const unsigned char maxColor = 255; | 636 | const unsigned char maxColor = 255; |
| 612 | const unsigned char colorBands = 16; | 637 | const unsigned char colorBands = 16; |
| @@ -615,7 +640,7 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, bool d · 2 unmodified lines | |||
| 615 | unsigned char newR = (colorBand*(gradientOver/colorBands))+(maxColor-gradientOver); | 640 | unsigned char newR = (colorBand*(gradientOver/colorBands))+(maxColor-gradientOver); |
| 616 | unsigned char newG = 0; | 641 | unsigned char newG = 0; |
| 617 | unsigned char newB = 0; | 642 | unsigned char newB = 0; |
| 618 | //printf("Setting color down=%s distance=%f min=%f max=%f distanceRatio=%f color=%d \n", | 643 | //printf("Setting color down=%s distance=%f min=%f max=%f distanceRatio=%f color=%d \n", |
| 619 | // (down ? "TRUE" : "FALSE"), distance, _minDistance, _maxDistance, distanceRatio, (int)newR); | 644 | // (down ? "TRUE" : "FALSE"), distance, _minDistance, _maxDistance, distanceRatio, (int)newR); |
| 620 | 645 | ||
| 621 | node->setFalseColor(newR,newG,newB); | 646 | node->setFalseColor(newR,newG,newB); |
| @@ -641,7 +666,7 @@ bool VoxelSystem::getDistanceFromViewRangeOperation(VoxelNode* node, bool down, · 19 unmodified lines | |||
| 641 | //printf("getDistanceFromViewRangeOperation() down=%s\n",(down ? "TRUE" : "FALSE")); | 666 | //printf("getDistanceFromViewRangeOperation() down=%s\n",(down ? "TRUE" : "FALSE")); |
| 642 | 667 | ||
| 643 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; | 668 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; |
| 644 | 669 | ||
| 645 | // only do this for truly colored voxels... | 670 | // only do this for truly colored voxels... |
| 646 | if (node->isColored()) { | 671 | if (node->isColored()) { |
| 647 | 672 | ||
| @@ -687,7 +712,7 @@ void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) { · 39 unmodified lines | |||
| 687 | printf("determining distance range for %d nodes\n",_nodeCount); | 712 | printf("determining distance range for %d nodes\n",_nodeCount); |
| 688 | 713 | ||
| 689 | _nodeCount = 0; | 714 | _nodeCount = 0; |
| 690 | 715 | ||
| 691 | tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); | 716 | tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); |
| 692 | printf("setting in distance false color for %d nodes\n",_nodeCount); | 717 | printf("setting in distance false color for %d nodes\n",_nodeCount); |
| 693 | setupNewVoxelsForDrawing(); | 718 | setupNewVoxelsForDrawing(); |