Refactor : bool split() → void split();

This commit is contained in:
Georges Dupéron 2012-01-20 12:43:35 +01:00
parent dd6f6e30a0
commit 4b258d1cc6
17 changed files with 36 additions and 46 deletions

19
lod.cpp
View File

@ -58,16 +58,17 @@ void Lod::setCamera(Vertex newCamera) {
}
void Lod::doSplit(Chose* c) {
if (c->split()) {
std::vector<Chose*>::iterator it;
for (it = c->children.begin(); it != c->children.end(); ++it) {
(*it)->triangulation();
(*it)->updateAABB();
// (*it)->drawAABB();
addSplitCube((*it));
}
addMergeCube(c);
c->split();
std::vector<Chose*>::iterator it;
bool mergeCube = false;
for (it = c->children.begin(); it != c->children.end(); ++it) {
mergeCube = true;
(*it)->triangulation();
(*it)->updateAABB();
// (*it)->drawAABB();
addSplitCube((*it));
}
addMergeCube(c);
// else {
// // Pour debug : quand on tente de split un objet qui ne peut
// // pas l'être, on vire le dessin de sa splitBox.

View File

@ -30,7 +30,7 @@ Arbre::Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type) : star
addEntropy((int)(type));
}
bool Arbre::split() {
void Arbre::split() {
if (type == ARBRE && length > floatInRange(seed, -1, 10, 20)) {
int nbBranches = 2 + (hash2(seed, -2) % 3);
for (int i = 0; i < nbBranches; i++) {
@ -43,7 +43,6 @@ bool Arbre::split() {
}
addChild(new Arbre(start, rotation, length, TRONC));
}
return true;
}
void Arbre::triangulation() {

View File

@ -25,7 +25,7 @@ public:
Arbre(Vertex _start, Quad plane);
Arbre(Vertex _start, Triangle plane);
Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type = ARBRE);
virtual bool split();
virtual void split();
virtual void triangulation();
virtual void getBoundingBoxPoints();
virtual float LODFactor();

View File

@ -13,17 +13,16 @@ ArcheQuad::ArcheQuad(Quad _c, float _height, float _start, float _end, Type _typ
}
}
bool ArcheQuad::split() {
void ArcheQuad::split() {
if (type == PLAT)
return false;
return;
if (std::abs(end - start) < 0.1 && std::abs(f(end) - f(start)) < 0.05)
return false;
return;
float mid = (start + end) / 2;
Vertex n = (c[NW] + c[NE]) / 2.f;
Vertex s = (c[SE] + c[SW]) / 2.f;
addChild(new ArcheQuad(Quad(n, s, c[SW], c[NW]), height, start, mid, type));
addChild(new ArcheQuad(Quad(c[NE], c[SE], s, n), height, mid, end, type));
return true;
}
void ArcheQuad::triangulation() {

View File

@ -19,7 +19,7 @@ private:
Type type;
public:
ArcheQuad(Quad _c, float _height, float _start = 0, float _end = 1, Type _type = RANDOM);
virtual bool split();
virtual void split();
virtual void triangulation();
virtual void getBoundingBoxPoints();
float f(float x);

View File

@ -7,7 +7,7 @@ BatimentQuad::BatimentQuad(Quad _c, bool _isSub, QuadBool _w)
addEntropy(w[N+i] ? 0 : 1);
}
bool BatimentQuad::split() {
void BatimentQuad::split() {
if (!isSub) {
bordureRouteTrottoir();
} else {
@ -21,8 +21,6 @@ bool BatimentQuad::split() {
addChild(new TerrainQuad(c));
}
}
return true;
}
void BatimentQuad::bordureRouteTrottoir() {
@ -97,8 +95,8 @@ BatimentTri_::BatimentTri_(Triangle _c) : Chose(), c(_c) {
addEntropy(c);
}
bool BatimentTri_::split() {
return false;
void BatimentTri_::split() {
// TODO : BatimentTri::split()
}
void BatimentTri_::triangulation() {

View File

@ -14,7 +14,7 @@ private:
public:
BatimentQuad(Quad _c, bool _isSub = false, QuadBool _w = QuadBool(true, true, true, true));
virtual bool split();
virtual void split();
virtual void triangulation();
virtual void getBoundingBoxPoints();
BatimentQuad* isSubdivision(bool val);
@ -25,7 +25,7 @@ class BatimentTri_ : public Chose {
public:
BatimentTri_(Triangle _c);
virtual bool split();
virtual void split();
virtual void triangulation();
virtual void getBoundingBoxPoints();
};

View File

@ -26,9 +26,8 @@ void Chose::addChild(Chose* c) {
children.push_back(c);
}
bool Chose::merge() {
void Chose::merge() {
clearChildren();
return true;
}
void Chose::addGPUTriangle(Vertex left, Vertex top, Vertex right, unsigned int rgb) {

View File

@ -16,8 +16,8 @@ public :
void display();
void displayNormals();
void drawAABB(); // DEBUG
virtual bool split() { return false; };
virtual bool merge();
virtual void split() {};
virtual void merge();
virtual void triangulation() { clearTriangles(); };
virtual void updateAABB();

View File

@ -12,7 +12,7 @@ void EtageQuad::getBoundingBoxPoints() {
addBBPoints(ch);
}
bool EtageQuad::split() {
void EtageQuad::split() {
if (nbEtages > 1 && etage == 0 && ((w[N] && w[S]) || (w[E] && w[W])) && c.minLengthEW() > 800 && proba(seed, 0, 0.8)) {
Quad q = c << ((w[N] && w[S]) ? 0 : 1);
Quad qh = ch << ((w[N] && w[S]) ? 0 : 1);
@ -61,7 +61,6 @@ bool EtageQuad::split() {
}
addChild(new PlancherPlafond(c, PlancherPlafond::PLANCHER));
addChild(new PlancherPlafond(ch.offsetNormal(-10), PlancherPlafond::PLAFOND));
return true;
}
void EtageQuad::triangulation() {

View File

@ -14,7 +14,7 @@ class EtageQuad : public Chose {
public :
EtageQuad(Quad c, Quad ch, QuadBool _w, int _etage, int _nbEtages);
virtual bool split();
virtual void split();
virtual void triangulation();
virtual void getBoundingBoxPoints();
};

View File

@ -25,9 +25,9 @@ void MurQuad::setWindowOrDoor() {
windowPosh = Quad(wFront[NE],wBack[NE],wBack[NW],wFront[NW]);
}
bool MurQuad::split() {
void MurQuad::split() {
if(!(window || door))
return false;
return;
float length = c.maxLengthNS();
@ -52,8 +52,6 @@ bool MurQuad::split() {
addChild(new MurQuad(left,lefth,false));
addChild(new MurQuad(right,righth,false));
}
return true;
}
void MurQuad::triangulation() {

View File

@ -18,7 +18,7 @@ public :
MurQuad(Quad c, Quad ch, bool _window=false, bool _top=false, bool _bottom=false, bool _door=false);
virtual void triangulation();
virtual bool split();
virtual void split();
virtual void getBoundingBoxPoints();
void setWindowOrDoor();
};

View File

@ -8,7 +8,7 @@ void QuartierQuad::getBoundingBoxPoints() {
addBBPoints(c, Dimensions::hauteurMaxBatiment);
}
bool QuartierQuad::split() {
void QuartierQuad::split() {
bool small = c.minLength() < 35 * 100;
bool big = (c.minLengthNS() > 100 * 100 || c.minLengthEW() > 100 * 100) && c.minLength() > 40*100 && c.maxLength() < 300*100;
bool isConcave = c.isConcave();
@ -36,7 +36,6 @@ bool QuartierQuad::split() {
carre();
else
addChild(new BatimentQuad(c));
return true;
}
void QuartierQuad::triangulation() {
@ -163,7 +162,7 @@ void QuartierTri::getBoundingBoxPoints() {
addBBPoints(c, Dimensions::hauteurMaxBatiment);
}
bool QuartierTri::split() {
void QuartierTri::split() {
bool small = c.minLength() < 6000;
bool big = c.maxLength() >= 10000;
float minAngle = c.minAngle();
@ -190,7 +189,6 @@ bool QuartierTri::split() {
} else {
batiments(); // TODO : addChild(new BatimentTri_(c));
}
return true;
}
void QuartierTri::triangulation() {

View File

@ -9,7 +9,7 @@ private:
public:
QuartierQuad(Quad _c);
virtual void getBoundingBoxPoints();
virtual bool split();
virtual void split();
virtual void triangulation();
private:
void triangulationConcave(Triangle t);
@ -28,7 +28,7 @@ private:
public:
QuartierTri(Triangle _c);
virtual void getBoundingBoxPoints();
virtual bool split();
virtual void split();
virtual void triangulation();
private:
void centre();

View File

@ -4,8 +4,8 @@ TerrainQuad::TerrainQuad(Quad _c, bool _addTrees) : Chose(), c(_c), addTrees(_ad
addEntropy(c);
}
bool TerrainQuad::split() {
if (!addTrees) return false;
void TerrainQuad::split() {
if (!addTrees) return;
addChild(new TerrainQuad(c, false));
@ -27,7 +27,6 @@ bool TerrainQuad::split() {
for (int i = 0; i < pi; i++) {
addChild(new Arbre(p[i], c));
}
return true;
}
void TerrainQuad::getBoundingBoxPoints() {

View File

@ -20,7 +20,7 @@ class TerrainQuad : public Chose {
public :
TerrainQuad(Quad _c, bool _addTrees = true);
virtual bool split();
virtual void split();
virtual void triangulation();
virtual void getBoundingBoxPoints();
};