From a4f2dc283dac65b857d708f7d2df984029fc8581 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 3 May 2013 09:58:52 -0700 Subject: [PATCH] various changes to help debug render pipeline - fixing some cases where TREE_SCALE was not using constant in prep for making TREE_SCALE larger - added createLine() to VoxelTree - added axis lines made of voxels to scene - added corner points made of voxels to scene --- interface/src/VoxelSystem.cpp | 2 +- interface/src/main.cpp | 2 +- libraries/voxels/src/VoxelNode.h | 1 + libraries/voxels/src/VoxelTree.cpp | 17 +++++++++++- libraries/voxels/src/VoxelTree.h | 2 ++ voxel-server/src/main.cpp | 44 ++++++++++++++++++++---------- 6 files changed, 50 insertions(+), 18 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index b8f8485a67..989ab8ff3d 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -433,7 +433,7 @@ void VoxelSystem::render() { // draw the number of voxels we have glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesID); - glScalef(10, 10, 10); + glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); glDrawElements(GL_TRIANGLES, 36 * _voxelsInArrays, GL_UNSIGNED_INT, 0); // deactivate vertex and color arrays after drawing diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 6d3adcdbba..f3b82cc663 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1696,7 +1696,7 @@ int main(int argc, const char * argv[]) // field of view and near and far clip to make it interesting. //viewFrustumOffsetCamera.setFieldOfView(90.0); viewFrustumOffsetCamera.setNearClip(0.1); - viewFrustumOffsetCamera.setFarClip(500.0); + viewFrustumOffsetCamera.setFarClip(500.0*TREE_SCALE); printLog( "Created Display Window.\n" ); diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index 26edb87e79..90ee3bf730 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -15,6 +15,7 @@ typedef unsigned char colorPart; typedef unsigned char nodeColor[4]; +typedef unsigned char rgbColor[3]; class VoxelNode { private: diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 72327c2346..21118c929e 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -25,7 +25,7 @@ using voxels_lib::printLog; int boundaryDistanceForRenderLevel(unsigned int renderLevel) { - float voxelSizeScale = 5000.0; + float voxelSizeScale = 500.0*TREE_SCALE; return voxelSizeScale / powf(2, renderLevel); } @@ -444,6 +444,21 @@ void VoxelTree::createVoxel(float x, float y, float z, float s, unsigned char re delete voxelData; } + +void VoxelTree::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color) { + glm::vec3 distance = point2 - point1; + glm::vec3 items = distance / unitSize; + int maxItems = std::max(items.x, std::max(items.y, items.z)); + glm::vec3 increment = distance * (1.0f/ maxItems); + glm::vec3 pointAt = point1; + for (int i = 0; i <= maxItems; i++ ) { + pointAt += increment; + unsigned char* voxelData = pointToVoxel(pointAt.x,pointAt.y,pointAt.z,unitSize,color[0],color[1],color[2]); + readCodeColorBufferToTree(voxelData); + delete voxelData; + } +} + 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 diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 2ccb704964..309766bcd2 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -47,6 +47,8 @@ public: void loadVoxelsFile(const char* fileName, bool wantColorRandomizer); void createSphere(float r,float xc, float yc, float zc, float s, bool solid, bool wantColorRandomizer); void createVoxel(float x, float y, float z, float s, unsigned char red, unsigned char green, unsigned char blue); + + void createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color); void recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData=NULL); diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 9f5fc75ccb..17c4915988 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -75,10 +75,36 @@ bool countVoxelsOperation(VoxelNode* node, void* extraData) { } void addSphereScene(VoxelTree * tree, bool wantColorRandomizer) { - printf("adding scene of spheres...\n"); + printf("adding scene...\n"); + + float voxelSize = 1.f/32; + printf("creating corner points...\n"); + tree->createVoxel(0 , 0 , 0 , voxelSize, 255, 255 ,255); + tree->createVoxel(1.0 - voxelSize, 0 , 0 , voxelSize, 255, 0 ,0 ); + tree->createVoxel(0 , 1.0 - voxelSize, 0 , voxelSize, 0 , 255 ,0 ); + tree->createVoxel(0 , 0 , 1.0 - voxelSize, voxelSize, 0 , 0 ,255); + + + tree->createVoxel(1.0 - voxelSize, 0 , 1.0 - voxelSize, voxelSize, 255, 0 ,255); + tree->createVoxel(0 , 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 0 , 255 ,255); + tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 0 , voxelSize, 255, 255 ,0 ); + tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 255, 255 ,255); + printf("DONE creating corner points...\n"); + + printf("creating voxel lines...\n"); + float lineVoxelSize = 0.99f/256; + rgbColor red = {255,0,0}; + rgbColor green = {0,255,0}; + rgbColor blue = {0,0,255}; + + tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 0, 1), lineVoxelSize, blue); + tree->createLine(glm::vec3(0, 0, 0), glm::vec3(1, 0, 0), lineVoxelSize, red); + tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 1, 0), lineVoxelSize, green); + + printf("DONE creating lines...\n"); int sphereBaseSize = 512; - + printf("creating spheres...\n"); tree->createSphere(0.25, 0.5, 0.5, 0.5, (1.0 / sphereBaseSize), true, wantColorRandomizer); printf("one sphere added...\n"); tree->createSphere(0.030625, 0.5, 0.5, (0.25-0.06125), (1.0 / (sphereBaseSize * 2)), true, true); @@ -106,19 +132,7 @@ void addSphereScene(VoxelTree * tree, bool wantColorRandomizer) { tree->createSphere(radius, 0.025, radius * 5.0f, 0.25, (1.0 / 4096), true, true); printf("11 spheres added...\n"); - float voxelSize = 0.99f/8; - printf("creating corner points...\n"); - tree->createVoxel(0 , 0 , 0 , voxelSize, 255, 255 ,255); - tree->createVoxel(1.0 - voxelSize, 0 , 0 , voxelSize, 255, 0 ,0 ); - tree->createVoxel(0 , 1.0 - voxelSize, 0 , voxelSize, 0 , 255 ,0 ); - tree->createVoxel(0 , 0 , 1.0 - voxelSize, voxelSize, 0 , 0 ,255); - - - tree->createVoxel(1.0 - voxelSize, 0 , 1.0 - voxelSize, voxelSize, 255, 0 ,255); - tree->createVoxel(0 , 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 0 , 255 ,255); - tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 255, 255 ,255); - tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 0 , voxelSize, 255, 255 ,0 ); - printf("DONE creating corner points...\n"); + printf("DONE creating spheres...\n"); _nodeCount=0; tree->recurseTreeWithOperation(countVoxelsOperation);