From fe8b6f7d635ca956ddafe01faa6ad2a5e7af18f2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 28 Mar 2013 13:54:28 -0700 Subject: [PATCH 1/3] * Moved load file and create sphere from VoxelSystem to VoxelTree * Added --local command line support to domain and voxel servers so that you can run them locally without recompiling. * made command line option parsing more cross platform * added --NoColorRandomizer to interface when loading local models * added -i file load support to voxel server to load in a preexisting model at launch * added --NoRandomVoxelSheet to voxel server to NOT create the built in voxel sheet * added first cut at 'I' command from clients to voxel server to insert voxels into voxel tree * changed ambient light settings in interface to not be so aggressive * added randInIntRange() helper to SharedUtils * tweat to pruneTree() to also repair child mask * some coding standard refactoring --- domain/src/main.cpp | 22 ++++- interface/src/VoxelSystem.cpp | 148 +----------------------------- interface/src/VoxelSystem.h | 2 +- interface/src/main.cpp | 21 +++-- shared/src/SharedUtil.cpp | 54 +++++------ shared/src/SharedUtil.h | 5 +- shared/src/VoxelTree.cpp | 168 ++++++++++++++++++++++++++++++---- shared/src/VoxelTree.h | 2 + voxel/src/main.cpp | 43 ++++++++- 9 files changed, 254 insertions(+), 211 deletions(-) diff --git a/domain/src/main.cpp b/domain/src/main.cpp index 4db6bc45b9..7ef0967e1b 100644 --- a/domain/src/main.cpp +++ b/domain/src/main.cpp @@ -37,6 +37,7 @@ #include #endif + const int DOMAIN_LISTEN_PORT = 40102; unsigned char packetData[MAX_PACKET_SIZE]; @@ -60,6 +61,21 @@ unsigned char * addAgentToBroadcastPacket(unsigned char *currentPosition, Agent int main(int argc, const char * argv[]) { + // If user asks to run in "local" mode then we do NOT replace the IP + // with the EC2 IP. Otherwise, we will replace the IP like we used to + // this allows developers to run a local domain without recompiling the + // domain server + bool useLocal = cmdOptionExists(argc, argv, "--local"); + if (useLocal) { + printf("NOTE: Running in Local Mode!\n"); + } else { + printf("--------------------------------------------------\n"); + printf("NOTE: Running in EC2 Mode. \n"); + printf("If you're a developer testing a local system, you\n"); + printf("probably want to include --local on command line.\n"); + printf("--------------------------------------------------\n"); + } + setvbuf(stdout, NULL, _IOLBF, 0); ssize_t receivedBytes = 0; @@ -90,7 +106,11 @@ int main(int argc, const char * argv[]) // if it matches our local address we're on the same box // so hardcode the EC2 public address for now if (agentPublicAddress.sin_addr.s_addr == serverLocalAddress) { - agentPublicAddress.sin_addr.s_addr = 895283510; + // If we're not running "local" then we do replace the IP + // with the EC2 IP. Otherwise, we use our normal public IP + if (!useLocal) { + agentPublicAddress.sin_addr.s_addr = 895283510; // local IP in this format... + } } if (agentList.addOrUpdateAgent((sockaddr *)&agentPublicAddress, diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index c4ead46090..e633ab06d2 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -14,7 +14,7 @@ #include #include "VoxelSystem.h" -const int MAX_VOXELS_PER_SYSTEM = 250000; +const int MAX_VOXELS_PER_SYSTEM = 1500000; //250000; const int VERTICES_PER_VOXEL = 8; const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL; @@ -54,57 +54,9 @@ VoxelSystem::~VoxelSystem() { // colors are set randomly // Complaints: Brad :) // To Do: Need to add color data to the file. -void VoxelSystem::loadVoxelsFile(char* fileName) { - int vCount = 0; - - std::ifstream file(fileName, std::ios::in|std::ios::binary); - - char octets; - unsigned int lengthInBytes; +void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) { - int totalBytesRead = 0; - if(file.is_open()) - { - bool bail = false; - while (!file.eof() && !bail) { - file.get(octets); - totalBytesRead++; - lengthInBytes = bytesRequiredForCodeLength(octets)-1; //(octets*3/8)+1; - unsigned char * voxelData = new unsigned char[lengthInBytes+1+3]; - voxelData[0]=octets; - char byte; - - for (size_t i = 0; i < lengthInBytes; i++) { - file.get(byte); - totalBytesRead++; - voxelData[i+1] = byte; - } - // read color data - char red,green,blue; - file.get(red); - file.get(green); - file.get(blue); - - //printf("red:%d\n",red); - //printf("green:%d\n",green); - //printf("blue:%d\n",blue); - vCount++; - //printf("vCount:%d\n",vCount); - - //randomColorValue(65); - float rf = randFloatInRange(.5,1); // add a little bit of variance to colors so we can see the voxels - voxelData[lengthInBytes+1] = red * rf; - voxelData[lengthInBytes+2] = green * rf; - voxelData[lengthInBytes+3] = blue * rf; - - //printVoxelCode(voxelData); - tree->readCodeColorBufferToTree(voxelData); - delete voxelData; - } - file.close(); - } - - tree->pruneTree(tree->rootNode); + tree->loadVoxelsFile(fileName,wantColorRandomizer); // reset the verticesEndPointer so we're writing to the beginning of the array verticesEndPointer = verticesArray; @@ -122,99 +74,9 @@ void VoxelSystem::loadVoxelsFile(char* fileName) { // mechanism to tell the system to redraw it's arrays after voxels are done // being added. This is a concept mostly only understood by VoxelSystem. // Complaints: Brad :) -void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bool solid) -{ - // About the color of the sphere... we're going to make this sphere be a gradient - // between two RGB colors. We will do the gradient along the phi spectrum - unsigned char r1 = randomColorValue(165); - unsigned char g1 = randomColorValue(165); - unsigned char b1 = randomColorValue(165); - unsigned char r2 = randomColorValue(65); - unsigned char g2 = randomColorValue(65); - unsigned char b2 = randomColorValue(65); - - // we don't want them to match!! - if (r1==r2 && g1==g2 && b1==b2) - { - r2=r1/2; - g2=g1/2; - b2=b1/2; - } +void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bool solid) { - /** - std::cout << "creatSphere COLORS "; - std::cout << " r1=" << (int)r1; - std::cout << " g1=" << (int)g1; - std::cout << " b1=" << (int)b1; - std::cout << " r2=" << (int)r2; - std::cout << " g2=" << (int)g2; - std::cout << " b2=" << (int)b2; - std::cout << std::endl; - **/ - - // Psuedocode for creating a sphere: - // - // for (theta from 0 to 2pi): - // for (phi from 0 to pi): - // x = xc+r*cos(theta)*sin(phi) - // y = yc+r*sin(theta)*sin(phi) - // z = zc+r*cos(phi) - - int t=0; // total points - - // We want to make sure that as we "sweep" through our angles - // we use a delta angle that's small enough to not skip any voxels - // we can calculate theta from our desired arc length - // - // lenArc = ndeg/360deg * 2pi*R - // lenArc = theta/2pi * 2pi*R - // lenArc = theta*R - // theta = lenArc/R - // theta = g/r - float angleDelta = (s/r); - - // assume solid for now - float ri = 0.0; - if (!solid) - { - ri=r; // just the outer surface - } - // If you also iterate form the interior of the sphere to the radius, makeing - // larger and larger sphere's you'd end up with a solid sphere. And lots of voxels! - for (; ri <= r; ri+=s) - { - for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) - { - for (float phi=0.0; phi <= M_PI; phi += angleDelta) - { - t++; // total voxels - float x = xc+r*cos(theta)*sin(phi); - float y = yc+r*sin(theta)*sin(phi); - float z = zc+r*cos(phi); - /* - std::cout << " r=" << r; - std::cout << " theta=" << theta; - std::cout << " phi=" << phi; - std::cout << " x=" << x; - std::cout << " y=" << y; - std::cout << " z=" << z; - std::cout << " t=" << t; - std::cout << std::endl; - */ - - // gradient color data - float gradient = (phi/M_PI); - unsigned char red = r1+((r2-r1)*gradient); - unsigned char green = g1+((g2-g1)*gradient); - unsigned char blue = b1+((b2-b1)*gradient); - - unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue); - tree->readCodeColorBufferToTree(voxelData); - delete voxelData; - - } - } - } + tree->createSphere(r,xc,yc,zc,s,solid); // reset the verticesEndPointer so we're writing to the beginning of the array verticesEndPointer = verticesArray; diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 6755886225..4427f71c49 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -33,7 +33,7 @@ public: void render(); void setVoxelsRendered(int v) {voxelsRendered = v;}; int getVoxelsRendered() {return voxelsRendered;}; - void loadVoxelsFile(char* fileName); + void loadVoxelsFile(const char* fileName,bool wantColorRandomizer); void createSphere(float r,float xc, float yc, float zc, float s, bool solid); private: int voxelsRendered; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 747254aeb8..203d9098e4 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -476,9 +476,9 @@ void display(void) GLfloat light_position0[] = { 1.0, 1.0, 0.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position0); - GLfloat ambient_color[] = { 0.125, 0.305, 0.5 }; + GLfloat ambient_color[] = { 0.7, 0.7, 0.8 }; //{ 0.125, 0.305, 0.5 }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color); - GLfloat diffuse_color[] = { 0.5, 0.42, 0.33 }; + GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 }; //{ 0.5, 0.42, 0.33 }; glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color); GLfloat specular_color[] = { 1.0, 1.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_SPECULAR, specular_color); @@ -895,7 +895,7 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) { } #endif -int main(int argc, char** argv) +int main(int argc, const char * argv[]) { // the callback for our instance of AgentList is attachNewHeadToAgent agentList.linkedDataCreateCallback = &attachNewHeadToAgent; @@ -913,7 +913,7 @@ int main(int argc, char** argv) int wsaresult = WSAStartup( MAKEWORD(2,2), &WsaData ); #endif - glutInit(&argc, argv); + glutInit(&argc, (char**)argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(WIDTH, HEIGHT); glutCreateWindow("Interface"); @@ -941,12 +941,17 @@ int main(int argc, char** argv) init(); + bool wantColorRandomizer = true; + // Check to see if the user passed in a command line option for randomizing colors + if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) { + wantColorRandomizer = false; + } + // Check to see if the user passed in a command line option for loading a local // Voxel File. If so, load it now. - char* voxelsFilename = getCmdOption(argc, argv, "-i"); - if (voxelsFilename) - { - voxels.loadVoxelsFile(voxelsFilename); + const char* voxelsFilename = getCmdOption(argc, argv, "-i"); + if (voxelsFilename) { + voxels.loadVoxelsFile(voxelsFilename,wantColorRandomizer); } // create thread for receipt of data via UDP diff --git a/shared/src/SharedUtil.cpp b/shared/src/SharedUtil.cpp index 6f1ae3fa90..2890a4f5bc 100644 --- a/shared/src/SharedUtil.cpp +++ b/shared/src/SharedUtil.cpp @@ -29,6 +29,10 @@ float randFloat () { return (rand() % 10000)/10000.f; } +int randIntInRange (int min, int max) { + return min + (rand() % (max - min)); +} + float randFloatInRange (float min,float max) { return min + ((rand() % 10000)/10000.f * (max-min)); } @@ -89,14 +93,11 @@ void switchToResourcesIfRequired() { // then you're using the "-i" flag to set the input file name. // Usage: char * inputFilename = getCmdOption(argc, argv, "-i"); // Complaints: Brad :) -char* getCmdOption(int argc, char** argv,char* option) -{ +const char* getCmdOption(int argc, const char * argv[],char* option) { // check each arg - for (int i=0; i < argc; i++) - { + for (int i=0; i < argc; i++) { // if the arg matches the desired option - if (strcmp(option,argv[i])==0 && i+1 < argc) - { + if (strcmp(option,argv[i])==0 && i+1 < argc) { // then return the next option return argv[i+1]; } @@ -110,14 +111,12 @@ char* getCmdOption(int argc, char** argv,char* option) // included while launching the application. Returns bool true/false // Usage: bool wantDump = cmdOptionExists(argc, argv, "-d"); // Complaints: Brad :) -bool cmdOptionExists(int argc, char** argv,char* option) -{ + +bool cmdOptionExists(int argc, const char * argv[],char* option) { // check each arg - for (int i=0; i < argc; i++) - { + for (int i=0; i < argc; i++) { // if the arg matches the desired option - if (strcmp(option,argv[i])==0) - { + if (strcmp(option,argv[i])==0) { // then return the next option return true; } @@ -172,13 +171,11 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, // Now we actually fill out the voxel code while (octetsDone < voxelSizeInOctets) { - if (x > xTest) { // byte = (byte << 1) | true; xTest += sTest/2.0; - } - else { + } else { // byte = (byte << 1) | false; xTest -= sTest/2.0; @@ -186,8 +183,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, bitInByteNDX++; // If we've reached the last bit of the byte, then we want to copy this byte // into our buffer. And get ready to start on a new byte - if (bitInByteNDX > 7) - { + if (bitInByteNDX > 7) { voxelOut[byteNDX]=byte; byteNDX++; bitInByteNDX=0; @@ -198,8 +194,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, // byte = (byte << 1) | true; yTest += sTest/2.0; - } - else { + } else { // byte = (byte << 1) | false; yTest -= sTest/2.0; @@ -207,8 +202,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, bitInByteNDX++; // If we've reached the last bit of the byte, then we want to copy this byte // into our buffer. And get ready to start on a new byte - if (bitInByteNDX > 7) - { + if (bitInByteNDX > 7) { voxelOut[byteNDX]=byte; byteNDX++; bitInByteNDX=0; @@ -219,8 +213,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, // byte = (byte << 1) | true; zTest += sTest/2.0; - } - else { + } else { // byte = (byte << 1) | false; zTest -= sTest/2.0; @@ -228,8 +221,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, bitInByteNDX++; // If we've reached the last bit of the byte, then we want to copy this byte // into our buffer. And get ready to start on a new byte - if (bitInByteNDX > 7) - { + if (bitInByteNDX > 7) { voxelOut[byteNDX]=byte; byteNDX++; bitInByteNDX=0; @@ -242,11 +234,9 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, // If we've got here, and we didn't fill the last byte, we need to zero pad this // byte before we copy it into our buffer. - if (bitInByteNDX > 0 && bitInByteNDX < 7) - { + if (bitInByteNDX > 0 && bitInByteNDX < 7) { // Pad the last byte - while (bitInByteNDX <= 7) - { + while (bitInByteNDX <= 7) { byte = (byte << 1) | false; bitInByteNDX++; } @@ -263,8 +253,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, return voxelOut; } -void printVoxelCode(unsigned char* voxelCode) -{ +void printVoxelCode(unsigned char* voxelCode) { unsigned char octets = voxelCode[0]; unsigned int voxelSizeInBits = octets*3; unsigned int voxelSizeInBytes = (voxelSizeInBits/8)+1; @@ -277,8 +266,7 @@ void printVoxelCode(unsigned char* voxelCode) printf("voxelSizeInOctets=%d\n",voxelSizeInOctets); printf("voxelBufferSize=%d\n",voxelBufferSize); - for(int i=0;i // to load voxels from file +#include // to load voxels from file VoxelTree::VoxelTree() { rootNode = new VoxelNode(); @@ -80,39 +82,39 @@ VoxelNode * VoxelTree::createMissingNode(VoxelNode *lastParentNode, unsigned cha /// If node has color & <= 4 children then prune children void VoxelTree::pruneTree(VoxelNode* pruneAt) { int childCount = 0; + int childMask = 0; // determine how many children we have - for (int i = 0; i < 8; i++) - { - if (pruneAt->children[i]) - { + for (int i = 0; i < 8; i++) { + if (pruneAt->children[i]) { childCount++; } } // if appropriate, prune them - if (pruneAt->color[3] && childCount <= 4) - { - for (int i = 0; i < 8; i++) - { - if (pruneAt->children[i]) - { + if (pruneAt->color[3] && childCount <= 4) { + for (int i = 0; i < 8; i++) { + if (pruneAt->children[i]) { delete pruneAt->children[i]; pruneAt->children[i]=NULL; } } - } - else - { + } else { // Otherwise, iterate the children and recursively call // prune on all of them - for (int i = 0; i < 8; i++) - { - if (pruneAt->children[i]) - { + for (int i = 0; i < 8; i++) { + if (pruneAt->children[i]) { this->pruneTree(pruneAt->children[i]); } } } + // repair our child mask + // determine how many children we have + pruneAt->childMask = 0; + for (int i = 0; i < 8; i++) { + if (pruneAt->children[i]) { + pruneAt->childMask += (1 << (7 - i)); + } + } } int VoxelTree::readNodeData(VoxelNode *destinationNode, unsigned char * nodeData, int bytesLeftToRead) { @@ -328,4 +330,134 @@ void VoxelTree::printTreeForDebugging(VoxelNode *startNode) { printTreeForDebugging(startNode->children[k]); } } -} \ No newline at end of file +} + + +////////////////////////////////////////////////////////////////////////////////////////// +// Method: VoxelTree::loadVoxelsFile() +// Description: Loads HiFidelity encoded Voxels from a binary file. The current file +// format is a stream of single voxels with color data. +// Complaints: Brad :) +void VoxelTree::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) { + int vCount = 0; + + std::ifstream file(fileName, std::ios::in|std::ios::binary); + + char octets; + unsigned int lengthInBytes; + + int totalBytesRead = 0; + if(file.is_open()) { + printf("loading file...\n"); + bool bail = false; + while (!file.eof() && !bail) { + file.get(octets); + //printf("octets=%d...\n",octets); + totalBytesRead++; + lengthInBytes = bytesRequiredForCodeLength(octets)-1; //(octets*3/8)+1; + unsigned char * voxelData = new unsigned char[lengthInBytes+1+3]; + voxelData[0]=octets; + char byte; + + for (size_t i = 0; i < lengthInBytes; i++) { + file.get(byte); + totalBytesRead++; + voxelData[i+1] = byte; + } + // read color data + char colorRead; + unsigned char red,green,blue; + file.get(colorRead); + red = (unsigned char)colorRead; + file.get(colorRead); + green = (unsigned char)colorRead; + file.get(colorRead); + blue = (unsigned char)colorRead; + + printf("voxel color from file red:%d\, green:%d, blue:%d \n",red,green,blue); + vCount++; + //printf("vCount:%d\n",vCount); + + int colorRandomizer = wantColorRandomizer ? randIntInRange (-5, 5) : 0; + voxelData[lengthInBytes+1] = std::max(0,std::min(255,red + colorRandomizer)); + voxelData[lengthInBytes+2] = std::max(0,std::min(255,green + colorRandomizer)); + voxelData[lengthInBytes+3] = std::max(0,std::min(255,blue + colorRandomizer)); + printf("voxel color after rand red:%d\, green:%d, blue:%d\n",voxelData[lengthInBytes+1],voxelData[lengthInBytes+2],voxelData[lengthInBytes+3]); + + //printVoxelCode(voxelData); + this->readCodeColorBufferToTree(voxelData); + delete voxelData; + } + file.close(); + } + + this->pruneTree(this->rootNode); +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Method: VoxelTree::createSphere() +// Description: Creates a sphere of voxels in the local system at a given location/radius +// To Do: Move this function someplace better? Do we really need to call pruneTree()?? +// Complaints: Brad :) +void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool solid) { + // About the color of the sphere... we're going to make this sphere be a gradient + // between two RGB colors. We will do the gradient along the phi spectrum + unsigned char r1 = randomColorValue(165); + unsigned char g1 = randomColorValue(165); + unsigned char b1 = randomColorValue(165); + unsigned char r2 = randomColorValue(65); + unsigned char g2 = randomColorValue(65); + unsigned char b2 = randomColorValue(65); + + // we don't want them to match!! + if (r1==r2 && g1==g2 && b1==b2) { + r2=r1/2; + g2=g1/2; + b2=b1/2; + } + + // Psuedocode for creating a sphere: + // + // for (theta from 0 to 2pi): + // for (phi from 0 to pi): + // x = xc+r*cos(theta)*sin(phi) + // y = yc+r*sin(theta)*sin(phi) + // z = zc+r*cos(phi) + + int t=0; // total points + + // We want to make sure that as we "sweep" through our angles we use a delta angle that's small enough to not skip any + // voxels we can calculate theta from our desired arc length + // lenArc = ndeg/360deg * 2pi*R ---> lenArc = theta/2pi * 2pi*R + // lenArc = theta*R ---> theta = lenArc/R ---> theta = g/r + float angleDelta = (s/r); + + // assume solid for now + float ri = 0.0; + if (!solid) { + ri=r; // just the outer surface + } + // If you also iterate form the interior of the sphere to the radius, makeing + // larger and larger sphere's you'd end up with a solid sphere. And lots of voxels! + for (; ri <= r; ri+=s) { + for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) { + for (float phi=0.0; phi <= M_PI; phi += angleDelta) { + t++; // total voxels + float x = xc+r*cos(theta)*sin(phi); + float y = yc+r*sin(theta)*sin(phi); + float z = zc+r*cos(phi); + + // gradient color data + float gradient = (phi/M_PI); + unsigned char red = r1+((r2-r1)*gradient); + unsigned char green = g1+((g2-g1)*gradient); + unsigned char blue = b1+((b2-b1)*gradient); + + unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue); + this->readCodeColorBufferToTree(voxelData); + delete voxelData; + } + } + } + this->pruneTree(this->rootNode); // XXXBHG Hack: Need to call this for now??? +} diff --git a/shared/src/VoxelTree.h b/shared/src/VoxelTree.h index bea2533543..a862bf56ef 100644 --- a/shared/src/VoxelTree.h +++ b/shared/src/VoxelTree.h @@ -36,6 +36,8 @@ public: void printTreeForDebugging(VoxelNode *startNode); void pruneTree(VoxelNode* pruneAt); + void loadVoxelsFile(const char* fileName, bool wantColorRandomizer); + void createSphere(float r,float xc, float yc, float zc, float s, bool solid); }; #endif /* defined(__hifi__VoxelTree__) */ diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index dc64e34eaf..8bc08a88c0 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -110,6 +110,14 @@ int main(int argc, const char * argv[]) { setvbuf(stdout, NULL, _IOLBF, 0); + // Handle Local Domain testing with the --local command line + bool wantLocalDomain = cmdOptionExists(argc, argv, "--local"); + if (wantLocalDomain) { + printf("Local Domain MODE!\n"); + int ip = getLocalAddress(); + sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF)); + } + agentList.linkedDataCreateCallback = &attachVoxelAgentDataToAgent; agentList.startSilentAgentRemovalThread(); agentList.startDomainServerCheckInThread(); @@ -119,9 +127,18 @@ int main(int argc, const char * argv[]) // use our method to create a random voxel tree VoxelTree randomTree; - // create an octal code buffer and load it with 0 so that the recursive tree fill can give - // octal codes to the tree nodes that it is creating - randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode); + // Check to see if the user passed in a command line option for loading a local + // Voxel File. If so, load it now. + bool wantColorRandomizer = !cmdOptionExists(argc, argv, "--NoColorRandomizer"); + const char* voxelsFilename = getCmdOption(argc, argv, "-i"); + if (voxelsFilename) { + randomTree.loadVoxelsFile(voxelsFilename,wantColorRandomizer); + } + if (!cmdOptionExists(argc, argv, "--NoRandomVoxelSheet")) { + // create an octal code buffer and load it with 0 so that the recursive tree fill can give + // octal codes to the tree nodes that it is creating + randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode); + } unsigned char *voxelPacket = new unsigned char[MAX_VOXEL_PACKET_SIZE]; unsigned char *voxelPacketEnd; @@ -138,8 +155,25 @@ int main(int argc, const char * argv[]) // loop to send to agents requesting data while (true) { if (agentList.getAgentSocket().receive(&agentPublicAddress, packetData, &receivedBytes)) { + // XXXBHG: Hacked in support for 'I' insert command + if (packetData[0] == 'I') { + unsigned short int itemNumber = (*((unsigned short int*)&packetData[1])); + printf("got I command from client receivedBytes=%ld itemNumber=%d\n",receivedBytes,itemNumber); + int atByte = 3; + unsigned char* pVoxelData = (unsigned char*)&packetData[3]; + while (atByte < receivedBytes) { + unsigned char octets = (unsigned char)*pVoxelData; + int voxelDataSize = bytesRequiredForCodeLength(octets)+3; // 3 for color! + randomTree.readCodeColorBufferToTree(pVoxelData); + //printf("readCodeColorBufferToTree() of size=%d atByte=%d receivedBytes=%ld\n",voxelDataSize,atByte,receivedBytes); + // skip to next + pVoxelData+=voxelDataSize; + atByte+=voxelDataSize; + } + //printf("about to call pruneTree()\n"); + //randomTree.pruneTree(randomTree.rootNode); // hack + } if (packetData[0] == 'H') { - if (agentList.addOrUpdateAgent(&agentPublicAddress, &agentPublicAddress, packetData[0], agentList.getLastAgentId())) { agentList.increaseAgentId(); } @@ -156,7 +190,6 @@ int main(int argc, const char * argv[]) packetCount = 0; totalBytesSent = 0; randomTree.leavesWrittenToBitstream = 0; - while (stopOctal != NULL) { voxelPacketEnd = voxelPacket; stopOctal = randomTree.loadBitstreamBuffer(voxelPacketEnd, From 6ec9949098221054fa610b940560575d3e1d4116 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 28 Mar 2013 14:03:16 -0700 Subject: [PATCH 2/3] Add --local support to interface command line --- interface/src/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 203d9098e4..f0eecd4d62 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -897,6 +897,14 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) { int main(int argc, const char * argv[]) { + // Handle Local Domain testing with the --local command line + bool wantLocalDomain = cmdOptionExists(argc, argv, "--local"); + if (wantLocalDomain) { + printf("Local Domain MODE!\n"); + int ip = getLocalAddress(); + sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF)); + } + // the callback for our instance of AgentList is attachNewHeadToAgent agentList.linkedDataCreateCallback = &attachNewHeadToAgent; From 055c46c60f79ab0153b9e2de64a79081530a71c3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 28 Mar 2013 14:32:53 -0700 Subject: [PATCH 3/3] add spheres from command line --- voxel/src/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/voxel/src/main.cpp b/voxel/src/main.cpp index 8bc08a88c0..e20ed3f3c6 100644 --- a/voxel/src/main.cpp +++ b/voxel/src/main.cpp @@ -43,6 +43,23 @@ const int MAX_VOXEL_TREE_DEPTH_LEVELS = 10; AgentList agentList('V', VOXEL_LISTEN_PORT); +void addRandomSphere(VoxelTree * tree) { + float r = randFloatInRange(0.05,0.1); + float xc = randFloatInRange(r,(1-r)); + float yc = randFloatInRange(r,(1-r)); + float zc = randFloatInRange(r,(1-r)); + float s = 0.001; // size of voxels to make up surface of sphere + bool solid = true; + + printf("random sphere\n"); + printf("radius=%f\n",r); + printf("xc=%f\n",xc); + printf("yc=%f\n",yc); + printf("zc=%f\n",zc); + + tree->createSphere(r,xc,yc,zc,s,solid); +} + int randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) { // randomly generate children for this node // the first level of the tree (where levelsToGo = MAX_VOXEL_TREE_DEPTH_LEVELS) has all 8 @@ -139,6 +156,10 @@ int main(int argc, const char * argv[]) // octal codes to the tree nodes that it is creating randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode); } + + if (cmdOptionExists(argc, argv, "--AddRandomSpheres")) { + addRandomSphere(&randomTree); + } unsigned char *voxelPacket = new unsigned char[MAX_VOXEL_PACKET_SIZE]; unsigned char *voxelPacketEnd;