mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 18:44:00 +02:00
added random color options, cleaned up compiler warnings, add reAverageParentColors when modifying voxel tree
This commit is contained in:
parent
f85abe53ef
commit
270f77799d
8 changed files with 51 additions and 35 deletions
|
@ -74,9 +74,9 @@ void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer)
|
|||
// 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) {
|
||||
void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer) {
|
||||
|
||||
tree->createSphere(r,xc,yc,zc,s,solid);
|
||||
tree->createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
|
||||
|
||||
// reset the verticesEndPointer so we're writing to the beginning of the array
|
||||
verticesEndPointer = verticesArray;
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
void setVoxelsRendered(int v) {voxelsRendered = v;};
|
||||
int getVoxelsRendered() {return voxelsRendered;};
|
||||
void loadVoxelsFile(const char* fileName,bool wantColorRandomizer);
|
||||
void createSphere(float r,float xc, float yc, float zc, float s, bool solid);
|
||||
void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer);
|
||||
private:
|
||||
int voxelsRendered;
|
||||
VoxelTree *tree;
|
||||
|
|
|
@ -81,6 +81,8 @@ int WIDTH = 1200;
|
|||
int HEIGHT = 800;
|
||||
int fullscreen = 0;
|
||||
|
||||
bool wantColorRandomizer = true; // for addSphere and load file
|
||||
|
||||
Oscilloscope audioScope(256,200,true);
|
||||
|
||||
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
|
||||
|
@ -625,7 +627,7 @@ void testPointToVoxel()
|
|||
}
|
||||
}
|
||||
|
||||
void addRandomSphere()
|
||||
void addRandomSphere(bool wantColorRandomizer)
|
||||
{
|
||||
float r = randFloatInRange(0.05,0.1);
|
||||
float xc = randFloatInRange(r,(1-r));
|
||||
|
@ -640,7 +642,7 @@ void addRandomSphere()
|
|||
printf("yc=%f\n",yc);
|
||||
printf("zc=%f\n",zc);
|
||||
|
||||
voxels.createSphere(r,xc,yc,zc,s,solid);
|
||||
voxels.createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -758,7 +760,7 @@ void key(unsigned char k, int x, int y)
|
|||
// press the . key to get a new random sphere of voxels added
|
||||
if (k == '.')
|
||||
{
|
||||
addRandomSphere();
|
||||
addRandomSphere(wantColorRandomizer);
|
||||
//testPointToVoxel();
|
||||
}
|
||||
}
|
||||
|
@ -899,7 +901,7 @@ int main(int argc, const char * argv[])
|
|||
{
|
||||
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
||||
if (domainIP) {
|
||||
sprintf(DOMAIN_IP,domainIP);
|
||||
strcpy(DOMAIN_IP,domainIP);
|
||||
}
|
||||
|
||||
// Handle Local Domain testing with the --local command line
|
||||
|
@ -953,7 +955,6 @@ int main(int argc, const 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;
|
||||
|
|
|
@ -93,7 +93,7 @@ void switchToResourcesIfRequired() {
|
|||
// then you're using the "-i" flag to set the input file name.
|
||||
// Usage: char * inputFilename = getCmdOption(argc, argv, "-i");
|
||||
// Complaints: Brad :)
|
||||
const char* getCmdOption(int argc, const char * argv[],char* option) {
|
||||
const char* getCmdOption(int argc, const char * argv[],const char* option) {
|
||||
// check each arg
|
||||
for (int i=0; i < argc; i++) {
|
||||
// if the arg matches the desired option
|
||||
|
@ -112,7 +112,7 @@ const char* getCmdOption(int argc, const char * argv[],char* option) {
|
|||
// Usage: bool wantDump = cmdOptionExists(argc, argv, "-d");
|
||||
// Complaints: Brad :)
|
||||
|
||||
bool cmdOptionExists(int argc, const char * argv[],char* option) {
|
||||
bool cmdOptionExists(int argc, const char * argv[],const char* option) {
|
||||
// check each arg
|
||||
for (int i=0; i < argc; i++) {
|
||||
// if the arg matches the desired option
|
||||
|
|
|
@ -34,8 +34,8 @@ bool oneAtBit(unsigned char byte, int bitIndex);
|
|||
|
||||
void switchToResourcesIfRequired();
|
||||
|
||||
const char* getCmdOption(int argc, const char * argv[],char* option);
|
||||
bool cmdOptionExists(int argc, const char * argv[],char* option);
|
||||
const char* getCmdOption(int argc, const char * argv[],const char* option);
|
||||
bool cmdOptionExists(int argc, const char * argv[],const char* option);
|
||||
unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, unsigned char g, unsigned char b );
|
||||
|
||||
#endif /* defined(__hifi__SharedUtil__) */
|
||||
|
|
|
@ -463,7 +463,7 @@ void VoxelTree::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {
|
|||
// Description: Creates a sphere of voxels in the local system at a given location/radius
|
||||
// To Do: Move this function someplace better?
|
||||
// Complaints: Brad :)
|
||||
void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool solid) {
|
||||
void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer) {
|
||||
// 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);
|
||||
|
@ -504,18 +504,19 @@ void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool
|
|||
// 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) {
|
||||
//printf("radius: %f\n",ri);
|
||||
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);
|
||||
float x = xc+ri*cos(theta)*sin(phi);
|
||||
float y = yc+ri*sin(theta)*sin(phi);
|
||||
float z = zc+ri*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 red = wantColorRandomizer ? randomColorValue(165) : r1+((r2-r1)*gradient);
|
||||
unsigned char green = wantColorRandomizer ? randomColorValue(165) : g1+((g2-g1)*gradient);
|
||||
unsigned char blue = wantColorRandomizer ? randomColorValue(165) : b1+((b2-b1)*gradient);
|
||||
|
||||
unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
|
||||
this->readCodeColorBufferToTree(voxelData);
|
||||
|
@ -523,4 +524,5 @@ void VoxelTree::createSphere(float r,float xc, float yc, float zc, float s, bool
|
|||
}
|
||||
}
|
||||
}
|
||||
this->reaverageVoxelColors(this->rootNode);
|
||||
}
|
|
@ -39,7 +39,7 @@ public:
|
|||
unsigned char * octalCode = NULL);
|
||||
|
||||
void loadVoxelsFile(const char* fileName, bool wantColorRandomizer);
|
||||
void createSphere(float r,float xc, float yc, float zc, float s, bool solid);
|
||||
void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer);
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__VoxelTree__) */
|
||||
|
|
|
@ -47,21 +47,23 @@ const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
|
|||
AgentList agentList('V', VOXEL_LISTEN_PORT);
|
||||
VoxelTree randomTree;
|
||||
|
||||
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
|
||||
void addSphere(VoxelTree * tree,bool random, bool wantColorRandomizer) {
|
||||
float r = random ? randFloatInRange(0.05,0.1) : 0.25;
|
||||
float xc = random ? randFloatInRange(r,(1-r)) : 0.5;
|
||||
float yc = random ? randFloatInRange(r,(1-r)) : 0.5;
|
||||
float zc = random ? randFloatInRange(r,(1-r)) : 0.5;
|
||||
float s = (1.0/256); // size of voxels to make up surface of sphere
|
||||
bool solid = true;
|
||||
|
||||
printf("random sphere\n");
|
||||
printf("radius=%f\n",r);
|
||||
printf("adding sphere:");
|
||||
if (random)
|
||||
printf(" random");
|
||||
printf("\nradius=%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);
|
||||
tree->createSphere(r,xc,yc,zc,s,solid,wantColorRandomizer);
|
||||
}
|
||||
|
||||
void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
||||
|
@ -198,7 +200,8 @@ 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");
|
||||
const char* local = "--local";
|
||||
bool wantLocalDomain = cmdOptionExists(argc, argv,local);
|
||||
if (wantLocalDomain) {
|
||||
printf("Local Domain MODE!\n");
|
||||
int ip = getLocalAddress();
|
||||
|
@ -213,22 +216,32 @@ int main(int argc, const char * argv[])
|
|||
|
||||
// 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");
|
||||
const char* NO_COLOR_RANDOMIZER="--NoColorRandomizer";
|
||||
const char* INPUT_FILE="-i";
|
||||
bool wantColorRandomizer = !cmdOptionExists(argc, argv, NO_COLOR_RANDOMIZER);
|
||||
const char* voxelsFilename = getCmdOption(argc, argv, INPUT_FILE);
|
||||
|
||||
if (voxelsFilename) {
|
||||
randomTree.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
|
||||
}
|
||||
|
||||
if (!cmdOptionExists(argc, argv, "--NoRandomVoxelSheet")) {
|
||||
const char* NO_RANDOM_VOXELS="--NoRandomVoxels";
|
||||
if (!cmdOptionExists(argc, argv, NO_RANDOM_VOXELS)) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
if (cmdOptionExists(argc, argv, "--AddRandomSpheres")) {
|
||||
addRandomSphere(&randomTree);
|
||||
const char* ADD_SPHERE="--AddSphere";
|
||||
const char* ADD_RANDOM_SPHERE="--AddRandomSphere";
|
||||
if (cmdOptionExists(argc, argv, ADD_SPHERE)) {
|
||||
printf("adding sphere\n");
|
||||
addSphere(&randomTree,false,wantColorRandomizer);
|
||||
} else if (cmdOptionExists(argc, argv, ADD_RANDOM_SPHERE)) {
|
||||
printf("adding random sphere\n");
|
||||
addSphere(&randomTree,true,wantColorRandomizer);
|
||||
}
|
||||
printf("past adding spheres...\n");
|
||||
|
||||
pthread_t sendVoxelThread;
|
||||
pthread_create(&sendVoxelThread, NULL, distributeVoxelsToListeners, NULL);
|
||||
|
|
Loading…
Reference in a new issue