code cleanup

This commit is contained in:
ZappoMan 2013-05-01 18:37:14 -07:00
parent 62e7c0383b
commit 015fd05e62
2 changed files with 13 additions and 29 deletions

View file

@ -364,19 +364,12 @@ void VoxelSystem::render() {
glPopMatrix(); glPopMatrix();
} }
void VoxelSystem::simulate(float deltaTime) {
}
int VoxelSystem::_nodeCount = 0; int VoxelSystem::_nodeCount = 0;
bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) { bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) {
_nodeCount++; _nodeCount++;
if (node->isColored()) { if (node->isColored()) {
nodeColor newColor = { 0,0,0,1 }; nodeColor newColor = { randomColorValue(150), randomColorValue(150), randomColorValue(150), 1 };
newColor[0] = randomColorValue(150);
newColor[1] = randomColorValue(150);
newColor[1] = randomColorValue(150);
node->setColor(newColor); node->setColor(newColor);
} }
return true; return true;
@ -385,24 +378,21 @@ bool VoxelSystem::randomColorOperation(VoxelNode* node, void* extraData) {
void VoxelSystem::randomizeVoxelColors() { void VoxelSystem::randomizeVoxelColors() {
_nodeCount = 0; _nodeCount = 0;
_tree->recurseTreeWithOperation(randomColorOperation); _tree->recurseTreeWithOperation(randomColorOperation);
printLog("setting randomized true color for %d nodes\n",_nodeCount); printLog("setting randomized true color for %d nodes\n", _nodeCount);
setupNewVoxelsForDrawing(); setupNewVoxelsForDrawing();
} }
bool VoxelSystem::falseColorizeRandomOperation(VoxelNode* node, void* extraData) { bool VoxelSystem::falseColorizeRandomOperation(VoxelNode* node, void* extraData) {
_nodeCount++; _nodeCount++;
// always false colorize // always false colorize
unsigned char newR = randomColorValue(150); node->setFalseColor(randomColorValue(150), randomColorValue(150), randomColorValue(150));
unsigned char newG = randomColorValue(150);
unsigned char newB = randomColorValue(150);
node->setFalseColor(newR,newG,newB);
return true; // keep going! return true; // keep going!
} }
void VoxelSystem::falseColorizeRandom() { void VoxelSystem::falseColorizeRandom() {
_nodeCount = 0; _nodeCount = 0;
_tree->recurseTreeWithOperation(falseColorizeRandomOperation); _tree->recurseTreeWithOperation(falseColorizeRandomOperation);
printLog("setting randomized false color for %d nodes\n",_nodeCount); printLog("setting randomized false color for %d nodes\n", _nodeCount);
setupNewVoxelsForDrawing(); setupNewVoxelsForDrawing();
} }
@ -415,7 +405,7 @@ bool VoxelSystem::trueColorizeOperation(VoxelNode* node, void* extraData) {
void VoxelSystem::trueColorize() { void VoxelSystem::trueColorize() {
_nodeCount = 0; _nodeCount = 0;
_tree->recurseTreeWithOperation(trueColorizeOperation); _tree->recurseTreeWithOperation(trueColorizeOperation);
printLog("setting true color for %d nodes\n",_nodeCount); printLog("setting true color for %d nodes\n", _nodeCount);
setupNewVoxelsForDrawing(); setupNewVoxelsForDrawing();
} }
@ -426,10 +416,7 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, void* extraData)
if (node->isColored()) { if (node->isColored()) {
if (!node->isInView(*viewFrustum)) { if (!node->isInView(*viewFrustum)) {
// Out of view voxels are colored RED // Out of view voxels are colored RED
unsigned char newR = 255; node->setFalseColor(255, 0, 0);
unsigned char newG = 0;
unsigned char newB = 0;
node->setFalseColor(newR,newG,newB);
} }
} }
return true; // keep going! return true; // keep going!
@ -438,7 +425,7 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, void* extraData)
void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) { void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) {
_nodeCount = 0; _nodeCount = 0;
_tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)viewFrustum); _tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)viewFrustum);
printLog("setting in view false color for %d nodes\n",_nodeCount); printLog("setting in view false color for %d nodes\n", _nodeCount);
setupNewVoxelsForDrawing(); setupNewVoxelsForDrawing();
} }
@ -448,17 +435,14 @@ bool VoxelSystem::falseColorizeDistanceFromViewOperation(VoxelNode* node, void*
if (node->isColored()) { if (node->isColored()) {
float distance = node->distanceToCamera(*viewFrustum); float distance = node->distanceToCamera(*viewFrustum);
_nodeCount++; _nodeCount++;
float distanceRatio = (_minDistance==_maxDistance) ? 1 : (distance - _minDistance)/(_maxDistance - _minDistance); float distanceRatio = (_minDistance == _maxDistance) ? 1 : (distance - _minDistance) / (_maxDistance - _minDistance);
// We want to colorize this in 16 bug chunks of color // We want to colorize this in 16 bug chunks of color
const unsigned char maxColor = 255; const unsigned char maxColor = 255;
const unsigned char colorBands = 16; const unsigned char colorBands = 16;
const unsigned char gradientOver = 128; const unsigned char gradientOver = 128;
unsigned char colorBand = (colorBands*distanceRatio); unsigned char colorBand = (colorBands * distanceRatio);
unsigned char newR = (colorBand*(gradientOver/colorBands))+(maxColor-gradientOver); node->setFalseColor((colorBand * (gradientOver / colorBands)) + (maxColor - gradientOver), 0, 0);
unsigned char newG = 0;
unsigned char newB = 0;
node->setFalseColor(newR,newG,newB);
} }
return true; // keep going! return true; // keep going!
} }
@ -491,10 +475,10 @@ void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) {
_maxDistance = 0.0; _maxDistance = 0.0;
_minDistance = FLT_MAX; _minDistance = FLT_MAX;
_tree->recurseTreeWithOperation(getDistanceFromViewRangeOperation,(void*)viewFrustum); _tree->recurseTreeWithOperation(getDistanceFromViewRangeOperation,(void*)viewFrustum);
printLog("determining distance range for %d nodes\n",_nodeCount); printLog("determining distance range for %d nodes\n", _nodeCount);
_nodeCount = 0; _nodeCount = 0;
_tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum);
printLog("setting in distance false color for %d nodes\n",_nodeCount); printLog("setting in distance false color for %d nodes\n", _nodeCount);
setupNewVoxelsForDrawing(); setupNewVoxelsForDrawing();
} }

View file

@ -33,7 +33,7 @@ public:
void setViewFrustum(ViewFrustum* viewFrustum) { _viewFrustum = viewFrustum; }; void setViewFrustum(ViewFrustum* viewFrustum) { _viewFrustum = viewFrustum; };
void init(); void init();
void simulate(float deltaTime); void simulate(float deltaTime) { };
void render(); void render();
unsigned long getVoxelsUpdated() const {return _voxelsUpdated;}; unsigned long getVoxelsUpdated() const {return _voxelsUpdated;};