diff --git a/.gitignore b/.gitignore index 31d86e7..4776918 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ city all.cpp -all_includes.hh.d all_includes.hh.gch -city-builder diff --git a/Makefile b/Makefile index 4f88943..7e659cd 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,10 @@ CXX=g++ # -ansi -pedantic -Wconversion CCWARN=-Wall -Wextra -Werror # -flto (nécessite GCC 4.5) -m32 ou -m64 -CFLAGS=-O0 -I. $(CCWARN) +CFLAGS=-O0 -I. $(CCWARN) -g -rdynamic SOURCES = $(shell echo *.cpp rules/*.cpp rules/*/*.cpp) +HEADERS = $(shell echo *.hh rules/*.hh rules/*/*.hh) LIBS = -lm -lGL -lGLU -lSDL -lGLEW EXECUTABLE = city @@ -14,7 +15,7 @@ all: $(EXECUTABLE) .PHONY: clean clean: - rm -f $(EXECUTABLE) all_includes.hh.d all_includes.hh.gch all.cpp + rm -f $(EXECUTABLE) all_includes.hh.gch all.cpp $(EXECUTABLE): $(SOURCES) all_includes.hh.gch Makefile @echo "#ifndef _ALL_CPP_"> all.cpp @@ -24,7 +25,5 @@ $(EXECUTABLE): $(SOURCES) all_includes.hh.gch Makefile $(CXX) $(LIBS) $(CFLAGS) all.cpp -o $@ @rm all.cpp --include all_includes.hh.d -all_includes.hh.d: -all_includes.hh.gch: all_includes.hh Makefile - $(CXX) $(CFLAGS) -MMD -MF all_includes.hh.d all_includes.hh -o all_includes.hh.gch +all_includes.hh.gch: $(HEADERS) Makefile + $(CXX) $(CFLAGS) all_includes.hh -o all_includes.hh.gch diff --git a/all_includes.hh b/all_includes.hh index 391f8f5..cde44af 100644 --- a/all_includes.hh +++ b/all_includes.hh @@ -24,9 +24,11 @@ class Chose; #include "quad.hh" #include "hash.hh" -#include "view.hh" -// LOD must be included before chose.hh +// heap.hh must be included before lod.hh +#include "heap.hh" +// lod.hh must be included before chose.hh and view.hh #include "lod.hh" +#include "view.hh" #include "rules/chose.hh" diff --git a/heap.cpp b/heap.cpp new file mode 100644 index 0000000..7b57cd2 --- /dev/null +++ b/heap.cpp @@ -0,0 +1,172 @@ +Heap::Heap() + : buckets(new HeapNode*[1]), lastAllocatedBucket(-1), + bucketArraySize(1), lastNode(-1) { +} + +void Heap::setId(int id) { this->id = id; } + +void Heap::insert(int key, Chose* value) { + // std::cout << "INSERT " << (int)(value) << " into " << id << std::endl; + int _d_node = value->lod.heaps[id]; + if (_d_node <= lastNode && _d_node >= 0 && + buckets[getBucket(_d_node)][getIndex(_d_node)].value == value) { + std::cout << "ERROR ! Trying to insert " << (int)(value) + << " but it is already here " + << (int)(buckets[getBucket(_d_node)][getIndex(_d_node)].value) + << std::endl; + } + // std::cout << "ENTER insert" << std::endl; + ++lastNode; + if (getBucket(lastNode) > lastAllocatedBucket) { + allocateBucket(); + } + buckets[getBucket(lastNode)][getIndex(lastNode)].key = key; + buckets[getBucket(lastNode)][getIndex(lastNode)].value = value; + siftUp(lastNode); + // std::cout << "EXIT insert" << std::endl; +} + +void handler(); +int global = 0; +void Heap::remove(Chose* value) { + // std::cout << "ENTER remove id=" << id << " " << (int)(value) << " " << value->lod.heaps[id] << "/" << lastNode << std::endl; + int node = value->lod.heaps[id]; + if (buckets[getBucket(node)][getIndex(node)].value != value) { + std::cout << "ERROR ! Trying to remove " << (int)(value) + << " but found " << (int)(buckets[getBucket(node)][getIndex(node)].value) + << std::endl; + } + + if (node == lastNode) { // On a supprimé le dernier noeud. + --lastNode; + // + 1 pour garder au moins un bucket "en cache". + if (getBucket(lastNode) + 1 < lastAllocatedBucket) + freeBucket(); + std::cout << "Remove exit A"; + return; + } + + buckets[getBucket(node)][getIndex(node)] = \ + buckets[getBucket(lastNode)][getIndex(lastNode)]; + + --lastNode; + + // + 1 pour garder au moins un bucket "en cache". + if (getBucket(lastNode) + 1 < lastAllocatedBucket) { + freeBucket(); + } + + siftDown(node); + std::cout << "Remove exit B"; +} + +Chose* Heap::popIfLessThan(int key) { + std::cout << "Enter Pop " << id << " lastNode=" << lastNode; + for (int i = 0; i <= lastNode; i++) + std::cout << " " + << (int)(buckets[getBucket(i)][getIndex(i)].key) << "_" + << (int)(buckets[getBucket(i)][getIndex(i)].value); + std::cout << std::endl; + if (lastNode >= 0 && buckets[0][0].key < key) { + Chose* ret = buckets[0][0].value; + std::cout << "Pop " << ret->lod.heaps[id] << std::endl; + remove(ret); + std::cout << "Exit A Pop " << id << " lastNode=" << lastNode << " return=" << (int)(ret); + for (int i = 0; i <= lastNode; i++) + std::cout << " " + << (int)(buckets[getBucket(i)][getIndex(i)].key) << "_" + << (int)(buckets[getBucket(i)][getIndex(i)].value); + std::cout << std::endl; + return ret; + } + std::cout << "Exit B Pop " << id << " lastNode=" << lastNode << std::endl; + return NULL; +} + +void Heap::siftUp(int node) { + HeapNode* n; + HeapNode* np; + while (true) { + n = &(buckets[getBucket(node)][getIndex(node)]); + if (node <= 0) + break; + int p = parent(node); + np = &(buckets[getBucket(p)][getIndex(p)]); + if (n->key >= np->key) + break; + HeapNode temp = *n; + *n = *np; + *np = temp; + // mettre à jour le champ lod.heaps[id] de l'ancien parent qu'on + // vient de descendre. + n->value->lod.heaps[id] = node; + // std::cout << "SET " << (int)(n->value) << " id=" << id << " to " << node << std::endl; + node = p; + } + // après les break; qui sortent de la boucle, on a déjà actualisé + // le pointeur `n` vers buckets[getBucket(node)][getIndex(node)]. + n->value->lod.heaps[id] = node; + // std::cout << "SET " << (int)(n->value) << " id=" << id << " to " << node << std::endl; +} + +void Heap::siftDown(int node) { + HeapNode* n; + HeapNode* nlc; + HeapNode* nrc; + while (true) { + n = &(buckets[getBucket(node)][getIndex(node)]); + int lc = leftchild(node); + int rc = rightchild(node); + nlc = &(buckets[getBucket(lc)][getIndex(lc)]); + nrc = &(buckets[getBucket(rc)][getIndex(rc)]); + // exchLeft et exchRight peuvent être tout deux true. Dans ce + // cas, c'est exchRight qui gagne. + bool exchLeft = (lc <= lastNode) && (n->key > nlc->key); + bool exchRight = (rc <= lastNode) && (n->key > nrc->key) && (nlc->key > nrc->key); + if ((!exchLeft) && (!exchRight)) + break; + HeapNode temp = *n; + if (exchRight) { + *n = *nrc; + *nrc = temp; + } else { + *n = *nlc; + *nlc = temp; + } + // mettre à jour le champ lod.heaps[id] de l'ancien fils qu'on + // vient de remonter. + n->value->lod.heaps[id] = node; + // std::cout << "SET " << (int)(n->value) << " id=" << id << " to " << node << std::endl; + node = (exchRight ? rc : lc); + } + // après les break; qui sortent de la boucle, on a déjà actualisé + // le pointeur `n` vers buckets[getBucket(node)][getIndex(node)]. + n->value->lod.heaps[id] = node; + // std::cout << "SET " << (int)(n->value) << " id=" << id << " to " << node << std::endl; +} + +void Heap::allocateBucket() { + ++lastAllocatedBucket; + if (lastAllocatedBucket >= bucketArraySize) { + HeapNode** old = buckets; + buckets = new HeapNode*[bucketArraySize*2]; + for (int i = 0; i < lastAllocatedBucket; i++) + buckets[i] = old[i]; + delete[] old; + bucketArraySize *= 2; + } + buckets[lastAllocatedBucket] = new HeapNode[bucketSize]; +} + +void Heap::freeBucket() { + delete[] buckets[lastAllocatedBucket]; + --lastAllocatedBucket; + if (lastAllocatedBucket * 4 < bucketArraySize && bucketArraySize > 1) { + HeapNode** old = buckets; + buckets = new HeapNode*[bucketArraySize/2]; + for (int i = 0; i <= lastAllocatedBucket; i++) + buckets[i] = old[i]; + delete[] old; + bucketArraySize /= 2; + } +} diff --git a/heap.hh b/heap.hh new file mode 100644 index 0000000..6db9dcd --- /dev/null +++ b/heap.hh @@ -0,0 +1,35 @@ +struct HeapNode { + int key; + Chose* value; +}; + +class Heap { +private: + int id; + static const int log2BucketSize = 9; // 2^9 = 512 + static const int bucketSize = (1 << log2BucketSize); + HeapNode** buckets; + int lastAllocatedBucket; + int bucketArraySize; + int lastNode; +private: + inline int getBucket(int node) { + return (node >> log2BucketSize); + } + inline int getIndex(int node) { + return (node & (bucketSize - 1)); + } + void allocateBucket(); // Allocate into last+1 + void freeBucket(); // free last + void siftUp(int node); + void siftDown(int node); + inline int parent(int node) { return (node - 1)/2; } + inline int leftchild(int node) { return node * 2 + 1; } + inline int rightchild(int node) { return node * 2 + 2; } +public: + Heap(); + void insert(int key, Chose* value); + void remove(Chose* value); + Chose* popIfLessThan(int key); + void setId(int id); +}; diff --git a/lod.cpp b/lod.cpp index e67b372..f32ea29 100644 --- a/lod.cpp +++ b/lod.cpp @@ -1,79 +1,54 @@ #include "all_includes.hh" -Abr::Abr() { +Lod::Lod(Vertex camera, Chose* root) { + for (int i = 0; i < 6; i++) merge[i].setId(i); + for (int i = 0; i < 12; i++) split[i].setId(6+i); + this->camera[0] = camera.x; + this->camera[1] = camera.y; + this->camera[2] = camera.z; + addSplitCube(root); + setCamera(camera); } -void Abr::insert(int key, Chose* value) { - key = key; - value = value; - //map.insert(key,value); -} - -void Abr::remove(int key, Chose* value) { - std::multimap::iterator it; - std::pair::iterator, std::multimap::iterator> ret; - ret = map.equal_range(key); - - for (it=ret.first; it!=ret.second; ++it) { - if ((*it).second == value) { - map.erase(it); - break; - } - } -} - -Chose* Abr::popIfLessThan(int key) { - std::multimap::iterator it = map.begin(); - - if((*it).first < key) { - map.erase(it); - return (*it).second; - } else { - return NULL; - } -} - -#define NegateEven(v, i) ((v)*(((i)&1) ? 1 : -1)) - -Lod::Lod(){}; - -Lod::Lod(float camera[3]) { - this->camera[0] = camera[0]; - this->camera[1] = camera[1]; - this->camera[2] = camera[2]; -} - -void Lod::setCamera(float camera[3]) { - this->camera[0] = camera[0]; - this->camera[1] = camera[1]; - this->camera[2] = camera[2]; +void Lod::setCamera(Vertex newCamera) { + this->camera[0] = newCamera.x; + this->camera[1] = newCamera.y; + this->camera[2] = newCamera.z; // Merge. for(int i = 0; i < 6; i++) { Chose* c; int pos = NegateEven(camera[i>>1], i); while((c = merge[i].popIfLessThan(pos))) { + std::cout << "=== mer Pop " << (int)(c) << " from merge " << i << std::endl; for(int j = 0; j < 6; j++) { - if(i == j) break; - // TODO : sera merge[j].remove(c->mergeCube[j]); - merge[j].remove(NegateEven(c->mergeCube[j], j), c); + if(i == j) continue; + std::cout << "=== mer Remove " << (int)(c) << " from merge " << j << std::endl; + merge[j].remove(c); + // TODO } } } // Split out vers split in. for(int i = 0; i < 6; i++) { Chose* c; - int pos = NegateEven(camera[i>>1], i+1); + int pos = NegateOdd(camera[i>>1], i); while((c = split[2*i+1].popIfLessThan(pos))) { + std::cout << "=== soi Pop " << (int)(c) << " from split " << 2*i+1 << std::endl; + for (int a = 0; a < 18; a++) std::cout << (c->lod.heaps[a]) << " "; + std::cout << std::endl; if(c->inCounter == 5) { for(int j = 0; j < 6; j++) { - if(i == j) break; - // TODO : sera split[2*j].remove(c->splitCube[j]); - split[2*j].remove(NegateEven(c->splitCube[j], j), c); + if(i == j) continue; + std::cout << "=== soi1 Remove " << (int)(c)<<" from split "<< 2*j<inCounter++; + std::cout << "=== soi2 Insert " << (int)(c) << " into split " << 2*i << std::endl; split[2*i].insert(c->splitCube[i], c); } } @@ -84,154 +59,55 @@ void Lod::setCamera(float camera[3]) { Chose* c; int pos = NegateEven(camera[i>>1], i); while((c = split[2*i].popIfLessThan(pos))) { + std::cout << "=== sio Pop " << (int)(c) << " from split " << 2*i << std::endl; c->inCounter--; + std::cout << "=== sio Insert " << (int)(c) << " into split " << 2*i+1 << std::endl; split[2*i+1].insert(c->splitCube[i], c); } } } -void Lod::addMergeCube(Chose* chose, int limits[6]) { - for(int i = 0; i < 5; i++) - merge[i].insert(NegateEven(limits[i], i), chose); +void Lod::doSplit(Chose* c) { + std::cout << "doSplit " << (int)(c) << std::endl; + // TODO + c->split(); + std::vector::iterator it; + for (it = c->children.begin(); it != c->children.end(); ++it) { + (*it)->triangulation(); + (*it)->updateAABB(); + addSplitCube((*it)); + } + std::cout << "END doSplit" << std::endl; } -void Lod::addSplitCube(Chose* chose, int limits[6]) { +void Lod::addMergeCube(Chose* chose) { + for(int i = 0; i < 5; i++) { + std::cout << "+++ mer Insert " << (int)(chose) << " into merge " << i << std::endl; + merge[i].insert(NegateEven(chose->lod.mergeCube[i], i), chose); + } +} + +void Lod::addSplitCube(Chose* chose) { + std::cout << "addSplitCube " << (int)chose << std::endl; chose->inCounter = 0; - for(int i = 0; i < 5; i++) - if(NegateEven(limits[i],i) > camera[i>>1]) { + 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(limits[i],i), chose); + std::cout << "+++ spl1 Insert " << (int)(chose) << " into split " << 2*i << std::endl; + split[2*i].insert(NegateEven(chose->lod.splitCube[i],i), chose); } else { - split[2*i+1].insert(NegateEven(limits[i],i+1), chose); + std::cout << "+++ spl2 Insert " << (int)(chose) << " into split " << 2*i+1<lod.splitCube[i],i), chose); } -} - -Heap::Heap(int id) - : id(id), buckets(new HeapNode*[1]), lastAllocatedBucket(-1), - bucketArraySize(1), lastNode(-1) { -} - -void Heap::insert(int key, Chose* value) { - ++lastNode; - if (getBucket(lastNode) > lastAllocatedBucket) { - allocateBucket(); } - buckets[getBucket(lastNode)][getIndex(lastNode)].key = key; - buckets[getBucket(lastNode)][getIndex(lastNode)].value = value; - siftUp(lastNode); -} - -void Heap::remove(int node) { - --lastNode; - - if (node > lastNode) { // On a supprimé le dernier noeud. - // + 1 pour garder au moins un bucket "en cache". - if (getBucket(lastNode) + 1 < lastAllocatedBucket) - freeBucket(); - return; - } - - buckets[getBucket(node)][getIndex(node)] = \ - buckets[getBucket(lastNode)][getIndex(lastNode)]; - - // + 1 pour garder au moins un bucket "en cache". - if (getBucket(lastNode) + 1 < lastAllocatedBucket) { - freeBucket(); - } - - siftDown(node); -} - -Chose* Heap::popIfLessThan(int key) { - if (lastNode >= 0 && buckets[0][0].key < key) { - Chose* ret = buckets[0][0].value; - remove(0); - return ret; - } - return NULL; -} - -void Heap::siftUp(int node) { - HeapNode* n; - HeapNode* np; - while (true) { - n = &(buckets[getBucket(node)][getIndex(node)]); - if (node <= 0) - break; - int p = parent(node); - np = &(buckets[getBucket(p)][getIndex(p)]); - if (n->key >= np->key) - break; - HeapNode temp = *n; - *n = *np; - *np = temp; - // mettre à jour le champ lod.heaps[id] de l'ancien parent qu'on - // vient de descendre. - n->value->lod.heaps[id] = node; - node = p; - } - // après les break; qui sortent de la boucle, on a déjà actualisé - // le pointeur `n` vers buckets[getBucket(node)][getIndex(node)]. - n->value->lod.heaps[id] = node; -} - -void Heap::siftDown(int node) { - HeapNode* n; - HeapNode* nlc; - HeapNode* nrc; - while (true) { - n = &(buckets[getBucket(node)][getIndex(node)]); - int lc = leftchild(node); - int rc = rightchild(node); - nlc = &(buckets[getBucket(lc)][getIndex(lc)]); - nrc = &(buckets[getBucket(rc)][getIndex(rc)]); - // exchLeft et exchRight peuvent être tout deux true. Dans ce - // cas, c'est exchRight qui gagne. - bool exchLeft = (lc <= lastNode) && (n->key > nlc->key); - bool exchRight = (rc <= lastNode) && (n->key > nrc->key) && (nlc->key > nrc->key); - if ((!exchLeft) && (!exchRight)) - break; - HeapNode temp = *n; - if (exchRight) { - *n = *nrc; - *nrc = temp; - } else { - *n = *nlc; - *nlc = temp; + // TODO : si chose->inCounter == 6, il faut le split immédiatement. + if (chose->inCounter == 6) { + for(int i = 0; i < 6; i++) { + std::cout << "+++ spl3 Remove " << (int)(chose) << " from split " << 2*i << std::endl; + split[2*i].remove(chose); } - // mettre à jour le champ lod.heaps[id] de l'ancien fils qu'on - // vient de remonter. - n->value->lod.heaps[id] = node; - node = (exchRight ? rc : lc); - } - // après les break; qui sortent de la boucle, on a déjà actualisé - // le pointeur `n` vers buckets[getBucket(node)][getIndex(node)]. - n->value->lod.heaps[id] = node; -} - -void Heap::allocateBucket() { - ++lastAllocatedBucket; - if (lastAllocatedBucket >= bucketArraySize) { - HeapNode** old = buckets; - buckets = new HeapNode*[bucketArraySize*2]; - for (int i = 0; i < lastAllocatedBucket; i++) - buckets[i] = old[i]; - delete[] old; - bucketArraySize *= 2; - } - buckets[lastAllocatedBucket] = new HeapNode[bucketSize]; -} - -void Heap::freeBucket() { - delete[] buckets[lastAllocatedBucket]; - --lastAllocatedBucket; - if (lastAllocatedBucket * 4 < bucketArraySize && bucketArraySize > 1) { - HeapNode** old = buckets; - buckets = new HeapNode*[bucketArraySize/2]; - for (int i = 0; i <= lastAllocatedBucket; i++) - buckets[i] = old[i]; - delete[] old; - bucketArraySize /= 2; + std::cout << "CALL doSplit FROM addSplitCube" << std::endl; + doSplit(chose); } } diff --git a/lod.hh b/lod.hh index 5b46fcf..2a47125 100644 --- a/lod.hh +++ b/lod.hh @@ -2,74 +2,33 @@ #define _LOD_HH_ #include "all_includes.hh" -class Abr { - private : - std::multimap map; - - public : - Abr(); - void insert(int key, Chose* value); //TODO Retourne un item*. - void remove(int key, Chose* value); //TODO Prend un item*. - Chose* popIfLessThan(int key); -}; - - class Lod { - private : - Abr merge[6]; // {xMin, xMax, yMin, yMax, zMin, zMax}. - Abr split[12]; // {xMinIn, xMinOut, xMaxIn, xMaxOut, yMinIn, yMaxOut, yMaxIn, yMaxOut, zMinIn, zMinOut, zMaxIn, zMaxOut}. +private : + Heap merge[6]; // {xMin, xMax, yMin, yMax, zMin, zMax}. + Heap split[12]; // {xMinIn, xMinOut, xMaxIn, xMaxOut, yMinIn, yMaxOut, yMaxIn, yMaxOut, zMinIn, zMinOut, zMaxIn, zMaxOut}. float camera[3]; - - public : - Lod(); - Lod(float[3]); - void addMergeCube(Chose* chose, int limits[6]); - void addSplitCube(Chose* chose, int limits[6]); - void setCamera(float camera[3]); -}; - -struct HeapNode { - int key; - Chose* value; -}; - -class Heap { private: - int id; - static const int log2BucketSize = 9; // 2^9 = 512 - static const int bucketSize = (1 << log2BucketSize); - HeapNode** buckets; - int lastAllocatedBucket; - int bucketArraySize; - int lastNode; -private: - inline int getBucket(int node) { - return (node >> log2BucketSize); + inline float NegateEven(float value, int evenodd) { + return (value*((evenodd&1) ? 1 : -1)); } - inline int getIndex(int node) { - return (node & (bucketSize - 1)); + inline float NegateOdd(float value, int evenodd) { + return (value*((evenodd&1) ? -1 : 1)); } - void allocateBucket(); // Allocate into last+1 - void freeBucket(); // free last - void siftUp(int node); - void siftDown(int node); - inline int parent(int node) { return (node - 1)/2; } - inline int leftchild(int node) { return node * 2 + 1; } - inline int rightchild(int node) { return node * 2 + 2; } -public: - Heap(int id); - void insert(int key, Chose* value); - void remove(int node); - Chose* popIfLessThan(int key); + void doSplit(Chose* c); +public : + Lod(Vertex camera, Chose* root); + void addMergeCube(Chose* chose); + void addSplitCube(Chose* chose); + void setCamera(Vertex camera); }; -class LodNode { -public: +struct LodNode { int heaps[18]; - int aabb[6]; + float aabb[6]; + float splitCube[12]; + float mergeCube[6]; int inCounter; - HeapNode* splitCube[12]; - HeapNode* mergeCube[6]; + bool firstBBPoint; }; #endif diff --git a/main.cpp b/main.cpp index 04e4441..dbb2578 100644 --- a/main.cpp +++ b/main.cpp @@ -27,22 +27,23 @@ int main() { Vertex sw(0, 0, 0); Vertex nw(0, size, 0); Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw); + c->triangulation(); + c->updateAABB(); // c->split(); - recursiveSubdivide(c); + // recursiveSubdivide(c); - Heap h(1); - (void)h; - h.insert(43,c); - h.insert(42,c->children[0]); - h.popIfLessThan(42); // NULL - h.popIfLessThan(43); // c->children[0] - h.popIfLessThan(44); // c - h.popIfLessThan(44); // NULL + // Heap h(1); + // (void)h; + // h.insert(43,c); + // h.insert(42,c->children[0]); + // h.popIfLessThan(42); // NULL + // h.popIfLessThan(43); // c->children[0] + // h.popIfLessThan(44); // c + // h.popIfLessThan(44); // NULL - View *v = new View(c); - Vertex cc = v->camera.cameraCenter; - float camera[3] = {cc.x, cc.y, cc.z}; - camera[0] = camera[0]; - Lod lod(camera); + new View(c); + // Vertex cc = v->camera.cameraCenter; + // float camera[3] = {cc.x, cc.y, cc.z}; + // Lod lod(camera); return 0; } diff --git a/rules/batiment/batimentquad.cpp b/rules/batiment/batimentquad.cpp index 1349f6f..5267005 100644 --- a/rules/batiment/batimentquad.cpp +++ b/rules/batiment/batimentquad.cpp @@ -1,62 +1,55 @@ #include "all_includes.hh" -BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal entry) : Chose(), ne(ne) { +BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal entry) : Chose() { addEntropy(ne, se, sw, nw); this->entry = entry; - lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); - this->ne = ne-lctr; - this->se = se-lctr; - this-> sw = sw-lctr; - this->nw = nw-lctr; - triangulation(); + lctr = (ne + se + sw + nw) / 4; + corner[NE] = ne;//-lctr; + corner[SE] = se;//-lctr; + corner[SW] = sw;//-lctr; + corner[NW] = nw;//-lctr; } BatimentQuad::~BatimentQuad() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -int BatimentQuad::width() { return this->ne.x - this->sw.x; } -int BatimentQuad::height() { return this->ne.y - this->sw.y; } - -std::vector BatimentQuad::getBoundingBoxPoints() const { - std::vector list; - return list; +void BatimentQuad::getBoundingBoxPoints() { + addBBPoint(corner[NE]); + addBBPoint(corner[SE]); + addBBPoint(corner[SW]); + addBBPoint(corner[NW]); + addBBPoint(corner[NE] + Vertex(0,0,maxHeight + maxHeight/2)); // TODO + addBBPoint(corner[SE] + Vertex(0,0,maxHeight + maxHeight/2)); + addBBPoint(corner[SW] + Vertex(0,0,maxHeight + maxHeight/2)); + addBBPoint(corner[NW] + Vertex(0,0,maxHeight + maxHeight/2)); } bool BatimentQuad::split() { - factory(1,1,ne,se,sw,nw); - return true; -} - -Chose* BatimentQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw) { - int th = 20; // Terrain height. - Quad q = Quad(ne,se,sw,nw); - seed = seed; - n = n; + int th = 20; // Terrain height. + Quad q = Quad(corner[NE],corner[SE],corner[SW],corner[NW]); q.offset(N,-140); q.offset(E,-140); q.offset(S,-140); q.offset(W,-140); - addChild(new TrottoirQuadNormal(lctr+ne,lctr+se,lctr+q.corner[1],lctr+q.corner[0],th,E)); - addChild(new TrottoirQuadNormal(lctr+se,lctr+sw,lctr+q.corner[2],lctr+q.corner[1],th,E)); - addChild(new TrottoirQuadNormal(lctr+sw,lctr+nw,lctr+q.corner[3],lctr+q.corner[2],th,E)); - addChild(new TrottoirQuadNormal(lctr+nw,lctr+ne,lctr+q.corner[0],lctr+q.corner[3],th,E)); + addChild(new TrottoirQuadNormal(/*lctr+*/corner[NE],/*lctr+*/corner[SE],/*lctr+*/q.corner[1],/*lctr+*/q.corner[0],th,E)); + addChild(new TrottoirQuadNormal(/*lctr+*/corner[SE],/*lctr+*/corner[SW],/*lctr+*/q.corner[2],/*lctr+*/q.corner[1],th,E)); + addChild(new TrottoirQuadNormal(/*lctr+*/corner[SW],/*lctr+*/corner[NW],/*lctr+*/q.corner[3],/*lctr+*/q.corner[2],th,E)); + addChild(new TrottoirQuadNormal(/*lctr+*/corner[NW],/*lctr+*/corner[NE],/*lctr+*/q.corner[0],/*lctr+*/q.corner[3],th,E)); q.corner[0] = q.corner[0] + Vertex(0,0,th); q.corner[1] = q.corner[1] + Vertex(0,0,th); q.corner[2] = q.corner[2] + Vertex(0,0,th); q.corner[3] = q.corner[3] + Vertex(0,0,th); - addChild(new BatimentQuadJardin(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3])); + addChild(new BatimentQuadJardin(/*lctr+*/q.corner[0],/*lctr+*/q.corner[1],/*lctr+*/q.corner[2],/*lctr+*/q.corner[3])); q.offset(this->entry,-400); - addChild(new BatimentQuadMaison(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3])); - return NULL; // pour compilation, à virer. + addChild(new BatimentQuadMaison(/*lctr+*/q.corner[0],/*lctr+*/q.corner[1],/*lctr+*/q.corner[2],/*lctr+*/q.corner[3])); + return true; } void BatimentQuad::triangulation() { @@ -64,17 +57,17 @@ void BatimentQuad::triangulation() { int h = hashInRange(seed,0,minHeight,maxHeight); int htoit = hashInRange(seed,0,minHeight/2,maxHeight/2); - Vertex neh = ne + Vertex(0,0,h); - Vertex seh = se + Vertex(0,0,h); - Vertex nwh = nw + Vertex(0,0,h); - Vertex swh = sw + Vertex(0,0,h); + Vertex neh = corner[NE] + Vertex(0,0,h); + Vertex seh = corner[SE] + Vertex(0,0,h); + Vertex nwh = corner[NW] + Vertex(0,0,h); + Vertex swh = corner[SW] + Vertex(0,0,h); Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit); // 4 Murs - addTriangle(new Triangle(neh,seh,ne,0xf1,0xe3,0xad)); addTriangle(new Triangle(seh,se,ne,0xf1,0xe3,0xad)); // ne-se-seh-neh - addTriangle(new Triangle(seh,swh,se,0xf1,0xe3,0xad)); addTriangle(new Triangle(swh,sw,se,0xf1,0xe3,0xad)); // se-sw-swh-seh - addTriangle(new Triangle(swh,nwh,sw,0xf1,0xe3,0xad)); addTriangle(new Triangle(nwh,nw,sw,0xf1,0xe3,0xad)); // sw-nw-nwh-swh - addTriangle(new Triangle(nwh,neh,nw,0xf1,0xe3,0xad)); addTriangle(new Triangle(neh,ne,nw,0xf1,0xe3,0xad)); // nw-ne-neh-nwh + addTriangle(new Triangle(neh,seh,corner[NE],0xf1,0xe3,0xad)); addTriangle(new Triangle(seh,corner[SE],corner[NE],0xf1,0xe3,0xad)); // ne-se-seh-neh + addTriangle(new Triangle(seh,swh,corner[SE],0xf1,0xe3,0xad)); addTriangle(new Triangle(swh,corner[SW],corner[SE],0xf1,0xe3,0xad)); // se-sw-swh-seh + addTriangle(new Triangle(swh,nwh,corner[SW],0xf1,0xe3,0xad)); addTriangle(new Triangle(nwh,corner[NW],corner[SW],0xf1,0xe3,0xad)); // sw-nw-nwh-swh + addTriangle(new Triangle(nwh,neh,corner[NW],0xf1,0xe3,0xad)); addTriangle(new Triangle(neh,corner[NE],corner[NW],0xf1,0xe3,0xad)); // nw-ne-neh-nwh // 1 Toit addTriangle(new Triangle(neh,toit,seh,0x9a,0x48,0x3c)); diff --git a/rules/batiment/batimentquad.hh b/rules/batiment/batimentquad.hh index a622f5c..0ccf6f6 100644 --- a/rules/batiment/batimentquad.hh +++ b/rules/batiment/batimentquad.hh @@ -6,10 +6,7 @@ // RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°. class BatimentQuad : public Chose { private : - Vertex ne; - Vertex se; - Vertex sw; - Vertex nw; + Vertex corner[4]; Cardinal entry; public : @@ -18,12 +15,10 @@ class BatimentQuad : public Chose { BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal door); virtual ~BatimentQuad(); - int width(); - int height(); virtual bool split(); virtual void triangulation(); Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; #endif diff --git a/rules/batiment/batimentquadjardin.cpp b/rules/batiment/batimentquadjardin.cpp index 112b1f8..4ea0b71 100644 --- a/rules/batiment/batimentquadjardin.cpp +++ b/rules/batiment/batimentquadjardin.cpp @@ -2,28 +2,27 @@ BatimentQuadJardin::BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { addEntropy(ne, se, sw, nw); - lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); - this->ne = ne-lctr; - this->se = se-lctr; - this-> sw = sw-lctr; - this->nw = nw-lctr; - triangulation(); + lctr = (ne + se + sw + nw) / 4; + corner[NE] = ne;//-lctr; + corner[SE] = se;//-lctr; + corner[SW] = sw;//-lctr; + corner[NW] = nw;//-lctr; } BatimentQuadJardin::~BatimentQuadJardin() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -int BatimentQuadJardin::width() { return this->ne.x - this->sw.x; } - -int BatimentQuadJardin::height() { return this->ne.y - this->sw.y; } - -std::vector BatimentQuadJardin::getBoundingBoxPoints() const { - std::vector list; - return list; +void BatimentQuadJardin::getBoundingBoxPoints() { + addBBPoint(corner[NE]); + addBBPoint(corner[SE]); + addBBPoint(corner[SW]); + addBBPoint(corner[NW]); + addBBPoint(corner[NE] + Vertex(0,0,200)); // TODO + addBBPoint(corner[SE] + Vertex(0,0,200)); + addBBPoint(corner[SW] + Vertex(0,0,200)); + addBBPoint(corner[NW] + Vertex(0,0,200)); } bool BatimentQuadJardin::split() { @@ -34,6 +33,6 @@ bool BatimentQuadJardin::split() { void BatimentQuadJardin::triangulation() { triangles.reserve(2); - addTriangle(new Triangle(lctr+ne,lctr+nw,lctr+sw,0x12,0x64,0x12)); - addTriangle(new Triangle(lctr+sw,lctr+se,lctr+ne,0x10,0x60,0x10)); + addTriangle(new Triangle(/*lctr+*/corner[NE],/*lctr+*/corner[NW],/*lctr+*/corner[SW],0x12,0x64,0x12)); + addTriangle(new Triangle(/*lctr+*/corner[SW],/*lctr+*/corner[SE],/*lctr+*/corner[NE],0x12,0x64,0x12)); } diff --git a/rules/batiment/batimentquadjardin.hh b/rules/batiment/batimentquadjardin.hh index 9c332ab..f9983e8 100644 --- a/rules/batiment/batimentquadjardin.hh +++ b/rules/batiment/batimentquadjardin.hh @@ -6,10 +6,7 @@ // RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°. class BatimentQuadJardin : public Chose { private : - Vertex ne; - Vertex se; - Vertex sw; - Vertex nw; + Vertex corner[4]; public : static const int minHeight = 400; @@ -17,12 +14,10 @@ class BatimentQuadJardin : public Chose { BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual ~BatimentQuadJardin(); - int width(); - int height(); virtual bool split(); virtual void triangulation(); Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; #endif diff --git a/rules/batiment/batimentquadmaison.cpp b/rules/batiment/batimentquadmaison.cpp index e2251fe..f8009c8 100644 --- a/rules/batiment/batimentquadmaison.cpp +++ b/rules/batiment/batimentquadmaison.cpp @@ -2,33 +2,31 @@ BatimentQuadMaison::BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { addEntropy(ne, se, sw, nw); - lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); - this->ne = ne-lctr; - this->se = se-lctr; - this-> sw = sw-lctr; - this->nw = nw-lctr; - triangulation(); + lctr = (ne + se + sw + nw) / 4; + corner[NE] = ne;//-lctr; + corner[SE] = se;//-lctr; + corner[SW] = sw;//-lctr; + corner[NW] = nw;//-lctr; } BatimentQuadMaison::~BatimentQuadMaison() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -int BatimentQuadMaison::width() { return this->ne.x - this->sw.x; } - -int BatimentQuadMaison::height() { return this->ne.y - this->sw.y; } - -std::vector BatimentQuadMaison::getBoundingBoxPoints() const { - std::vector list; - return list; +void BatimentQuadMaison::getBoundingBoxPoints() { + addBBPoint(corner[NE]); + addBBPoint(corner[SE]); + addBBPoint(corner[SW]); + addBBPoint(corner[NW]); + addBBPoint(corner[NE] + Vertex(0,0,maxHeight + maxHeight/2)); // TODO + addBBPoint(corner[SE] + Vertex(0,0,maxHeight + maxHeight/2)); + addBBPoint(corner[SW] + Vertex(0,0,maxHeight + maxHeight/2)); + addBBPoint(corner[NW] + Vertex(0,0,maxHeight + maxHeight/2)); } bool BatimentQuadMaison::split() { - - return true; + return false; } void BatimentQuadMaison::triangulation() { @@ -36,21 +34,21 @@ void BatimentQuadMaison::triangulation() { int h = hashInRange(seed,0,minHeight,maxHeight); int htoit = hashInRange(seed,0,minHeight/2,maxHeight/2); - Vertex neh = ne + Vertex(0,0,h); - Vertex seh = se + Vertex(0,0,h); - Vertex nwh = nw + Vertex(0,0,h); - Vertex swh = sw + Vertex(0,0,h); + Vertex neh = corner[NE] + Vertex(0,0,h); + Vertex seh = corner[SE] + Vertex(0,0,h); + Vertex nwh = corner[NW] + Vertex(0,0,h); + Vertex swh = corner[SW] + Vertex(0,0,h); Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit); // 4 Murs - addTriangle(new Triangle(lctr+neh,lctr+seh,lctr+ne,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+seh,lctr+se,lctr+ne,0xf1,0xe3,0xad)); // ne-se-seh-neh - addTriangle(new Triangle(lctr+seh,lctr+swh,lctr+se,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+swh,lctr+sw,lctr+se,0xf1,0xe3,0xad)); // se-sw-swh-seh - addTriangle(new Triangle(lctr+swh,lctr+nwh,lctr+sw,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+nwh,lctr+nw,lctr+sw,0xf1,0xe3,0xad)); // sw-nw-nwh-swh - addTriangle(new Triangle(lctr+nwh,lctr+neh,lctr+nw,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+neh,lctr+ne,lctr+nw,0xf1,0xe3,0xad)); // nw-ne-neh-nwh + addTriangle(new Triangle(/*lctr+*/neh,/*lctr+*/seh,/*lctr+*/corner[NE],0xf1,0xe3,0xad)); addTriangle(new Triangle(/*lctr+*/seh,/*lctr+*/corner[SE],/*lctr+*/corner[NE],0xf1,0xe3,0xad)); // ne-se-seh-neh + addTriangle(new Triangle(/*lctr+*/seh,/*lctr+*/swh,/*lctr+*/corner[SE],0xf1,0xe3,0xad)); addTriangle(new Triangle(/*lctr+*/swh,/*lctr+*/corner[SW],/*lctr+*/corner[SE],0xf1,0xe3,0xad)); // se-sw-swh-seh + addTriangle(new Triangle(/*lctr+*/swh,/*lctr+*/nwh,/*lctr+*/corner[SW],0xf1,0xe3,0xad)); addTriangle(new Triangle(/*lctr+*/nwh,/*lctr+*/corner[NW],/*lctr+*/corner[SW],0xf1,0xe3,0xad)); // sw-nw-nwh-swh + addTriangle(new Triangle(/*lctr+*/nwh,/*lctr+*/neh,/*lctr+*/corner[NW],0xf1,0xe3,0xad)); addTriangle(new Triangle(/*lctr+*/neh,/*lctr+*/corner[NE],/*lctr+*/corner[NW],0xf1,0xe3,0xad)); // nw-ne-neh-nwh // 1 Toit - addTriangle(new Triangle(lctr+neh,lctr+toit,lctr+seh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(lctr+seh,lctr+toit,lctr+swh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(lctr+swh,lctr+toit,lctr+nwh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(lctr+nwh,lctr+toit,lctr+neh,0x9a,0x48,0x3c)); + addTriangle(new Triangle(/*lctr+*/neh,/*lctr+*/toit,/*lctr+*/seh,0x9a,0x48,0x3c)); + addTriangle(new Triangle(/*lctr+*/seh,/*lctr+*/toit,/*lctr+*/swh,0x9a,0x48,0x3c)); + addTriangle(new Triangle(/*lctr+*/swh,/*lctr+*/toit,/*lctr+*/nwh,0x9a,0x48,0x3c)); + addTriangle(new Triangle(/*lctr+*/nwh,/*lctr+*/toit,/*lctr+*/neh,0x9a,0x48,0x3c)); } diff --git a/rules/batiment/batimentquadmaison.hh b/rules/batiment/batimentquadmaison.hh index 437c376..d673ff4 100644 --- a/rules/batiment/batimentquadmaison.hh +++ b/rules/batiment/batimentquadmaison.hh @@ -6,10 +6,7 @@ // RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°. class BatimentQuadMaison : public Chose { private : - Vertex ne; - Vertex se; - Vertex sw; - Vertex nw; + Vertex corner[4]; public : static const int minHeight = 400; @@ -17,12 +14,10 @@ class BatimentQuadMaison : public Chose { BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual ~BatimentQuadMaison(); - int width(); - int height(); virtual bool split(); virtual void triangulation(); Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; #endif diff --git a/rules/chose.cpp b/rules/chose.cpp index ab73b72..0fce8ae 100644 --- a/rules/chose.cpp +++ b/rules/chose.cpp @@ -1,6 +1,8 @@ #include "all_includes.hh" -Chose::Chose() : seed(initialSeed), children() {} +Chose::Chose() : seed(initialSeed), children() { + std::cout << "NEW CHOSE " << (int)(this) << std::endl; +} void Chose::addChild(Chose* c) { children.push_back(c); @@ -11,8 +13,6 @@ void Chose::addTriangle(Triangle* t) { } bool Chose::merge() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); // triangles.clear(); return true; @@ -32,4 +32,33 @@ void Chose::display() { } } -unsigned int Chose::initialSeed = random_seed(); +void Chose::addBBPoint(Vertex v) { + if (lod.firstBBPoint) { + lod.firstBBPoint = false; + lod.aabb[0] = v.x; + lod.aabb[1] = v.x; + lod.aabb[2] = v.y; + lod.aabb[3] = v.y; + lod.aabb[4] = v.z; + lod.aabb[5] = v.z; + } else { + lod.aabb[0] = std::min(lod.aabb[0], v.x); + lod.aabb[1] = std::max(lod.aabb[1], v.x); + lod.aabb[2] = std::min(lod.aabb[2], v.y); + lod.aabb[3] = std::max(lod.aabb[3], v.y); + lod.aabb[4] = std::min(lod.aabb[4], v.z); + lod.aabb[5] = std::max(lod.aabb[5], v.z); + } +} + +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]; + } +} + +unsigned int Chose::initialSeed = 779313522;//random_seed(); diff --git a/rules/chose.hh b/rules/chose.hh index 796b76b..81d5a3d 100644 --- a/rules/chose.hh +++ b/rules/chose.hh @@ -20,8 +20,12 @@ class Chose { void display(); virtual bool split() = 0; virtual bool merge(); + virtual void triangulation() = 0; + virtual void updateAABB(); protected : + void addBBPoint(Vertex v); + virtual void getBoundingBoxPoints() = 0; Chose(); inline void addEntropy(unsigned int x1) { seed = hash2(seed, x1); @@ -49,8 +53,6 @@ class Chose { } void addChild(Chose* c); void addTriangle(Triangle* t); - virtual void triangulation() = 0; - virtual std::vector getBoundingBoxPoints() const = 0; }; #endif diff --git a/rules/quartier/quartierquad.cpp b/rules/quartier/quartierquad.cpp index 0e0a993..6e4fa3c 100644 --- a/rules/quartier/quartierquad.cpp +++ b/rules/quartier/quartierquad.cpp @@ -9,15 +9,19 @@ QuartierQuad::QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() } QuartierQuad::~QuartierQuad() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -std::vector QuartierQuad::getBoundingBoxPoints() const { - std::vector list; - return list; +void QuartierQuad::getBoundingBoxPoints() { + addBBPoint(corner[NE]); + addBBPoint(corner[SE]); + addBBPoint(corner[SW]); + addBBPoint(corner[NW]); + addBBPoint(corner[NE] + Vertex(0,0,1000)); // TODO + addBBPoint(corner[SE] + Vertex(0,0,1000)); + addBBPoint(corner[SW] + Vertex(0,0,1000)); + addBBPoint(corner[NW] + Vertex(0,0,1000)); } Chose* QuartierQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw) { diff --git a/rules/quartier/quartierquad.hh b/rules/quartier/quartierquad.hh index e0a03f0..5f9f7fb 100644 --- a/rules/quartier/quartierquad.hh +++ b/rules/quartier/quartierquad.hh @@ -13,7 +13,7 @@ public: virtual bool split(); virtual void triangulation(); static Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; #endif diff --git a/rules/quartier/quartierquadangle.cpp b/rules/quartier/quartierquadangle.cpp index a05c182..6af41b2 100644 --- a/rules/quartier/quartierquadangle.cpp +++ b/rules/quartier/quartierquadangle.cpp @@ -1,21 +1,13 @@ #include "all_includes.hh" QuartierQuadAngle::QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) { - triangulation(); } QuartierQuadAngle::~QuartierQuadAngle() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -std::vector QuartierQuadAngle::getBoundingBoxPoints() const { - std::vector list; - return list; -} - bool QuartierQuadAngle::split() { for (int i = 0; i < 4; i++) { if (Triangle(corner[NW+i], corner[NE+i], corner[SE+i]).angle() >= Angle::d2r(130)) { diff --git a/rules/quartier/quartierquadangle.hh b/rules/quartier/quartierquadangle.hh index 020bf0e..6f4a5e1 100644 --- a/rules/quartier/quartierquadangle.hh +++ b/rules/quartier/quartierquadangle.hh @@ -12,7 +12,6 @@ class QuartierQuadAngle : public QuartierQuad { QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual ~QuartierQuadAngle(); virtual bool split(); - virtual std::vector getBoundingBoxPoints() const; private : void cutAngle(); diff --git a/rules/quartier/quartierquadcarre.cpp b/rules/quartier/quartierquadcarre.cpp index 1e43473..6af11d1 100644 --- a/rules/quartier/quartierquadcarre.cpp +++ b/rules/quartier/quartierquadcarre.cpp @@ -4,17 +4,10 @@ QuartierQuadCarre::QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw) } QuartierQuadCarre::~QuartierQuadCarre() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -std::vector QuartierQuadCarre::getBoundingBoxPoints() const { - std::vector list; - return list; -} - bool QuartierQuadCarre::split() { Vertex middle[4]; Quad q[4]; diff --git a/rules/quartier/quartierquadcarre.hh b/rules/quartier/quartierquadcarre.hh index 427e0ff..ae13e71 100644 --- a/rules/quartier/quartierquadcarre.hh +++ b/rules/quartier/quartierquadcarre.hh @@ -12,7 +12,6 @@ class QuartierQuadCarre : public QuartierQuad { QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual ~QuartierQuadCarre(); virtual bool split(); - virtual std::vector getBoundingBoxPoints() const; }; #endif diff --git a/rules/quartier/quartierquadrect.cpp b/rules/quartier/quartierquadrect.cpp index 1f8fe3b..3bac028 100644 --- a/rules/quartier/quartierquadrect.cpp +++ b/rules/quartier/quartierquadrect.cpp @@ -4,17 +4,10 @@ QuartierQuadRect::QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw) : } QuartierQuadRect::~QuartierQuadRect() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -std::vector QuartierQuadRect::getBoundingBoxPoints() const { - std::vector list; - return list; -} - bool QuartierQuadRect::split() { Vertex n = Segment(corner[NW], corner[NE]).randomPos(seed, 0, 33, 67); Vertex s = Segment(corner[SE], corner[SW]).randomPos(seed, 1, 33, 67); diff --git a/rules/quartier/quartierquadrect.hh b/rules/quartier/quartierquadrect.hh index d5c8e31..e3ad997 100644 --- a/rules/quartier/quartierquadrect.hh +++ b/rules/quartier/quartierquadrect.hh @@ -12,7 +12,6 @@ class QuartierQuadRect : public QuartierQuad { QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual ~QuartierQuadRect(); virtual bool split(); - virtual std::vector getBoundingBoxPoints() const; }; #endif diff --git a/rules/quartier/quartiertri.cpp b/rules/quartier/quartiertri.cpp index 5864df2..d66bc30 100644 --- a/rules/quartier/quartiertri.cpp +++ b/rules/quartier/quartiertri.cpp @@ -5,19 +5,20 @@ QuartierTri::QuartierTri(Vertex left, Vertex top, Vertex right) : Chose() { corner[0] = left; corner[1] = top; corner[2] = right; - triangulation(); } QuartierTri::~QuartierTri() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); - children.clear(); - triangles.clear(); + children.clear(); + triangles.clear(); } -std::vector QuartierTri::getBoundingBoxPoints() const { - std::vector list; - return list; +void QuartierTri::getBoundingBoxPoints() { + addBBPoint(corner[0]); + addBBPoint(corner[1]); + addBBPoint(corner[2]); + addBBPoint(corner[0] + Vertex(0,0,1000)); // TODO + addBBPoint(corner[1] + Vertex(0,0,1000)); + addBBPoint(corner[2] + Vertex(0,0,1000)); } Chose* QuartierTri::factory(int seed, int n, Vertex left, Vertex top, Vertex right) { diff --git a/rules/quartier/quartiertri.hh b/rules/quartier/quartiertri.hh index b2f92aa..e8e5b08 100644 --- a/rules/quartier/quartiertri.hh +++ b/rules/quartier/quartiertri.hh @@ -14,7 +14,7 @@ class QuartierTri : public Chose { virtual bool split(); virtual void triangulation(); static Chose* factory(int seed, int n, Vertex left, Vertex top, Vertex right); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; #endif diff --git a/rules/route/routequadcarrefour.cpp b/rules/route/routequadcarrefour.cpp index f2f29a8..8483d1c 100644 --- a/rules/route/routequadcarrefour.cpp +++ b/rules/route/routequadcarrefour.cpp @@ -1,20 +1,27 @@ #include "all_includes.hh" -RouteQuadCarrefour::RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) { +RouteQuadCarrefour::RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { addEntropy(ne,se,sw,nw); - triangulation(); + corner[NE] = ne; + corner[SE] = se; + corner[SW] = sw; + corner[NW] = nw; } RouteQuadCarrefour::~RouteQuadCarrefour() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -std::vector RouteQuadCarrefour::getBoundingBoxPoints() const { - std::vector list; - return list; +void RouteQuadCarrefour::getBoundingBoxPoints() { + addBBPoint(corner[NE]); + addBBPoint(corner[SE]); + addBBPoint(corner[SW]); + addBBPoint(corner[NW]); + addBBPoint(corner[NE] + Vertex(0,0,1000)); // TODO + addBBPoint(corner[SE] + Vertex(0,0,1000)); + addBBPoint(corner[SW] + Vertex(0,0,1000)); + addBBPoint(corner[NW] + Vertex(0,0,1000)); } bool RouteQuadCarrefour::split() { @@ -24,6 +31,6 @@ bool RouteQuadCarrefour::split() { void RouteQuadCarrefour::triangulation() { triangles.reserve(2); - addTriangle(new Triangle(ne, nw, sw, 0x36, 0x36, 0x36)); - addTriangle(new Triangle(sw, se, ne, 0x36, 0x36, 0x36)); + addTriangle(new Triangle(corner[NE], corner[NW], corner[SW], 0x36, 0x36, 0x36)); + addTriangle(new Triangle(corner[SW], corner[SE], corner[NE], 0x36, 0x36, 0x36)); } diff --git a/rules/route/routequadcarrefour.hh b/rules/route/routequadcarrefour.hh index 7239834..e4b179c 100644 --- a/rules/route/routequadcarrefour.hh +++ b/rules/route/routequadcarrefour.hh @@ -5,17 +5,14 @@ class RouteQuadCarrefour : public Chose { private : - Vertex ne; - Vertex se; - Vertex sw; - Vertex nw; + Vertex corner[4]; public : RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual ~RouteQuadCarrefour(); virtual bool split(); virtual void triangulation(); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; #endif diff --git a/rules/route/routequadchaussee.cpp b/rules/route/routequadchaussee.cpp index 2f6d4e1..6cf16d3 100644 --- a/rules/route/routequadchaussee.cpp +++ b/rules/route/routequadchaussee.cpp @@ -1,19 +1,27 @@ #include "all_includes.hh" -RouteQuadChaussee::RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) { - triangulation(); +RouteQuadChaussee::RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { + addEntropy(ne,se,sw,nw); + corner[NE] = ne; + corner[SE] = se; + corner[SW] = sw; + corner[NW] = nw; } RouteQuadChaussee::~RouteQuadChaussee() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -std::vector RouteQuadChaussee::getBoundingBoxPoints() const { - std::vector list; - return list; +void RouteQuadChaussee::getBoundingBoxPoints() { + addBBPoint(corner[NE]); + addBBPoint(corner[SE]); + addBBPoint(corner[SW]); + addBBPoint(corner[NW]); + addBBPoint(corner[NE] + Vertex(0,0,1000)); // TODO + addBBPoint(corner[SE] + Vertex(0,0,1000)); + addBBPoint(corner[SW] + Vertex(0,0,1000)); + addBBPoint(corner[NW] + Vertex(0,0,1000)); } bool RouteQuadChaussee::split() { @@ -23,8 +31,8 @@ bool RouteQuadChaussee::split() { void RouteQuadChaussee::triangulation() { triangles.reserve(2); - addTriangle(new Triangle(ne, nw, sw, 0x36, 0x36, 0x36)); - addTriangle(new Triangle(sw, se, ne, 0x36, 0x36, 0x36)); + addTriangle(new Triangle(corner[NE], corner[NW], corner[SW], 0x36, 0x36, 0x36)); + addTriangle(new Triangle(corner[SW], corner[SE], corner[NE], 0x36, 0x36, 0x36)); } // Version avec trottoirs. diff --git a/rules/route/routequadchaussee.hh b/rules/route/routequadchaussee.hh index 1d28f1e..2ca8196 100644 --- a/rules/route/routequadchaussee.hh +++ b/rules/route/routequadchaussee.hh @@ -5,17 +5,14 @@ class RouteQuadChaussee : public Chose { private : - Vertex ne; - Vertex se; - Vertex sw; - Vertex nw; + Vertex corner[4]; public : RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual ~RouteQuadChaussee(); virtual bool split(); virtual void triangulation(); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; #endif diff --git a/rules/route/trottoirquadnormal.cpp b/rules/route/trottoirquadnormal.cpp index 817cd5a..6c6c0f6 100644 --- a/rules/route/trottoirquadnormal.cpp +++ b/rules/route/trottoirquadnormal.cpp @@ -1,25 +1,30 @@ #include "all_includes.hh" TrottoirQuadNormal::TrottoirQuadNormal(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height, Cardinal border) { - this->ne = ne; - this->nw = nw; - this->se = se; - this->sw = sw; + c[NE] = ne; + c[SE] = se; + c[SW] = sw; + c[NW] = nw; this->height = height; this->border = border; - triangulation(); + // TODO : pas besoin de ce champ : il suffit d'orienter + // correctement le trottoir lorsqu'on le crée. } TrottoirQuadNormal::~TrottoirQuadNormal() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -std::vector TrottoirQuadNormal::getBoundingBoxPoints() const { - std::vector list; - return list; +void TrottoirQuadNormal::getBoundingBoxPoints() { + addBBPoint(c[NE]); + addBBPoint(c[SE]); + addBBPoint(c[SW]); + addBBPoint(c[NW]); + addBBPoint(c[NE] + Vertex(0,0,height)); // TODO + addBBPoint(c[SE] + Vertex(0,0,height)); + addBBPoint(c[SW] + Vertex(0,0,height)); + addBBPoint(c[NW] + Vertex(0,0,height)); } bool TrottoirQuadNormal::split() { @@ -29,37 +34,37 @@ bool TrottoirQuadNormal::split() { void TrottoirQuadNormal::triangulation() { Vertex h = Vertex(0,0,height); - Quad q = Quad(ne,se,sw,nw); + Quad q = Quad(c[NE],c[SE],c[SW],c[NW]); if(border == E) { q.offset(E,-15); addTriangle(new Triangle(q.corner[0] + h, q.corner[3] + h, q.corner[2] + h, 0x66, 0x66, 0x66)); addTriangle(new Triangle(q.corner[2] + h, q.corner[1] + h, q.corner[0] + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(ne + h,q.corner[0] + h, q.corner[1] + h, 0xAA, 0xAA, 0xAA)); - addTriangle(new Triangle(q.corner[1] + h, se + h, ne + h, 0xAA, 0xAA, 0xAA)); + addTriangle(new Triangle(c[NE] + h,q.corner[0] + h, q.corner[1] + h, 0xAA, 0xAA, 0xAA)); + addTriangle(new Triangle(q.corner[1] + h, c[SE] + h, c[NE] + h, 0xAA, 0xAA, 0xAA)); - addTriangle(new Triangle(nw + h, nw, sw, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(sw, sw + h, nw + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(ne, ne + h, se + h, 0xAA, 0xAA, 0xAA)); - addTriangle(new Triangle(se + h, se, ne, 0xAA, 0xAA, 0xAA)); + addTriangle(new Triangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[SW], c[SW] + h, c[NW] + h, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[NE], c[NE] + h, c[SE] + h, 0xAA, 0xAA, 0xAA)); + addTriangle(new Triangle(c[SE] + h, c[SE], c[NE], 0xAA, 0xAA, 0xAA)); - addTriangle(new Triangle(ne + h, ne, nw, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(nw, nw + h, ne + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(sw, sw + h, se + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(se + h, se, sw, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[NE] + h, c[NE], c[NW], 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66)); } else { addTriangle(new Triangle(q.corner[0] + h, q.corner[3] + h, q.corner[2] + h, 0x66, 0x66, 0x66)); addTriangle(new Triangle(q.corner[2] + h, q.corner[1] + h, q.corner[0] + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(nw + h, nw, sw, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(sw, sw + h, nw + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(ne, ne + h, se + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(se + h, se, ne, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[SW], c[SW] + h, c[NW] + h, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[NE], c[NE] + h, c[SE] + h, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[SE] + h, c[SE], c[NE], 0x66, 0x66, 0x66)); - addTriangle(new Triangle(ne + h, ne, nw, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(nw, nw + h, ne + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(sw, sw + h, se + h, 0x66, 0x66, 0x66)); - addTriangle(new Triangle(se + h, se, sw, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[NE] + h, c[NE], c[NW], 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66)); + addTriangle(new Triangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66)); } } diff --git a/rules/route/trottoirquadnormal.hh b/rules/route/trottoirquadnormal.hh index 0d81644..693789e 100644 --- a/rules/route/trottoirquadnormal.hh +++ b/rules/route/trottoirquadnormal.hh @@ -5,10 +5,7 @@ class TrottoirQuadNormal : public Chose { private : - Vertex ne; - Vertex se; - Vertex sw; - Vertex nw; + Vertex c[4]; int height; Cardinal border; @@ -17,7 +14,7 @@ class TrottoirQuadNormal : public Chose { virtual ~TrottoirQuadNormal(); virtual bool split(); virtual void triangulation(); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; #endif diff --git a/rules/terrain/terrainquadherbe.cpp b/rules/terrain/terrainquadherbe.cpp index 6e7662b..75ec363 100644 --- a/rules/terrain/terrainquadherbe.cpp +++ b/rules/terrain/terrainquadherbe.cpp @@ -6,22 +6,26 @@ TerrainQuadHerbe::TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw) : corner[SE] = se; corner[SW] = sw; corner[NW] = nw; - triangulation(); } TerrainQuadHerbe::~TerrainQuadHerbe() { - for(unsigned int i = 0; i < children.size(); i++) - delete(children[i]); children.clear(); triangles.clear(); } -std::vector TerrainQuadHerbe::getBoundingBoxPoints() const { - std::vector list; - return list; +void TerrainQuadHerbe::getBoundingBoxPoints() { + addBBPoint(corner[NE]); + addBBPoint(corner[SE]); + addBBPoint(corner[SW]); + addBBPoint(corner[NW]); + addBBPoint(corner[NE] + Vertex(0,0,1000)); // TODO + addBBPoint(corner[SE] + Vertex(0,0,1000)); + addBBPoint(corner[SW] + Vertex(0,0,1000)); + addBBPoint(corner[NW] + Vertex(0,0,1000)); } -TerrainQuadHerbe::TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), red(red) { +TerrainQuadHerbe::TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Vertex nw) + : Chose(), red(red) { addEntropy(ne, se, sw, nw); corner[NE] = ne; corner[SE] = se; diff --git a/rules/terrain/terrainquadherbe.hh b/rules/terrain/terrainquadherbe.hh index a052588..a3cc8b9 100644 --- a/rules/terrain/terrainquadherbe.hh +++ b/rules/terrain/terrainquadherbe.hh @@ -15,7 +15,7 @@ class TerrainQuadHerbe : public Chose { virtual ~TerrainQuadHerbe(); virtual bool split(); virtual void triangulation(); - virtual std::vector getBoundingBoxPoints() const; + virtual void getBoundingBoxPoints(); }; diff --git a/view.cpp b/view.cpp index 51be1a6..0ef6539 100644 --- a/view.cpp +++ b/view.cpp @@ -1,7 +1,10 @@ #include "all_includes.hh" -// camera(Camera(Vertex(1000,1000,2000),45,100,1000,0.6) -View::View(Chose* root) : root(root), camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6)) { +// 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)), + lod(camera.cameraCenter, root) { initWindow(); mainLoop(); } @@ -86,6 +89,7 @@ void View::renderScene(int lastTime, int currentTime) { camera.animation(currentTime-lastTime); camera.setCamera(); + lod.setCamera(camera.cameraCenter); setLight(); //displayAxes(); diff --git a/view.hh b/view.hh index 2f5cfba..78b6df7 100644 --- a/view.hh +++ b/view.hh @@ -43,6 +43,8 @@ class View { public : Camera camera; +private: + Lod lod; static const int windowWidth = 1024; static const int windowHeight = 768;