Showing the changes to interface/src/VoxelSystem.cpp (1 of 1 file). Show all
Unified · Split
| @@ -299,7 +299,6 @@ void VoxelSystem::updateVBOs() { · 298 unmodified lines | ||
| 299 | 299 | if (_voxelsDirty) { |
| 300 | 300 | glBufferIndex segmentStart = 0; |
| 301 | 301 | glBufferIndex segmentEnd = 0; |
| 302 | − | |
| 303 | 302 | bool inSegment = false; |
| 304 | 303 | for (glBufferIndex i = 0; i < _voxelsInArrays; i++) { |
| 305 | 304 | if (!inSegment) { |
| @@ -313,20 +312,14 @@ void VoxelSystem::updateVBOs() { · 7 unmodified lines | ||
| 313 | 312 | segmentEnd = i; |
| 314 | 313 | inSegment = false; |
| 315 | 314 | int segmentLength = (segmentEnd - segmentStart) + 1; |
| 316 | − | |
| 317 | − // vertices for segment - note: we might not need to do this | |
| 318 | 315 | GLintptr segmentStartAt = segmentStart * VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat); |
| 319 | 316 | GLsizeiptr segmentSizeBytes = segmentLength * VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat); |
| 320 | 317 | GLfloat* readVerticesFrom = _readVerticesArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); |
| 321 | − | |
| 322 | 318 | glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID); |
| 323 | 319 | glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readVerticesFrom); |
| 324 | − | |
| 325 | − // colors for segment | |
| 326 | 320 | segmentStartAt = segmentStart * VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte); |
| 327 | 321 | segmentSizeBytes = segmentLength * VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte); |
| 328 | 322 | GLubyte* readColorsFrom = _readColorsArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); |
| 329 | − | |
| 330 | 323 | glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID); |
| 331 | 324 | glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readColorsFrom); |
| 332 | 325 | } |
| @@ -378,7 +371,6 @@ void VoxelSystem::simulate(float deltaTime) { · 45 unmodified lines | ||
| 378 | 371 | int VoxelSystem::_nodeCount = 0; |
| 379 | 372 | |
| 380 | 373 | bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) { |
| 381 | − | |
| 382 | 374 | _nodeCount++; |
| 383 | 375 | if (node->isColored()) { |
| 384 | 376 | nodeColor newColor = { 0,0,0,1 }; |
| @@ -398,15 +390,12 @@ void VoxelSystem::randomizeVoxelColors() { · 13 unmodified lines | ||
| 398 | 390 | } |
| 399 | 391 | |
| 400 | 392 | bool VoxelSystem::falseColorizeRandomOperation(VoxelNode* node, void* extraData) { |
| 401 | − | |
| 402 | 393 | _nodeCount++; |
| 403 | − | |
| 404 | 394 | // always false colorize |
| 405 | 395 | unsigned char newR = randomColorValue(150); |
| 406 | 396 | unsigned char newG = randomColorValue(150); |
| 407 | 397 | unsigned char newB = randomColorValue(150); |
| 408 | 398 | node->setFalseColor(newR,newG,newB); |
| 409 | − | |
| 410 | 399 | return true; // keep going! |
| 411 | 400 | } |
| 412 | 401 | |
| @@ -433,12 +422,8 @@ void VoxelSystem::trueColorize() { · 20 unmodified lines | ||
| 433 | 422 | // Will false colorize voxels that are not in view |
| 434 | 423 | bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, void* extraData) { |
| 435 | 424 | const ViewFrustum* viewFrustum = (const ViewFrustum*) extraData; |
| 436 | − | |
| 437 | 425 | _nodeCount++; |
| 438 | − | |
| 439 | − // only do this for truely colored voxels... | |
| 440 | 426 | if (node->isColored()) { |
| 441 | − // If the voxel is outside of the view frustum, then false color it red | |
| 442 | 427 | if (!node->isInView(*viewFrustum)) { |
| 443 | 428 | // Out of view voxels are colored RED |
| 444 | 429 | unsigned char newR = 255; |
| @@ -447,7 +432,6 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, void* extraData) · 2 unmodified lines | ||
| 447 | 432 | node->setFalseColor(newR,newG,newB); |
| 448 | 433 | } |
| 449 | 434 | } |
| 450 | − | |
| 451 | 435 | return true; // keep going! |
| 452 | 436 | } |
| 453 | 437 | |
| @@ -461,29 +445,9 @@ void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) { · 7 unmodified lines | ||
| 461 | 445 | // Will false colorize voxels based on distance from view |
| 462 | 446 | bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, void* extraData) { |
| 463 | 447 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; |
| 464 | − | |
| 465 | − // only do this for truly colored voxels... | |
| 466 | 448 | if (node->isColored()) { |
| 467 | − glm::vec3 nodePosition; | |
| 468 | − float* startVertex = firstVertexForCode(node->octalCode); | |
| 469 | − nodePosition.x = startVertex[0]; | |
| 470 | − nodePosition.y = startVertex[1]; | |
| 471 | − nodePosition.z = startVertex[2]; | |
| 472 | − delete startVertex; | |
| 473 | − | |
| 474 | − // scale up the node position | |
| 475 | − nodePosition = nodePosition*(float)TREE_SCALE; | |
| 476 | − | |
| 477 | − float halfUnitForVoxel = powf(0.5, *node->octalCode) * (0.5 * TREE_SCALE); | |
| 478 | − glm::vec3 viewerPosition = viewFrustum->getPosition(); | |
| 479 | − | |
| 480 | − float distance = sqrtf(powf(viewerPosition.x - nodePosition.x - halfUnitForVoxel, 2) + | |
| 481 | − powf(viewerPosition.y - nodePosition.y - halfUnitForVoxel, 2) + | |
| 482 | − powf(viewerPosition.z - nodePosition.z - halfUnitForVoxel, 2)); | |
| 483 | − | |
| 484 | − // actually colorize | |
| 449 | + float distance = node->distanceToCamera(*viewFrustum); | |
| 485 | 450 | _nodeCount++; |
| 486 | − | |
| 487 | 451 | float distanceRatio = (_minDistance==_maxDistance) ? 1 : (distance - _minDistance)/(_maxDistance - _minDistance); |
| 488 | 452 | |
| 489 | 453 | // We want to colorize this in 16 bug chunks of color |
| @@ -507,28 +471,9 @@ float VoxelSystem::_minDistance = FLT_MAX; · 17 unmodified lines | ||
| 507 | 471 | // we wouldn't need to do two passes of the tree |
| 508 | 472 | bool VoxelSystem::getDistanceFromViewRangeOperation(VoxelNode* node, void* extraData) { |
| 509 | 473 | ViewFrustum* viewFrustum = (ViewFrustum*) extraData; |
| 510 | − | |
| 511 | 474 | // only do this for truly colored voxels... |
| 512 | 475 | if (node->isColored()) { |
| 513 | − | |
| 514 | − // We need our distance for both up and down | |
| 515 | − glm::vec3 nodePosition; | |
| 516 | − float* startVertex = firstVertexForCode(node->octalCode); | |
| 517 | − nodePosition.x = startVertex[0]; | |
| 518 | − nodePosition.y = startVertex[1]; | |
| 519 | − nodePosition.z = startVertex[2]; | |
| 520 | − delete startVertex; | |
| 521 | − | |
| 522 | − // scale up the node position | |
| 523 | − nodePosition = nodePosition*(float)TREE_SCALE; | |
| 524 | − | |
| 525 | − float halfUnitForVoxel = powf(0.5, *node->octalCode) * (0.5 * TREE_SCALE); | |
| 526 | − glm::vec3 viewerPosition = viewFrustum->getPosition(); | |
| 527 | − | |
| 528 | − float distance = sqrtf(powf(viewerPosition.x - nodePosition.x - halfUnitForVoxel, 2) + | |
| 529 | − powf(viewerPosition.y - nodePosition.y - halfUnitForVoxel, 2) + | |
| 530 | − powf(viewerPosition.z - nodePosition.z - halfUnitForVoxel, 2)); | |
| 531 | − | |
| 476 | + float distance = node->distanceToCamera(*viewFrustum); | |
| 532 | 477 | // calculate the range of distances |
| 533 | 478 | if (distance > _maxDistance) { |
| 534 | 479 | _maxDistance = distance; |
| @@ -536,7 +481,6 @@ bool VoxelSystem::getDistanceFromViewRangeOperation(VoxelNode* node, void* extra · 1 unmodified line | ||
| 536 | 481 | if (distance < _minDistance) { |
| 537 | 482 | _minDistance = distance; |
| 538 | 483 | } |
| 539 | − | |
| 540 | 484 | _nodeCount++; |
| 541 | 485 | } |
| 542 | 486 | return true; // keep going! |
| @@ -544,14 +488,11 @@ bool VoxelSystem::getDistanceFromViewRangeOperation(VoxelNode* node, void* extra · 1 unmodified line | ||
| 544 | 488 | |
| 545 | 489 | void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) { |
| 546 | 490 | _nodeCount = 0; |
| 547 | − | |
| 548 | 491 | _maxDistance = 0.0; |
| 549 | 492 | _minDistance = FLT_MAX; |
| 550 | 493 | _tree->recurseTreeWithOperation(getDistanceFromViewRangeOperation,(void*)viewFrustum); |
| 551 | 494 | printLog("determining distance range for %d nodes\n",_nodeCount); |
| 552 | − | |
| 553 | 495 | _nodeCount = 0; |
| 554 | − | |
| 555 | 496 | _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); |
| 556 | 497 | printLog("setting in distance false color for %d nodes\n",_nodeCount); |
| 557 | 498 | setupNewVoxelsForDrawing(); |