receive bitstream from voxel server on client

This commit is contained in:
Stephen Birarda 2013-03-19 15:51:48 -07:00
parent 482e65c296
commit 92fc1ed1a6
2 changed files with 56 additions and 40 deletions

View file

@ -6,9 +6,10 @@
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. // Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
// //
#include "VoxelSystem.h"
#include <AgentList.h>
#include <cstring> #include <cstring>
#include <SharedUtil.h>
#include <AgentList.h>
#include "VoxelSystem.h"
const int MAX_VOXELS_PER_SYSTEM = 500000; const int MAX_VOXELS_PER_SYSTEM = 500000;
@ -37,53 +38,66 @@ GLubyte identityIndices[] = { 0,1,2, 0,2,3,
VoxelSystem::VoxelSystem() { VoxelSystem::VoxelSystem() {
voxelsRendered = 0; voxelsRendered = 0;
tree = new VoxelTree();
} }
VoxelSystem::~VoxelSystem() { VoxelSystem::~VoxelSystem() {
delete[] verticesArray; delete[] verticesArray;
delete[] colorsArray; delete[] colorsArray;
delete tree;
} }
void VoxelSystem::parseData(void *data, int size) { void VoxelSystem::parseData(void *data, int size) {
// ignore the first char, it's a V to tell us that this is voxel data // output the bits received from the voxel server
char *voxelDataPtr = (char *) data + 1; unsigned char *voxelData = (unsigned char *) data + 1;
printf("Received a packet of %d bytes from VS\n", size);
// ask the VoxelTree to read the bitstream into the tree
tree->readBitstreamToTree(voxelData, size - 1);
// output the VoxelTree data to see if it matches the server
tree->printTreeForDebugging(tree->rootNode);
GLfloat *position = new GLfloat[3]; // // ignore the first char, it's a V to tell us that this is voxel data
GLubyte *color = new GLubyte[3]; // char *voxelDataPtr = (char *) data + 1;
//
// get pointers to position of last append of data // GLfloat *position = new GLfloat[3];
GLfloat *parseVerticesPtr = lastAddPointer; // GLubyte *color = new GLubyte[3];
GLubyte *parseColorsPtr = colorsArray + (lastAddPointer - verticesArray); //
// // get pointers to position of last append of data
int voxelsInData = 0; // GLfloat *parseVerticesPtr = lastAddPointer;
// GLubyte *parseColorsPtr = colorsArray + (lastAddPointer - verticesArray);
// pull voxels out of the received data and put them into our internal memory structure //
while ((voxelDataPtr - (char *) data) < size) { // int voxelsInData = 0;
//
memcpy(position, voxelDataPtr, 3 * sizeof(float)); // // pull voxels out of the received data and put them into our internal memory structure
voxelDataPtr += 3 * sizeof(float); // while ((voxelDataPtr - (char *) data) < size) {
memcpy(color, voxelDataPtr, 3); //
voxelDataPtr += 3; // memcpy(position, voxelDataPtr, 3 * sizeof(float));
// voxelDataPtr += 3 * sizeof(float);
for (int v = 0; v < VERTEX_POINTS_PER_VOXEL; v++) { // memcpy(color, voxelDataPtr, 3);
parseVerticesPtr[v] = position[v % 3] + (identityVertices[v] * CUBE_WIDTH); // voxelDataPtr += 3;
} //
// for (int v = 0; v < VERTEX_POINTS_PER_VOXEL; v++) {
parseVerticesPtr += VERTEX_POINTS_PER_VOXEL; // parseVerticesPtr[v] = position[v % 3] + (identityVertices[v] * CUBE_WIDTH);
// }
for (int c = 0; c < COLOR_VALUES_PER_VOXEL; c++) { //
parseColorsPtr[c] = color[c % 3]; // parseVerticesPtr += VERTEX_POINTS_PER_VOXEL;
} //
// for (int c = 0; c < COLOR_VALUES_PER_VOXEL; c++) {
parseColorsPtr += COLOR_VALUES_PER_VOXEL; // parseColorsPtr[c] = color[c % 3];
// }
//
voxelsInData++; // parseColorsPtr += COLOR_VALUES_PER_VOXEL;
} //
//
// increase the lastAddPointer to the new spot, increase the number of rendered voxels // voxelsInData++;
lastAddPointer = parseVerticesPtr; // }
voxelsRendered += voxelsInData; //
// // increase the lastAddPointer to the new spot, increase the number of rendered voxels
// lastAddPointer = parseVerticesPtr;
// voxelsRendered += voxelsInData;
} }
VoxelSystem* VoxelSystem::clone() const { VoxelSystem* VoxelSystem::clone() const {

View file

@ -14,6 +14,7 @@
#include <iostream> #include <iostream>
#include <UDPSocket.h> #include <UDPSocket.h>
#include <AgentData.h> #include <AgentData.h>
#include <VoxelTree.h>
#include "Util.h" #include "Util.h"
#include "world.h" #include "world.h"
@ -34,6 +35,7 @@ public:
int getVoxelsRendered() {return voxelsRendered;}; int getVoxelsRendered() {return voxelsRendered;};
private: private:
int voxelsRendered; int voxelsRendered;
VoxelTree *tree;
GLfloat *verticesArray; GLfloat *verticesArray;
GLubyte *colorsArray; GLubyte *colorsArray;
GLfloat *lastAddPointer; GLfloat *lastAddPointer;