Showing the changes to interface/src/VoxelSystem.cpp (1 of 1 file). Show all
Unified · Split
| @@ -115,8 +115,6 @@ float VoxelSystem::getVoxelsBytesReadPerSecondAverage() { · 114 unmodified lines | |||
| 115 | return tree->voxelsBytesReadStats.getAverageSampleValuePerSecond(); | 115 | return tree->voxelsBytesReadStats.getAverageSampleValuePerSecond(); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | bool pickAorB = false; | ||
| 119 | |||
| 120 | int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { | 118 | int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { |
| 121 | 119 | ||
| 122 | unsigned char command = *sourceBuffer; | 120 | unsigned char command = *sourceBuffer; |
| @@ -130,6 +128,71 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 7 unmodified lines | |||
| 130 | // would make a point of removing this code when all this work is done. But in the mean time, I need it here for | 128 | // would make a point of removing this code when all this work is done. But in the mean time, I need it here for |
| 131 | // debugging purposes... When you do the code review... DO NOT tell me to remove it. :) Thank you! | 129 | // debugging purposes... When you do the code review... DO NOT tell me to remove it. :) Thank you! |
| 132 | // | 130 | // |
| 131 | unsigned char fakePacketA[18] = { 86,4,39,128,232,128,128,128,139,138,139,139,137,139,138,139,139,0 }; | ||
| 132 | unsigned char fakePacketB[13] = { 86, | ||
| 133 | 7,39,135,128, | ||
| 134 | 136, | ||
| 135 | 255,0,0, | ||
| 136 | 0,255,0, | ||
| 137 | 0 | ||
| 138 | }; | ||
| 139 | unsigned char fakePacketC[13] = { 86, | ||
| 140 | 7,39,135,64, | ||
| 141 | 136, | ||
| 142 | 0,0,255, | ||
| 143 | 0,255,255, | ||
| 144 | 0 | ||
| 145 | }; | ||
| 146 | |||
| 147 | unsigned char fakePacketD[25] = { 86, | ||
| 148 | 6,39,135,64, | ||
| 149 | 136, | ||
| 150 | 0,0,255, | ||
| 151 | 0,255,255, | ||
| 152 | 0, | ||
| 153 | 6,39,135,128, | ||
| 154 | 136, | ||
| 155 | 255,0,0, | ||
| 156 | 0,255,0, | ||
| 157 | 0 | ||
| 158 | }; | ||
| 159 | |||
| 160 | unsigned char fakePacketE[60] = { | ||
| 161 | 86 // V | ||
| 162 | |||
| 163 | ,6,39,135,64, | ||
| 164 | 136, | ||
| 165 | 0,0,255, | ||
| 166 | 0,255,255, | ||
| 167 | 0 | ||
| 168 | |||
| 169 | ,6,39,135,128, | ||
| 170 | 136, | ||
| 171 | 255,0,0, | ||
| 172 | 0,255,0, | ||
| 173 | 0 | ||
| 174 | |||
| 175 | // now some extra bits, what happens??? | ||
| 176 | ,2,252, // octcode for root | ||
| 177 | 7, // child color bits | ||
| 178 | 255,0,0, // child 1 color | ||
| 179 | 255,255,0, // child 1 color | ||
| 180 | 128,128,0, // child 1 color | ||
| 181 | 0 // child tree bits | ||
| 182 | |||
| 183 | ,3,0,0, // octcode for root | ||
| 184 | 3, // child color bits | ||
| 185 | 0,0,255, // child 128 color | ||
| 186 | 0,255,0, // child 8 color | ||
| 187 | 0 // child tree bits - none | ||
| 188 | |||
| 189 | ,3,0,0, // octcode for root | ||
| 190 | 136, // child color bits | ||
| 191 | 0,0,255, // child 128 color | ||
| 192 | 0,255,0, // child 8 color | ||
| 193 | 0 // child tree bits - none | ||
| 194 | }; | ||
| 195 | |||
| 133 | unsigned char fakeBuffer[18] = { | 196 | unsigned char fakeBuffer[18] = { |
| 134 | 86, // V | 197 | 86, // V |
| 135 | 2,0, // octcode for root | 198 | 2,0, // octcode for root |
| @@ -185,13 +248,6 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 49 unmodified lines | |||
| 185 | }; | 248 | }; |
| 186 | 249 | ||
| 187 | // trim off the "V" | 250 | // trim off the "V" |
| 188 | printf("loading fake data! pickAorB=%s\n", (pickAorB ? "A" : "B") ); | ||
| 189 | if (pickAorB) { | ||
| 190 | tree->readBitstreamToTree((unsigned char*)&fakeBufferA[1], sizeof(fakeBufferA)-1); | ||
| 191 | } else { | ||
| 192 | tree->readBitstreamToTree((unsigned char*)&fakeBufferB[1], sizeof(fakeBufferB)-1); | ||
| 193 | } | ||
| 194 | pickAorB = !pickAorB; | ||
| 195 | 251 | ||
| 196 | ***** END OF TEMPORARY CODE ***************************************************************************************/ | 252 | ***** END OF TEMPORARY CODE ***************************************************************************************/ |
| 197 | 253 | ||
| @@ -256,9 +312,8 @@ void VoxelSystem::copyWrittenDataToReadArrays() { · 58 unmodified lines | |||
| 256 | pthread_mutex_unlock(&bufferWriteLock); | 312 | pthread_mutex_unlock(&bufferWriteLock); |
| 257 | } | 313 | } |
| 258 | 314 | ||
| 259 | int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosition) { | 315 | int VoxelSystem::treeToArrays(VoxelNode* currentNode, const glm::vec3& nodePosition) { |
| 260 | int voxelsAdded = 0; | 316 | int voxelsAdded = 0; |
| 261 | |||
| 262 | float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE); | 317 | float halfUnitForVoxel = powf(0.5, *currentNode->octalCode) * (0.5 * TREE_SCALE); |
| 263 | glm::vec3 viewerPosition = viewerAvatar->getPosition(); | 318 | glm::vec3 viewerPosition = viewerAvatar->getPosition(); |
| 264 | 319 | ||
| @@ -266,21 +321,12 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 1 unmodified line | |||
| 266 | glm::vec3 debugNodePosition; | 321 | glm::vec3 debugNodePosition; |
| 267 | copyFirstVertexForCode(currentNode->octalCode,(float*)&debugNodePosition); | 322 | copyFirstVertexForCode(currentNode->octalCode,(float*)&debugNodePosition); |
| 268 | 323 | ||
| 269 | //printf("-----------------\n"); | ||
| 270 | //printf("halfUnitForVoxel=%f\n",halfUnitForVoxel); | ||
| 271 | //printf("viewer.x=%f y=%f z=%f \n", viewerPosition.x, viewerPosition.y, viewerPosition.z); | ||
| 272 | //printf("node.x=%f y=%f z=%f \n", nodePosition[0], nodePosition[1], nodePosition[2]); | ||
| 273 | //printf("debugNodePosition.x=%f y=%f z=%f \n", debugNodePosition[0], debugNodePosition[1], debugNodePosition[2]); | ||
| 274 | |||
| 275 | float distanceToVoxelCenter = sqrtf(powf(viewerPosition.x - nodePosition[0] - halfUnitForVoxel, 2) + | 324 | float distanceToVoxelCenter = sqrtf(powf(viewerPosition.x - nodePosition[0] - halfUnitForVoxel, 2) + |
| 276 | powf(viewerPosition.y - nodePosition[1] - halfUnitForVoxel, 2) + | 325 | powf(viewerPosition.y - nodePosition[1] - halfUnitForVoxel, 2) + |
| 277 | powf(viewerPosition.z - nodePosition[2] - halfUnitForVoxel, 2)); | 326 | powf(viewerPosition.z - nodePosition[2] - halfUnitForVoxel, 2)); |
| 278 | 327 | ||
| 279 | int renderLevel = *currentNode->octalCode + 1; | 328 | int renderLevel = *currentNode->octalCode + 1; |
| 280 | int boundaryPosition = boundaryDistanceForRenderLevel(renderLevel); | 329 | int boundaryPosition = boundaryDistanceForRenderLevel(renderLevel); |
| 281 | //printLog("treeToArrays() renderLevel=%d distanceToVoxelCenter=%f boundaryPosition=%d\n", | ||
| 282 | // renderLevel,distanceToVoxelCenter,boundaryPosition); | ||
| 283 | |||
| 284 | bool alwaysDraw = false; // XXXBHG - temporary debug code. Flip this to true to disable LOD blurring | 330 | bool alwaysDraw = false; // XXXBHG - temporary debug code. Flip this to true to disable LOD blurring |
| 285 | 331 | ||
| 286 | if (alwaysDraw || distanceToVoxelCenter < boundaryPosition) { | 332 | if (alwaysDraw || distanceToVoxelCenter < boundaryPosition) { |
| @@ -291,22 +337,6 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 4 unmodified lines | |||
| 291 | glm::vec3 childNodePosition; | 337 | glm::vec3 childNodePosition; |
| 292 | copyFirstVertexForCode(currentNode->children[i]->octalCode,(float*)&childNodePosition); | 338 | copyFirstVertexForCode(currentNode->children[i]->octalCode,(float*)&childNodePosition); |
| 293 | childNodePosition *= (float)TREE_SCALE; // scale it up | 339 | childNodePosition *= (float)TREE_SCALE; // scale it up |
| 294 | |||
| 295 | /**** disabled ************************************************************************************************ | ||
| 296 | // Note: Stephen, I intentionally left this in so you would talk to me about it. Here's the deal, this code | ||
| 297 | // doesn't seem to work correctly. It returns X and Z flipped and the values are negative. Since we use the | ||
| 298 | // firstVertexForCode() function below to calculate the child vertex and that DOES work, I've decided to use | ||
| 299 | // that function to calculate our position for LOD handling. | ||
| 300 | // | ||
| 301 | // calculate the child's position based on the parent position | ||
| 302 | for (int j = 0; j < 3; j++) { | ||
| 303 | childNodePosition[j] = nodePosition[j]; | ||
| 304 | |||
| 305 | if (oneAtBit(branchIndexWithDescendant(currentNode->octalCode,currentNode->children[i]->octalCode),(7 - j))) { | ||
| 306 | childNodePosition[j] -= (powf(0.5, *currentNode->children[i]->octalCode) * TREE_SCALE); | ||
| 307 | } | ||
| 308 | } | ||
| 309 | **** disabled ************************************************************************************************/ | ||
| 310 | voxelsAdded += treeToArrays(currentNode->children[i], childNodePosition); | 340 | voxelsAdded += treeToArrays(currentNode->children[i], childNodePosition); |
| 311 | } | 341 | } |
| 312 | } | 342 | } |
| @@ -314,6 +344,15 @@ int VoxelSystem::treeToArrays(VoxelNode *currentNode, const glm::vec3& nodePosi · 1 unmodified line | |||
| 314 | 344 | ||
| 315 | // if we didn't get any voxels added then we're a leaf | 345 | // if we didn't get any voxels added then we're a leaf |
| 316 | // add our vertex and color information to the interleaved array | 346 | // add our vertex and color information to the interleaved array |
| 347 | /****** XXXBHG ***** Stephen!!! ******************************************************************************************** | ||
| 348 | * What is this code about??? Why are we checking to see if voxelsAdded==0???? Shouldn't we always be writing arrays? | ||
| 349 | * Help me understand this? If I remove this check, then two things happen: | ||
| 350 | * 1) I get much more blinking... which is not desirable. | ||
| 351 | * 2) I seem to get large blocks of "average color" voxels... namely I see big voxels, where their should be smaller ones | ||
| 352 | * | ||
| 353 | * But with this check in here, the blinking stops... which kind of makes sense... and the average blocks go away??? not | ||
| 354 | * sure why, but updates seem to be slower... namely, we don't seem to see the new voxels even though the client got them. | ||
| 355 | ***************************************************************************************************************************/ | ||
| 317 | if (voxelsAdded == 0 && currentNode->isColored()) { | 356 | if (voxelsAdded == 0 && currentNode->isColored()) { |
| 318 | float startVertex[3]; | 357 | float startVertex[3]; |
| 319 | copyFirstVertexForCode(currentNode->octalCode,(float*)&startVertex); | 358 | copyFirstVertexForCode(currentNode->octalCode,(float*)&startVertex); |