History

cleaned up some code for distanceToCamera()

ZappoMan committed 13 years ago

Commit 62e7c031 parent cfcfacf1 file · +2 −61Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 1 file). Show all

Unified · Split

interface/src/VoxelSystem.cpp+2−61
@@ -299,7 +299,6 @@ void VoxelSystem::updateVBOs() { · 298 unmodified lines
299299 if (_voxelsDirty) {
300300 glBufferIndex segmentStart = 0;
301301 glBufferIndex segmentEnd = 0;
302−
303302 bool inSegment = false;
304303 for (glBufferIndex i = 0; i < _voxelsInArrays; i++) {
305304 if (!inSegment) {
@@ -313,20 +312,14 @@ void VoxelSystem::updateVBOs() { · 7 unmodified lines
313312 segmentEnd = i;
314313 inSegment = false;
315314 int segmentLength = (segmentEnd - segmentStart) + 1;
316−
317− // vertices for segment - note: we might not need to do this
318315 GLintptr segmentStartAt = segmentStart * VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat);
319316 GLsizeiptr segmentSizeBytes = segmentLength * VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat);
320317 GLfloat* readVerticesFrom = _readVerticesArray + (segmentStart * VERTEX_POINTS_PER_VOXEL);
321−
322318 glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
323319 glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readVerticesFrom);
324−
325− // colors for segment
326320 segmentStartAt = segmentStart * VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte);
327321 segmentSizeBytes = segmentLength * VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte);
328322 GLubyte* readColorsFrom = _readColorsArray + (segmentStart * VERTEX_POINTS_PER_VOXEL);
329−
330323 glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
331324 glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readColorsFrom);
332325 }
@@ -378,7 +371,6 @@ void VoxelSystem::simulate(float deltaTime) { · 45 unmodified lines
378371 int VoxelSystem::_nodeCount = 0;
379372
380373 bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) {
381−
382374 _nodeCount++;
383375 if (node->isColored()) {
384376 nodeColor newColor = { 0,0,0,1 };
@@ -398,15 +390,12 @@ void VoxelSystem::randomizeVoxelColors() { · 13 unmodified lines
398390 }
399391
400392 bool VoxelSystem::falseColorizeRandomOperation(VoxelNode* node, void* extraData) {
401−
402393 _nodeCount++;
403−
404394 // always false colorize
405395 unsigned char newR = randomColorValue(150);
406396 unsigned char newG = randomColorValue(150);
407397 unsigned char newB = randomColorValue(150);
408398 node->setFalseColor(newR,newG,newB);
409−
410399 return true; // keep going!
411400 }
412401
@@ -433,12 +422,8 @@ void VoxelSystem::trueColorize() { · 20 unmodified lines
433422 // Will false colorize voxels that are not in view
434423 bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, void* extraData) {
435424 const ViewFrustum* viewFrustum = (const ViewFrustum*) extraData;
436−
437425 _nodeCount++;
438−
439− // only do this for truely colored voxels...
440426 if (node->isColored()) {
441− // If the voxel is outside of the view frustum, then false color it red
442427 if (!node->isInView(*viewFrustum)) {
443428 // Out of view voxels are colored RED
444429 unsigned char newR = 255;
@@ -447,7 +432,6 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, void* extraData) · 2 unmodified lines
447432 node->setFalseColor(newR,newG,newB);
448433 }
449434 }
450−
451435 return true; // keep going!
452436 }
453437
@@ -461,29 +445,9 @@ void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) { · 7 unmodified lines
461445 // Will false colorize voxels based on distance from view
462446 bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, void* extraData) {
463447 ViewFrustum* viewFrustum = (ViewFrustum*) extraData;
464−
465− // only do this for truly colored voxels...
466448 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);
485450 _nodeCount++;
486−
487451 float distanceRatio = (_minDistance==_maxDistance) ? 1 : (distance - _minDistance)/(_maxDistance - _minDistance);
488452
489453 // We want to colorize this in 16 bug chunks of color
@@ -507,28 +471,9 @@ float VoxelSystem::_minDistance = FLT_MAX; · 17 unmodified lines
507471 // we wouldn't need to do two passes of the tree
508472 bool VoxelSystem::getDistanceFromViewRangeOperation(VoxelNode* node, void* extraData) {
509473 ViewFrustum* viewFrustum = (ViewFrustum*) extraData;
510−
511474 // only do this for truly colored voxels...
512475 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);
532477 // calculate the range of distances
533478 if (distance > _maxDistance) {
534479 _maxDistance = distance;
@@ -536,7 +481,6 @@ bool VoxelSystem::getDistanceFromViewRangeOperation(VoxelNode* node, void* extra · 1 unmodified line
536481 if (distance < _minDistance) {
537482 _minDistance = distance;
538483 }
539−
540484 _nodeCount++;
541485 }
542486 return true; // keep going!
@@ -544,14 +488,11 @@ bool VoxelSystem::getDistanceFromViewRangeOperation(VoxelNode* node, void* extra · 1 unmodified line
544488
545489 void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) {
546490 _nodeCount = 0;
547−
548491 _maxDistance = 0.0;
549492 _minDistance = FLT_MAX;
550493 _tree->recurseTreeWithOperation(getDistanceFromViewRangeOperation,(void*)viewFrustum);
551494 printLog("determining distance range for %d nodes\n",_nodeCount);
552−
553495 _nodeCount = 0;
554−
555496 _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum);
556497 printLog("setting in distance false color for %d nodes\n",_nodeCount);
557498 setupNewVoxelsForDrawing();