Showing the changes to interface/src/VoxelSystem.cpp (1 of 1 file). Show all
Unified · Split
| @@ -230,8 +230,6 @@ void VoxelSystem::parseData(void *data, int size) { · 229 unmodified lines | |||
| 230 | // output the bits received from the voxel server | 230 | // output the bits received from the voxel server |
| 231 | unsigned char *voxelData = (unsigned char *) data + 1; | 231 | unsigned char *voxelData = (unsigned char *) data + 1; |
| 232 | 232 | ||
| 233 | printf("Received a packet of %d bytes from VS\n", size); | ||
| 234 | |||
| 235 | // ask the VoxelTree to read the bitstream into the tree | 233 | // ask the VoxelTree to read the bitstream into the tree |
| 236 | tree->readBitstreamToTree(voxelData, size - 1); | 234 | tree->readBitstreamToTree(voxelData, size - 1); |
| 237 | 235 | ||
| @@ -240,10 +238,15 @@ void VoxelSystem::parseData(void *data, int size) { · 2 unmodified lines | |||
| 240 | 238 | ||
| 241 | // call recursive function to populate in memory arrays | 239 | // call recursive function to populate in memory arrays |
| 242 | // it will return the number of voxels added | 240 | // it will return the number of voxels added |
| 243 | voxelsRendered = treeToArrays(tree->rootNode); | 241 | int newVoxels = treeToArrays(tree->rootNode); |
| 244 | 242 | ||
| 245 | // set the boolean if there are any voxels to be rendered so we re-fill the VBOs | 243 | if (newVoxels > voxelsRendered) { |
| 246 | voxelsToRender = (voxelsRendered > 0); | 244 | |
| 245 | voxelsRendered = newVoxels; | ||
| 246 | |||
| 247 | // set the boolean if there are any voxels to be rendered so we re-fill the VBOs | ||
| 248 | voxelsToRender = true; | ||
| 249 | } | ||
| 247 | } | 250 | } |
| 248 | 251 | ||
| 249 | int VoxelSystem::treeToArrays(VoxelNode *currentNode) { | 252 | int VoxelSystem::treeToArrays(VoxelNode *currentNode) { |
| @@ -318,7 +321,9 @@ void VoxelSystem::init() { · 68 unmodified lines | |||
| 318 | // VBO for the indicesArray | 321 | // VBO for the indicesArray |
| 319 | glGenBuffers(1, &vboIndicesID); | 322 | glGenBuffers(1, &vboIndicesID); |
| 320 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); | 323 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); |
| 321 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDICES_PER_VOXEL * sizeof(GLuint) * MAX_VOXELS_PER_SYSTEM, indicesArray, GL_STATIC_DRAW); | 324 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, |
| 325 | INDICES_PER_VOXEL * sizeof(GLuint) * MAX_VOXELS_PER_SYSTEM, | ||
| 326 | indicesArray, GL_STATIC_DRAW); | ||
| 322 | 327 | ||
| 323 | // delete the indices array that is no longer needed | 328 | // delete the indices array that is no longer needed |
| 324 | delete[] indicesArray; | 329 | delete[] indicesArray; |
| @@ -352,6 +357,7 @@ void VoxelSystem::render() { · 27 unmodified lines | |||
| 352 | 357 | ||
| 353 | // draw the number of voxels we have | 358 | // draw the number of voxels we have |
| 354 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); | 359 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID); |
| 360 | glTranslatef(40, 0, 40); | ||
| 355 | glScalef(10, 10, 10); | 361 | glScalef(10, 10, 10); |
| 356 | glDrawElements(GL_TRIANGLES, 36 * voxelsRendered, GL_UNSIGNED_INT, 0); | 362 | glDrawElements(GL_TRIANGLES, 36 * voxelsRendered, GL_UNSIGNED_INT, 0); |
| 357 | 363 | ||