Le LOD marche 100% pour les split !

This commit is contained in:
Georges Dupéron 2011-12-22 18:13:12 +01:00
parent 3701b8e1d5
commit b333f10d0b
3 changed files with 14 additions and 42 deletions

View File

@ -6,14 +6,6 @@ Heap::Heap()
void Heap::init(int id, int factor) { this->id = id; this->factor = factor; }
void Heap::insert(float key, Chose* value) {
// { // DEBUG
// 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 " << value;
// std::cout << " but it is already here." << std::endl;
// }
// }
++lastNode;
if (getBucket(lastNode) > lastAllocatedBucket) {
allocateBucket();
@ -21,26 +13,11 @@ void Heap::insert(float key, Chose* value) {
buckets[getBucket(lastNode)][getIndex(lastNode)].key = key;
buckets[getBucket(lastNode)][getIndex(lastNode)].value = value;
siftUp(lastNode);
for (int i = 0; i <= lastNode; i++) {
std::cout << id << " ";
std::cout << buckets[getBucket(lastNode)][getIndex(lastNode)].key << " ";
std::cout << buckets[getBucket(lastNode)][getIndex(lastNode)].value;
std::cout << typeid(*(buckets[getBucket(lastNode)][getIndex(lastNode)].value)).name();
std::cout << std::endl;
}
}
void Heap::remove(Chose* value) {
int node = value->lod.heaps[id];
// { // DEBUG
// if (buckets[getBucket(node)][getIndex(node)].value != value) {
// std::cout << "ERROR ! Trying to remove " << value;
// std::cout << " but found " << buckets[getBucket(node)][getIndex(node)].value;
// std::cout << std::endl;
// }
// }
if (node == lastNode) { // On a supprimé le dernier noeud.
--lastNode;
// + 1 pour garder au moins un bucket "en cache".
@ -84,7 +61,7 @@ void Heap::siftUp(int node) {
break;
int p = parent(node);
np = &(buckets[getBucket(p)][getIndex(p)]);
if (n->key * factor <= np->key * factor)
if (n->key * factor >= np->key * factor) //!!!!!
break;
HeapNode temp = *n;
*n = *np;
@ -111,9 +88,9 @@ void Heap::siftDown(int node) {
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 * factor < nlc->key * factor);
bool exchRight = (rc <= lastNode) && (n->key * factor < nrc->key * factor);
exchRight = exchRight && (nlc->key * factor < nrc->key * factor);
bool exchLeft = (lc <= lastNode) && (n->key * factor > nlc->key * factor);
bool exchRight = (rc <= lastNode) && (n->key * factor > nrc->key * factor);
exchRight = exchRight && (nlc->key * factor > nrc->key * factor);
if ((!exchLeft) && (!exchRight))
break;
HeapNode temp = *n;

21
lod.cpp
View File

@ -33,7 +33,6 @@ void Lod::setCamera(Vertex newCamera) {
for(int i = 0; i < 6; i++) {
Chose* c;
while((c = splitOut[i].popIfLessThan(camera[i>>1]))) {
std::cout<<"soi "<<c->lod.inCounter+1<<" "<<typeid(*c).name()<<" "<<c<<std::endl;
if(c->lod.inCounter == 5) {
for(int j = 0; j < 6; j++) {
if(i == j) continue;
@ -52,7 +51,6 @@ void Lod::setCamera(Vertex newCamera) {
for(int i = 0; i < 6; i++) {
Chose* c;
while((c = splitIn[i].popIfLessThan(camera[i>>1]))) {
std::cout<<"SIO "<<c->lod.inCounter-1<<" "<<typeid(*c).name()<<" "<<c<<std::endl;
c->lod.inCounter--;
splitOut[i].insert(c->lod.splitBox[i], c);
}
@ -61,20 +59,21 @@ void Lod::setCamera(Vertex newCamera) {
void Lod::doSplit(Chose* c) {
// TODO
if (c->split() && c->children.size() > 0) {
if (c->split()) {
std::vector<Chose*>::iterator it;
for (it = c->children.begin(); it != c->children.end(); ++it) {
(*it)->triangulation();
(*it)->updateAABB();
(*it)->drawAABB();
// (*it)->drawAABB();
addSplitCube((*it));
}
} else {
// Pour debug : quand on tente de split un objet qui ne peut
// pas l'être, on vire le dessin de sa splitBox.
c->triangles.clear();
c->triangulation();
}
// else {
// // Pour debug : quand on tente de split un objet qui ne peut
// // pas l'être, on vire le dessin de sa splitBox.
// c->triangles.clear();
// c->triangulation();
// }
}
void Lod::addMergeCube(Chose* chose) {
@ -85,9 +84,6 @@ void Lod::addMergeCube(Chose* chose) {
void Lod::addSplitCube(Chose* chose) {
chose->lod.inCounter = 0;
for(int i = 0; i < 6; i++) {
// std::cout << chose->lod.splitBox[i] << " " << camera[i>>1] << " " << splitOut[i].factor;
// std::cout << " " << (splitOut[i].lessThan(chose->lod.splitBox[i], camera[i>>1]) ? "t" : "f");
// std::cout << std::endl;
if(splitOut[i].lessThan(chose->lod.splitBox[i], camera[i>>1])) {
chose->lod.inCounter++;
splitIn[i].insert(chose->lod.splitBox[i], chose);
@ -101,5 +97,4 @@ void Lod::addSplitCube(Chose* chose) {
splitIn[i].remove(chose);
doSplit(chose);
}
std::cout<<"insert "<<chose->lod.inCounter<<" "<<typeid(*chose).name()<<" "<<chose<<std::endl;
}

View File

@ -3,7 +3,7 @@
// camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6)
View::View(Chose* root)
: root(root),
camera(Camera(Vertex(-15000,-15000,3000),45,90,1000,0.6)),
camera(Camera(Vertex(-9000,-15000,3000),45,90,1000,0.6)),
lod(camera.cameraCenter, root) {
initWindow();
mainLoop();
@ -105,7 +105,7 @@ void View::mainLoop() {
short continuer = 1;
SDL_Event event;
SDL_EnableKeyRepeat(40,40);
// SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(SDL_DISABLE);
while ( SDL_PollEvent(&event) ); // empty queue.