mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +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
|
// 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.
|
// being added. This is a concept mostly only understood by VoxelSystem.
|
||||||
// Complaints: Brad :)
|
// 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
|
// reset the verticesEndPointer so we're writing to the beginning of the array
|
||||||
verticesEndPointer = verticesArray;
|
verticesEndPointer = verticesArray;
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
void setVoxelsRendered(int v) {voxelsRendered = v;};
|
void setVoxelsRendered(int v) {voxelsRendered = v;};
|
||||||
int getVoxelsRendered() {return voxelsRendered;};
|
int getVoxelsRendered() {return voxelsRendered;};
|
||||||
void loadVoxelsFile(const char* fileName,bool wantColorRandomizer);
|
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:
|
private:
|
||||||
int voxelsRendered;
|
int voxelsRendered;
|
||||||
VoxelTree *tree;
|
VoxelTree *tree;
|
||||||
|
|
|
@ -81,6 +81,8 @@ int WIDTH = 1200;
|
||||||
int HEIGHT = 800;
|
int HEIGHT = 800;
|
||||||
int fullscreen = 0;
|
int fullscreen = 0;
|
||||||
|
|
||||||
|
bool wantColorRandomizer = true; // for addSphere and load file
|
||||||
|
|
||||||
Oscilloscope audioScope(256,200,true);
|
Oscilloscope audioScope(256,200,true);
|
||||||
|
|
||||||
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
|
#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 r = randFloatInRange(0.05,0.1);
|
||||||
float xc = randFloatInRange(r,(1-r));
|
float xc = randFloatInRange(r,(1-r));
|
||||||
|
@ -640,7 +642,7 @@ void addRandomSphere()
|
||||||
printf("yc=%f\n",yc);
|
printf("yc=%f\n",yc);
|
||||||
printf("zc=%f\n",zc);
|
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
|
// press the . key to get a new random sphere of voxels added
|
||||||
if (k == '.')
|
if (k == '.')
|
||||||
{
|
{
|
||||||
addRandomSphere();
|
addRandomSphere(wantColorRandomizer);
|
||||||
//testPointToVoxel();
|
//testPointToVoxel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -899,7 +901,7 @@ int main(int argc, const char * argv[])
|
||||||
{
|
{
|
||||||
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
||||||
if (domainIP) {
|
if (domainIP) {
|
||||||
sprintf(DOMAIN_IP,domainIP);
|
strcpy(DOMAIN_IP,domainIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Local Domain testing with the --local command line
|
// Handle Local Domain testing with the --local command line
|
||||||
|
@ -953,7 +955,6 @@ int main(int argc, const char * argv[])
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
bool wantColorRandomizer = true;
|
|
||||||
// Check to see if the user passed in a command line option for randomizing colors
|
// Check to see if the user passed in a command line option for randomizing colors
|
||||||
if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) {
|
if (cmdOptionExists(argc, argv, "--NoColorRandomizer")) {
|
||||||
wantColorRandomizer = false;
|
wantColorRandomizer = false;
|
||||||
|
|
|
@ -93,7 +93,7 @@ void switchToResourcesIfRequired() {
|
||||||
// then you're using the "-i" flag to set the input file name.
|
// then you're using the "-i" flag to set the input file name.
|
||||||
// Usage: char * inputFilename = getCmdOption(argc, argv, "-i");
|
// Usage: char * inputFilename = getCmdOption(argc, argv, "-i");
|
||||||
// Complaints: Brad :)
|
// 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
|
// 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 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");
|
// Usage: bool wantDump = cmdOptionExists(argc, argv, "-d");
|
||||||
// Complaints: Brad :)
|
// Complaints: Brad :)
|
||||||
|
|
||||||
bool cmdOptionExists(int argc, const char * argv[],char* option) {
|
bool cmdOptionExists(int argc, const char * argv[],const char* option) {
|
||||||
// check each arg
|
// 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 the arg matches the desired option
|
||||||
|
|
|
@ -34,8 +34,8 @@ bool oneAtBit(unsigned char byte, int bitIndex);
|
||||||
|
|
||||||
void switchToResourcesIfRequired();
|
void switchToResourcesIfRequired();
|
||||||
|
|
||||||
const char* getCmdOption(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[],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 );
|
unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, unsigned char g, unsigned char b );
|
||||||
|
|
||||||
#endif /* defined(__hifi__SharedUtil__) */
|
#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
|
// Description: Creates a sphere of voxels in the local system at a given location/radius
|
||||||
// To Do: Move this function someplace better?
|
// To Do: Move this function someplace better?
|
||||||
// Complaints: Brad :)
|
// 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
|
// 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
|
// between two RGB colors. We will do the gradient along the phi spectrum
|
||||||
unsigned char r1 = randomColorValue(165);
|
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
|
// 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!
|
// larger and larger sphere's you'd end up with a solid sphere. And lots of voxels!
|
||||||
for (; ri <= r; ri+=s) {
|
for (; ri <= r; ri+=s) {
|
||||||
|
//printf("radius: %f\n",ri);
|
||||||
for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) {
|
for (float theta=0.0; theta <= 2*M_PI; theta += angleDelta) {
|
||||||
for (float phi=0.0; phi <= M_PI; phi += angleDelta) {
|
for (float phi=0.0; phi <= M_PI; phi += angleDelta) {
|
||||||
t++; // total voxels
|
t++; // total voxels
|
||||||
float x = xc+r*cos(theta)*sin(phi);
|
float x = xc+ri*cos(theta)*sin(phi);
|
||||||
float y = yc+r*sin(theta)*sin(phi);
|
float y = yc+ri*sin(theta)*sin(phi);
|
||||||
float z = zc+r*cos(phi);
|
float z = zc+ri*cos(phi);
|
||||||
|
|
||||||
// gradient color data
|
// gradient color data
|
||||||
float gradient = (phi/M_PI);
|
float gradient = (phi/M_PI);
|
||||||
unsigned char red = r1+((r2-r1)*gradient);
|
unsigned char red = wantColorRandomizer ? randomColorValue(165) : r1+((r2-r1)*gradient);
|
||||||
unsigned char green = g1+((g2-g1)*gradient);
|
unsigned char green = wantColorRandomizer ? randomColorValue(165) : g1+((g2-g1)*gradient);
|
||||||
unsigned char blue = b1+((b2-b1)*gradient);
|
unsigned char blue = wantColorRandomizer ? randomColorValue(165) : b1+((b2-b1)*gradient);
|
||||||
|
|
||||||
unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
|
unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
|
||||||
this->readCodeColorBufferToTree(voxelData);
|
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);
|
unsigned char * octalCode = NULL);
|
||||||
|
|
||||||
void loadVoxelsFile(const char* fileName, bool wantColorRandomizer);
|
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__) */
|
#endif /* defined(__hifi__VoxelTree__) */
|
||||||
|
|
|
@ -47,21 +47,23 @@ const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
|
||||||
AgentList agentList('V', VOXEL_LISTEN_PORT);
|
AgentList agentList('V', VOXEL_LISTEN_PORT);
|
||||||
VoxelTree randomTree;
|
VoxelTree randomTree;
|
||||||
|
|
||||||
void addRandomSphere(VoxelTree * tree) {
|
void addSphere(VoxelTree * tree,bool random, bool wantColorRandomizer) {
|
||||||
float r = randFloatInRange(0.05,0.1);
|
float r = random ? randFloatInRange(0.05,0.1) : 0.25;
|
||||||
float xc = randFloatInRange(r,(1-r));
|
float xc = random ? randFloatInRange(r,(1-r)) : 0.5;
|
||||||
float yc = randFloatInRange(r,(1-r));
|
float yc = random ? randFloatInRange(r,(1-r)) : 0.5;
|
||||||
float zc = randFloatInRange(r,(1-r));
|
float zc = random ? randFloatInRange(r,(1-r)) : 0.5;
|
||||||
float s = 0.001; // size of voxels to make up surface of sphere
|
float s = (1.0/256); // size of voxels to make up surface of sphere
|
||||||
bool solid = true;
|
bool solid = true;
|
||||||
|
|
||||||
printf("random sphere\n");
|
printf("adding sphere:");
|
||||||
printf("radius=%f\n",r);
|
if (random)
|
||||||
|
printf(" random");
|
||||||
|
printf("\nradius=%f\n",r);
|
||||||
printf("xc=%f\n",xc);
|
printf("xc=%f\n",xc);
|
||||||
printf("yc=%f\n",yc);
|
printf("yc=%f\n",yc);
|
||||||
printf("zc=%f\n",zc);
|
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) {
|
void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
|
||||||
|
@ -198,7 +200,8 @@ int main(int argc, const char * argv[])
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
|
|
||||||
// Handle Local Domain testing with the --local command line
|
// 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) {
|
if (wantLocalDomain) {
|
||||||
printf("Local Domain MODE!\n");
|
printf("Local Domain MODE!\n");
|
||||||
int ip = getLocalAddress();
|
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
|
// Check to see if the user passed in a command line option for loading a local
|
||||||
// Voxel File. If so, load it now.
|
// Voxel File. If so, load it now.
|
||||||
bool wantColorRandomizer = !cmdOptionExists(argc, argv, "--NoColorRandomizer");
|
const char* NO_COLOR_RANDOMIZER="--NoColorRandomizer";
|
||||||
const char* voxelsFilename = getCmdOption(argc, argv, "-i");
|
const char* INPUT_FILE="-i";
|
||||||
|
bool wantColorRandomizer = !cmdOptionExists(argc, argv, NO_COLOR_RANDOMIZER);
|
||||||
|
const char* voxelsFilename = getCmdOption(argc, argv, INPUT_FILE);
|
||||||
|
|
||||||
if (voxelsFilename) {
|
if (voxelsFilename) {
|
||||||
randomTree.loadVoxelsFile(voxelsFilename,wantColorRandomizer);
|
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
|
// 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
|
// octal codes to the tree nodes that it is creating
|
||||||
randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode);
|
randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmdOptionExists(argc, argv, "--AddRandomSpheres")) {
|
const char* ADD_SPHERE="--AddSphere";
|
||||||
addRandomSphere(&randomTree);
|
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_t sendVoxelThread;
|
||||||
pthread_create(&sendVoxelThread, NULL, distributeVoxelsToListeners, NULL);
|
pthread_create(&sendVoxelThread, NULL, distributeVoxelsToListeners, NULL);
|
||||||
|
|
Loading…
Reference in a new issue