From bbba6364720cb941a649de25ae867ded2bc9a3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Thu, 22 Dec 2011 12:28:16 +0100 Subject: [PATCH] Affichage des splitBox. --- hash.hh | 2 +- lod.cpp | 39 ++++++++++++++------------ lod.hh | 4 +-- main.cpp | 1 + rules/chose.cpp | 73 ++++++++++++++++--------------------------------- rules/chose.hh | 5 +--- view.cpp | 9 +----- 7 files changed, 50 insertions(+), 83 deletions(-) diff --git a/hash.hh b/hash.hh index 59e880e..036200a 100644 --- a/hash.hh +++ b/hash.hh @@ -6,7 +6,7 @@ int random_seed(); unsigned int hash2(unsigned int a, unsigned int b); -int hashInRange(int seed, int n, int a, int b); // Renvoie le n-ième nombre aléatoire dérivé de seed entre a et b. +int hashInRange(int seed, int n, int a, int b); // Renvoie le n-ième nombre aléatoire dérivé de seed entre a et b (a inclus, b non inclus). bool proba(int seed, int n, unsigned int a, unsigned int b); // Renvoie vrai avec `a` fois sur `b`. #endif diff --git a/lod.cpp b/lod.cpp index 7af7ace..c6e632e 100644 --- a/lod.cpp +++ b/lod.cpp @@ -32,7 +32,8 @@ void Lod::setCamera(Vertex newCamera) { Chose* c; int pos = NegateOdd(camera[i>>1], i); while((c = split[2*i+1].popIfLessThan(pos))) { - if(c->inCounter == 5) { + std::cout << "soi " << (int)(c) << std::endl; + if(c->lod.inCounter == 5) { for(int j = 0; j < 6; j++) { if(i == j) continue; split[2*j].remove(c); @@ -40,8 +41,8 @@ void Lod::setCamera(Vertex newCamera) { doSplit(c); } else { - c->inCounter++; - split[2*i].insert(c->splitCube[i], c); + c->lod.inCounter++; + split[2*i].insert(c->lod.splitBox[i], c); } } } @@ -51,40 +52,42 @@ void Lod::setCamera(Vertex newCamera) { Chose* c; int pos = NegateEven(camera[i>>1], i); while((c = split[2*i].popIfLessThan(pos))) { - c->inCounter--; - split[2*i+1].insert(c->splitCube[i], c); + c->lod.inCounter--; + split[2*i+1].insert(c->lod.splitBox[i], c); } } } void Lod::doSplit(Chose* c) { // TODO - c->split(); - std::vector::iterator it; - for (it = c->children.begin(); it != c->children.end(); ++it) { - (*it)->triangulation(); - (*it)->updateAABB(); - addSplitCube((*it)); + if (c->split()) { + std::vector::iterator it; + for (it = c->children.begin(); it != c->children.end(); ++it) { + (*it)->triangulation(); + (*it)->updateAABB(); + (*it)->drawAABB(); + addSplitCube((*it)); + } } } void Lod::addMergeCube(Chose* chose) { for(int i = 0; i < 5; i++) - merge[i].insert(NegateEven(chose->lod.mergeCube[i], i), chose); + merge[i].insert(NegateEven(chose->lod.mergeBox[i], i), chose); } void Lod::addSplitCube(Chose* chose) { - chose->inCounter = 0; + chose->lod.inCounter = 0; for(int i = 0; i < 6; i++) { - if(NegateEven(chose->lod.splitCube[i] - camera[i>>1], i) >= 0) { - chose->inCounter++; - split[2*i].insert(NegateEven(chose->lod.splitCube[i],i), chose); + if(NegateEven(chose->lod.splitBox[i] - camera[i>>1], i) >= 0) { + chose->lod.inCounter++; + split[2*i].insert(NegateEven(chose->lod.splitBox[i],i), chose); } else { - split[2*i+1].insert(NegateOdd(chose->lod.splitCube[i],i), chose); + split[2*i+1].insert(NegateOdd(chose->lod.splitBox[i],i), chose); } } // TODO : si chose->inCounter == 6, il faut le split immédiatement. - if (chose->inCounter == 6) { + if (chose->lod.inCounter == 6) { for(int i = 0; i < 6; i++) { split[2*i].remove(chose); } diff --git a/lod.hh b/lod.hh index 2a47125..6a2416c 100644 --- a/lod.hh +++ b/lod.hh @@ -25,8 +25,8 @@ public : struct LodNode { int heaps[18]; float aabb[6]; - float splitCube[12]; - float mergeCube[6]; + float splitBox[12]; + float mergeBox[6]; int inCounter; bool firstBBPoint; }; diff --git a/main.cpp b/main.cpp index 7fdae39..e594ef9 100644 --- a/main.cpp +++ b/main.cpp @@ -30,6 +30,7 @@ int main() { Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw); c->triangulation(); c->updateAABB(); + c->drawAABB(); // c->split(); // recursiveSubdivide(c); diff --git a/rules/chose.cpp b/rules/chose.cpp index 9d40e02..6490c6e 100644 --- a/rules/chose.cpp +++ b/rules/chose.cpp @@ -68,59 +68,32 @@ void Chose::addBBPoint(Vertex v) { void Chose::updateAABB() { lod.firstBBPoint = true; getBoundingBoxPoints(); - for (int i = 0; i < 6; i++) { - // TODO - lod.splitCube[i] = lod.aabb[i]; - lod.mergeCube[i] = lod.aabb[i]; + for (int i = 0; i < 3; i++) { + float splitFactor = 2; + float mergeFactor = 3; + float center = (lod.aabb[2*i] + lod.aabb[2*i+1]) / 2; + lod.splitBox[2*i] = (lod.aabb[2*i] - center) * splitFactor + center; + lod.splitBox[2*i+1] = (lod.aabb[2*i+1] - center) * splitFactor + center; + lod.mergeBox[2*i] = (lod.aabb[2*i] - center) * mergeFactor + center; + lod.mergeBox[2*i+1] = (lod.aabb[2*i+1] - center) * mergeFactor + center; } } -void Chose::displayAABB() { - updateAABB(); - if (children.size() > 0) { - std::vector::iterator it; - for (it = children.begin(); it != children.end(); ++it) { - (*it)->displayAABB(); - } - } else { - // Affiche la AABB. - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[0],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[2],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[0],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[3],lod.aabb[4]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[4]); - glVertex3d(lod.aabb[0],lod.aabb[3],lod.aabb[4]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[2],lod.aabb[5]); - glVertex3d(lod.aabb[1],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[3],lod.aabb[4]); - glVertex3d(lod.aabb[0],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[2],lod.aabb[5]); - glVertex3d(lod.aabb[1],lod.aabb[2],lod.aabb[5]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[1],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[2],lod.aabb[5]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[0],lod.aabb[3],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[5]); - glVertex3d(lod.aabb[1],lod.aabb[2],lod.aabb[4]); - glVertex3d(lod.aabb[1],lod.aabb[3],lod.aabb[4]); - } +// DEBUG +void Chose::drawAABB() { + addOcto( + Vertex(lod.splitBox[0], lod.splitBox[2], lod.splitBox[4]), + Vertex(lod.splitBox[1], lod.splitBox[2], lod.splitBox[4]), + Vertex(lod.splitBox[1], lod.splitBox[3], lod.splitBox[4]), + Vertex(lod.splitBox[0], lod.splitBox[3], lod.splitBox[4]), + Vertex(lod.splitBox[0], lod.splitBox[2], lod.splitBox[5]), + Vertex(lod.splitBox[1], lod.splitBox[2], lod.splitBox[5]), + Vertex(lod.splitBox[1], lod.splitBox[3], lod.splitBox[5]), + Vertex(lod.splitBox[0], lod.splitBox[3], lod.splitBox[5]), + hashInRange(seed, 42, 0, 256), + hashInRange(seed, 43, 0, 256), + hashInRange(seed, 44, 0, 256) + ); } unsigned int Chose::initialSeed = 779313522;//random_seed(); diff --git a/rules/chose.hh b/rules/chose.hh index 46188de..5ddc4b0 100644 --- a/rules/chose.hh +++ b/rules/chose.hh @@ -11,14 +11,11 @@ class Chose { std::vector children; std::vector triangles; LodNode lod; - int inCounter; - int splitCube[6]; - int mergeCube[6]; Vertex lctr; // Local center; public : void display(); - void displayAABB(); + void drawAABB(); // DEBUG virtual bool split() = 0; virtual bool merge(); virtual void triangulation() = 0; diff --git a/view.cpp b/view.cpp index 75566ba..2a2ba65 100644 --- a/view.cpp +++ b/view.cpp @@ -3,7 +3,7 @@ // camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6) View::View(Chose* root) : root(root), - camera(Camera(Vertex(10,10,-100),45,90,1000,0.6)), + camera(Camera(Vertex(-15000,-15000,3000),45,90,1000,0.6)), lod(camera.cameraCenter, root) { initWindow(); mainLoop(); @@ -97,13 +97,6 @@ void View::renderScene(int lastTime, int currentTime) { root->display(); glEnd(); - // DEBUG : display AABB - // glDisable(GL_LIGHTING); - // glDisable(GL_TEXTURE_2D); - // glBegin(GL_TRIANGLES); - // root->displayAABB(); - // glEnd(); - glFlush(); SDL_GL_SwapBuffers(); }