mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 16:01:09 +02:00
removed voxel addSphere since it wasn't compiling and was old debug code
This commit is contained in:
parent
ef60aec81e
commit
26adabf130
7 changed files with 48 additions and 236 deletions
|
@ -2392,12 +2392,6 @@ void VoxelSystem::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize,
|
|||
setupNewVoxelsForDrawing();
|
||||
};
|
||||
|
||||
void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bool solid,
|
||||
creationMode mode, bool destructive, bool debug) {
|
||||
_tree->createSphere(r, xc, yc, zc, s, solid, mode, destructive, debug);
|
||||
setupNewVoxelsForDrawing();
|
||||
};
|
||||
|
||||
void VoxelSystem::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destination, bool rebaseToRoot) {
|
||||
_tree->copySubTreeIntoNewTree(startNode, destination->_tree, rebaseToRoot);
|
||||
destination->setupNewVoxelsForDrawing();
|
||||
|
|
|
@ -98,8 +98,6 @@ public:
|
|||
void createVoxel(float x, float y, float z, float s,
|
||||
unsigned char red, unsigned char green, unsigned char blue, bool destructive = false);
|
||||
void createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color, bool destructive = false);
|
||||
void createSphere(float r,float xc, float yc, float zc, float s, bool solid,
|
||||
creationMode mode, bool destructive = false, bool debug = false);
|
||||
|
||||
void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destinationTree, bool rebaseToRoot);
|
||||
void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelTree* destinationTree, bool rebaseToRoot);
|
||||
|
|
|
@ -41,45 +41,6 @@ void addCornersAndAxisLines(VoxelTree* tree) {
|
|||
printf("DONE creating lines...\n");
|
||||
}
|
||||
|
||||
void addSphereScene(VoxelTree * tree) {
|
||||
printf("adding sphere scene...\n");
|
||||
|
||||
// Now some more examples... creating some spheres using the sphere primitive
|
||||
// We want the smallest unit of our spheres to be about 1/16th of a meter tall
|
||||
float sphereVoxelSize = 1.f / (8 * TREE_SCALE);
|
||||
printf("creating spheres... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
|
||||
tree->createSphere(0.030625, 0.5, 0.5, (0.25 - 0.06125), sphereVoxelSize, true, NATURAL);
|
||||
printf("1 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), (0.75 - 0.030625), (0.75 - 0.06125), sphereVoxelSize, true, GRADIENT);
|
||||
printf("2 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), (0.75 - 0.030625), 0.06125, sphereVoxelSize, true, RANDOM);
|
||||
printf("3 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.030625, (0.75 - 0.030625), 0.06125, (0.75 - 0.06125), sphereVoxelSize, true, GRADIENT);
|
||||
printf("4 spheres added... sphereVoxelSize=%f\n",sphereVoxelSize);
|
||||
tree->createSphere(0.06125, 0.125, 0.125, (0.75 - 0.125), sphereVoxelSize, true, GRADIENT);
|
||||
|
||||
/**
|
||||
float radius = 0.0125f;
|
||||
printf("5 spheres added...\n");
|
||||
tree->createSphere(radius, 0.25, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("6 spheres added...\n");
|
||||
tree->createSphere(radius, 0.125, radius * 5.0f, 0.25, sphereVoxelSize, true, RANDOM);
|
||||
printf("7 spheres added...\n");
|
||||
tree->createSphere(radius, 0.075, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("8 spheres added...\n");
|
||||
tree->createSphere(radius, 0.05, radius * 5.0f, 0.25, sphereVoxelSize, true, RANDOM);
|
||||
printf("9 spheres added...\n");
|
||||
tree->createSphere(radius, 0.025, radius * 5.0f, 0.25, sphereVoxelSize, true, GRADIENT);
|
||||
printf("10 spheres added...\n");
|
||||
*/
|
||||
float largeRadius = 0.1875f;
|
||||
tree->createSphere(largeRadius, 0.5, 0.5, 0.5, sphereVoxelSize, true, NATURAL);
|
||||
printf("11 - last large sphere added... largeRadius=%f sphereVoxelSize=%f\n", largeRadius, sphereVoxelSize);
|
||||
|
||||
printf("DONE adding scene of spheres...\n");
|
||||
}
|
||||
|
||||
void addSurfaceScene(VoxelTree * tree) {
|
||||
printf("adding surface scene...\n");
|
||||
float voxelSize = 1.f / (8 * TREE_SCALE);
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <SharedUtil.h>
|
||||
|
||||
void addCornersAndAxisLines(VoxelTree* tree);
|
||||
void addSphereScene(VoxelTree * tree);
|
||||
void addSurfaceScene(VoxelTree * tree);
|
||||
|
||||
|
||||
|
|
|
@ -67,139 +67,6 @@ void VoxelTree::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, r
|
|||
}
|
||||
}
|
||||
|
||||
void VoxelTree::createSphere(float radius, float xc, float yc, float zc, float voxelSize,
|
||||
bool solid, creationMode mode, bool destructive, bool debug) {
|
||||
|
||||
bool wantColorRandomizer = (mode == RANDOM);
|
||||
bool wantNaturalSurface = (mode == NATURAL);
|
||||
bool wantNaturalColor = (mode == NATURAL);
|
||||
|
||||
// About the color of the sphere... we're going to make this sphere be a mixture of two colors
|
||||
// in NATURAL mode, those colors will be green dominant and blue dominant. In GRADIENT mode we
|
||||
// will randomly pick which color family red, green, or blue to be dominant. In RANDOM mode we
|
||||
// ignore these dominant colors and make every voxel a completely random color.
|
||||
unsigned char r1, g1, b1, r2, g2, b2;
|
||||
|
||||
if (wantNaturalColor) {
|
||||
r1 = r2 = b2 = g1 = 0;
|
||||
b1 = g2 = 255;
|
||||
} else if (!wantColorRandomizer) {
|
||||
unsigned char dominantColor1 = randIntInRange(1, 3); //1=r, 2=g, 3=b dominant
|
||||
unsigned char dominantColor2 = randIntInRange(1, 3);
|
||||
|
||||
if (dominantColor1 == dominantColor2) {
|
||||
dominantColor2 = dominantColor1 + 1 % 3;
|
||||
}
|
||||
|
||||
r1 = (dominantColor1 == 1) ? randIntInRange(200, 255) : randIntInRange(40, 100);
|
||||
g1 = (dominantColor1 == 2) ? randIntInRange(200, 255) : randIntInRange(40, 100);
|
||||
b1 = (dominantColor1 == 3) ? randIntInRange(200, 255) : randIntInRange(40, 100);
|
||||
r2 = (dominantColor2 == 1) ? randIntInRange(200, 255) : randIntInRange(40, 100);
|
||||
g2 = (dominantColor2 == 2) ? randIntInRange(200, 255) : randIntInRange(40, 100);
|
||||
b2 = (dominantColor2 == 3) ? randIntInRange(200, 255) : randIntInRange(40, 100);
|
||||
}
|
||||
|
||||
// We initialize our rgb to be either "grey" in case of randomized surface, or
|
||||
// the average of the gradient, in the case of the gradient sphere.
|
||||
unsigned char red = wantColorRandomizer ? 128 : (r1 + r2) / 2; // average of the colors
|
||||
unsigned char green = wantColorRandomizer ? 128 : (g1 + g2) / 2;
|
||||
unsigned char blue = wantColorRandomizer ? 128 : (b1 + b2) / 2;
|
||||
|
||||
// I want to do something smart like make these inside circles with bigger voxels, but this doesn't seem to work.
|
||||
float thisVoxelSize = voxelSize; // radius / 2.0f;
|
||||
float thisRadius = 0.0;
|
||||
if (!solid) {
|
||||
thisRadius = radius; // just the outer surface
|
||||
thisVoxelSize = voxelSize;
|
||||
}
|
||||
|
||||
// If you also iterate form the interior of the sphere to the radius, making
|
||||
// larger and larger spheres you'd end up with a solid sphere. And lots of voxels!
|
||||
bool lastLayer = false;
|
||||
while (!lastLayer) {
|
||||
lastLayer = (thisRadius + (voxelSize * 2.0) >= radius);
|
||||
|
||||
// We want to make sure that as we "sweep" through our angles we use a delta angle that voxelSize
|
||||
// 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 = (thisVoxelSize / thisRadius);
|
||||
|
||||
if (debug) {
|
||||
int percentComplete = 100 * (thisRadius/radius);
|
||||
qDebug("percentComplete=%d\n",percentComplete);
|
||||
}
|
||||
|
||||
for (float theta=0.0; theta <= 2 * M_PI; theta += angleDelta) {
|
||||
for (float phi=0.0; phi <= M_PI; phi += angleDelta) {
|
||||
bool naturalSurfaceRendered = false;
|
||||
float x = xc + thisRadius * cos(theta) * sin(phi);
|
||||
float y = yc + thisRadius * sin(theta) * sin(phi);
|
||||
float z = zc + thisRadius * cos(phi);
|
||||
|
||||
// if we're on the outer radius, then we do a couple of things differently.
|
||||
// 1) If we're in NATURAL mode we will actually draw voxels from our surface outward (from the surface) up
|
||||
// some random height. This will give our sphere some contours.
|
||||
// 2) In all modes, we will use our "outer" color to draw the voxels. Otherwise we will use the average color
|
||||
if (lastLayer) {
|
||||
if (false && debug) {
|
||||
qDebug("adding candy shell: theta=%f phi=%f thisRadius=%f radius=%f\n",
|
||||
theta, phi, thisRadius,radius);
|
||||
}
|
||||
switch (mode) {
|
||||
case RANDOM: {
|
||||
red = randomColorValue(165);
|
||||
green = randomColorValue(165);
|
||||
blue = randomColorValue(165);
|
||||
} break;
|
||||
case GRADIENT: {
|
||||
float gradient = (phi / M_PI);
|
||||
red = r1 + ((r2 - r1) * gradient);
|
||||
green = g1 + ((g2 - g1) * gradient);
|
||||
blue = b1 + ((b2 - b1) * gradient);
|
||||
} break;
|
||||
case NATURAL: {
|
||||
glm::vec3 position = glm::vec3(theta,phi,radius);
|
||||
float perlin = glm::perlin(position) + .25f * glm::perlin(position * 4.f)
|
||||
+ .125f * glm::perlin(position * 16.f);
|
||||
float gradient = (1.0f + perlin)/ 2.0f;
|
||||
red = (unsigned char)std::min(255, std::max(0, (int)(r1 + ((r2 - r1) * gradient))));
|
||||
green = (unsigned char)std::min(255, std::max(0, (int)(g1 + ((g2 - g1) * gradient))));
|
||||
blue = (unsigned char)std::min(255, std::max(0, (int)(b1 + ((b2 - b1) * gradient))));
|
||||
if (debug) {
|
||||
qDebug("perlin=%f gradient=%f color=(%d,%d,%d)\n",perlin, gradient, red, green, blue);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
if (wantNaturalSurface) {
|
||||
// for natural surfaces, we will render up to 16 voxel's above the surface of the sphere
|
||||
glm::vec3 position = glm::vec3(theta,phi,radius);
|
||||
float perlin = glm::perlin(position) + .25f * glm::perlin(position * 4.f)
|
||||
+ .125f * glm::perlin(position * 16.f);
|
||||
float gradient = (1.0f + perlin)/ 2.0f;
|
||||
|
||||
int height = (4 * gradient)+1; // make it at least 4 thick, so we get some averaging
|
||||
float subVoxelScale = thisVoxelSize;
|
||||
for (int i = 0; i < height; i++) {
|
||||
x = xc + (thisRadius + i * subVoxelScale) * cos(theta) * sin(phi);
|
||||
y = yc + (thisRadius + i * subVoxelScale) * sin(theta) * sin(phi);
|
||||
z = zc + (thisRadius + i * subVoxelScale) * cos(phi);
|
||||
this->createVoxel(x, y, z, subVoxelScale, red, green, blue, destructive);
|
||||
}
|
||||
naturalSurfaceRendered = true;
|
||||
}
|
||||
}
|
||||
if (!naturalSurfaceRendered) {
|
||||
this->createVoxel(x, y, z, thisVoxelSize, red, green, blue, destructive);
|
||||
}
|
||||
}
|
||||
}
|
||||
thisRadius += thisVoxelSize;
|
||||
thisVoxelSize = std::max(voxelSize, thisVoxelSize / 2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class NodeChunkArgs {
|
||||
public:
|
||||
VoxelTree* thisVoxelTree;
|
||||
|
|
|
@ -39,8 +39,6 @@ public:
|
|||
unsigned char red, unsigned char green, unsigned char blue, bool destructive = false);
|
||||
|
||||
void createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color, bool destructive = false);
|
||||
void createSphere(float radius, float xc, float yc, float zc, float voxelSize,
|
||||
bool solid, creationMode mode, bool destructive = false, bool debug = false);
|
||||
|
||||
void nudgeSubTree(VoxelTreeElement* elementToNudge, const glm::vec3& nudgeAmount, VoxelEditPacketSender& voxelEditSender);
|
||||
|
||||
|
|
|
@ -343,11 +343,6 @@ int main(int argc, const char * argv[])
|
|||
addCornersAndAxisLines(&myTree);
|
||||
}
|
||||
|
||||
const char* ADD_SPHERE_SCENE = "--addSphereScene";
|
||||
if (cmdOptionExists(argc, argv, ADD_SPHERE_SCENE)) {
|
||||
addSphereScene(&myTree);
|
||||
}
|
||||
|
||||
const char* ADD_SURFACE_SCENE = "--addSurfaceScene";
|
||||
if (cmdOptionExists(argc, argv, ADD_SURFACE_SCENE)) {
|
||||
addSurfaceScene(&myTree);
|
||||
|
|
Loading…
Reference in a new issue