Merge branch 'master' of github:jsmaniac/2011-m2s3-city-builder

This commit is contained in:
Georges Dupéron 2011-12-09 23:46:34 +01:00
commit 9d8a85afd6
3 changed files with 47 additions and 7 deletions

47
lod.cpp
View File

@ -39,24 +39,61 @@ Lod::Lod(float[3] camera) {
void Lod::setCamera(float[3] camera) { void Lod::setCamera(float[3] camera) {
this->camera = camera; this->camera = camera;
for(int i = 0; i < 5; i++) { // Merge.
for(int i = 0; i < 6; i++) {
Chose* c; Chose* c;
int pos = NegateEven(camera[i>>1], i); int pos = NegateEven(camera[i>>1], i);
while(c = merge[i].popIfLessThan(pos)) { while(c = merge[i].popIfLessThan(pos)) {
for(int j = 0; j < 5; j++) { for(int j = 0; j < 6; j++) {
if(i == j) break; if(i == j) break;
// TODO : sera merge[j].remove(c->mergeCube[j]); // TODO : sera merge[j].remove(c->mergeCube[j]);
merge[j].remove(NegateEven(c->mergeCube[j], j), c); merge[j].remove(NegateEven(c->mergeCube[j], j), c);
} }
} }
} }
// Split out vers split in.
for(int i = 0; i < 6; i++) {
Chose* c;
int pos = NegateEven(camera[i>>1], i+1);
while(c = split[2*i+1].popIfLessThan(pos)) {
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);
}
}
else {
c->inCounter++;
split[2*i].insert(c->splitCube[i], c);
}
}
}
// Split in vers split out.
for(int i = 0; i < 6; i++) {
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);
}
}
} }
void Lod::addMergeCube(Chose* chose, int[6] limits) { void Lod::addMergeCube(Chose* chose, int[6] limits) {
for(int i = 0; i < 5; i++) for(int i = 0; i < 5; i++)
merge.insert(NegateEven(limits[i], i), chose); merge[i].insert(NegateEven(limits[i], i), chose);
} }
void Lod::addSplitCube(int[6] limits) { void Lod::addSplitCube(Chose* chose, int[6] limits) {
chose->inCounter = 0;
for(int i = 0; i < 5; i++)
if(NegateEven(limits[i],i) > camera[i>>1]) {
chose->inCounter++;
split[2*i].insert(NegateEven(limits[i],i), chose);
}
else {
split[2*i+1].insert(NegateEven(limits[i],i+1), chose);
}
} }

4
lod.hh
View File

@ -14,8 +14,8 @@ class Abr {
class Lod { class Lod {
private : private :
Abr merge[6]; Abr merge[6]; // {xMin, xMax, yMin, yMax, zMin, zMax}.
Abr split[12]; Abr split[12]; // {xMinIn, xMinOut, xMaxIn, xMaxOut, yMinIn, yMaxOut, yMaxIn, yMaxOut, zMinIn, zMinOut, zMaxIn, zMaxOut}.
float camera[3]; float camera[3];
public : public :

View File

@ -10,6 +10,9 @@ public:
unsigned int seed; unsigned int seed;
std::vector<Chose*> children; std::vector<Chose*> children;
std::vector<Triangle*> triangles; std::vector<Triangle*> triangles;
int inCounter;
int splitCube[6];
int mergeCube[6];
public: public:
Chose(); Chose();
inline void addEntropy(unsigned int x1) { seed = hash2(seed, x1); } inline void addEntropy(unsigned int x1) { seed = hash2(seed, x1); }