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

View File

@ -58,16 +58,17 @@ void Lod::setCamera(Vertex newCamera) {
} }
void Lod::doSplit(Chose* c) { void Lod::doSplit(Chose* c) {
if (c->split()) { c->split();
std::vector<Chose*>::iterator it; std::vector<Chose*>::iterator it;
bool mergeCube = false;
for (it = c->children.begin(); it != c->children.end(); ++it) { for (it = c->children.begin(); it != c->children.end(); ++it) {
mergeCube = true;
(*it)->triangulation(); (*it)->triangulation();
(*it)->updateAABB(); (*it)->updateAABB();
// (*it)->drawAABB(); // (*it)->drawAABB();
addSplitCube((*it)); addSplitCube((*it));
} }
addMergeCube(c); addMergeCube(c);
}
// else { // else {
// // Pour debug : quand on tente de split un objet qui ne peut // // Pour debug : quand on tente de split un objet qui ne peut
// // pas l'être, on vire le dessin de sa splitBox. // // 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)); addEntropy((int)(type));
} }
bool Arbre::split() { void Arbre::split() {
if (type == ARBRE && length > floatInRange(seed, -1, 10, 20)) { if (type == ARBRE && length > floatInRange(seed, -1, 10, 20)) {
int nbBranches = 2 + (hash2(seed, -2) % 3); int nbBranches = 2 + (hash2(seed, -2) % 3);
for (int i = 0; i < nbBranches; i++) { for (int i = 0; i < nbBranches; i++) {
@ -43,7 +43,6 @@ bool Arbre::split() {
} }
addChild(new Arbre(start, rotation, length, TRONC)); addChild(new Arbre(start, rotation, length, TRONC));
} }
return true;
} }
void Arbre::triangulation() { void Arbre::triangulation() {

View File

@ -25,7 +25,7 @@ public:
Arbre(Vertex _start, Quad plane); Arbre(Vertex _start, Quad plane);
Arbre(Vertex _start, Triangle plane); Arbre(Vertex _start, Triangle plane);
Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type = ARBRE); Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type = ARBRE);
virtual bool split(); virtual void split();
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();
virtual float LODFactor(); 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) if (type == PLAT)
return false; return;
if (std::abs(end - start) < 0.1 && std::abs(f(end) - f(start)) < 0.05) if (std::abs(end - start) < 0.1 && std::abs(f(end) - f(start)) < 0.05)
return false; return;
float mid = (start + end) / 2; float mid = (start + end) / 2;
Vertex n = (c[NW] + c[NE]) / 2.f; Vertex n = (c[NW] + c[NE]) / 2.f;
Vertex s = (c[SE] + c[SW]) / 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(n, s, c[SW], c[NW]), height, start, mid, type));
addChild(new ArcheQuad(Quad(c[NE], c[SE], s, n), height, mid, end, type)); addChild(new ArcheQuad(Quad(c[NE], c[SE], s, n), height, mid, end, type));
return true;
} }
void ArcheQuad::triangulation() { void ArcheQuad::triangulation() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,7 +12,7 @@ void EtageQuad::getBoundingBoxPoints() {
addBBPoints(ch); 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)) { 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 q = c << ((w[N] && w[S]) ? 0 : 1);
Quad qh = ch << ((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(c, PlancherPlafond::PLANCHER));
addChild(new PlancherPlafond(ch.offsetNormal(-10), PlancherPlafond::PLAFOND)); addChild(new PlancherPlafond(ch.offsetNormal(-10), PlancherPlafond::PLAFOND));
return true;
} }
void EtageQuad::triangulation() { void EtageQuad::triangulation() {

View File

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

View File

@ -25,9 +25,9 @@ void MurQuad::setWindowOrDoor() {
windowPosh = Quad(wFront[NE],wBack[NE],wBack[NW],wFront[NW]); windowPosh = Quad(wFront[NE],wBack[NE],wBack[NW],wFront[NW]);
} }
bool MurQuad::split() { void MurQuad::split() {
if(!(window || door)) if(!(window || door))
return false; return;
float length = c.maxLengthNS(); float length = c.maxLengthNS();
@ -52,8 +52,6 @@ bool MurQuad::split() {
addChild(new MurQuad(left,lefth,false)); addChild(new MurQuad(left,lefth,false));
addChild(new MurQuad(right,righth,false)); addChild(new MurQuad(right,righth,false));
} }
return true;
} }
void MurQuad::triangulation() { 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); MurQuad(Quad c, Quad ch, bool _window=false, bool _top=false, bool _bottom=false, bool _door=false);
virtual void triangulation(); virtual void triangulation();
virtual bool split(); virtual void split();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();
void setWindowOrDoor(); void setWindowOrDoor();
}; };

View File

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

View File

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

View File

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

View File

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