www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 6c35e2e47cb9e3c90363834641cd755f36af7113
parent 8aee27c488c3f1571b709dcd5c261784da5d8ea9
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Wed,  4 Jan 2012 23:51:56 +0100

Nettoyage. Refactor : Utilisation de Quad et Triangle au lieu de Vertex[] dans toutes les classes. Suppression des destructeurs. Suppression des factory déclarés par erreur dans les `.h`. Ajouts : enum SommetTriangle, operator+(Quad, Vertex), operator+(Triangle, Vertex), {Quad,Triangle}::{operator[],operator>>,operator<<}

Diffstat:
Mgeometry/directions.hh | 10++++++++++
Mgeometry/quad.cpp | 4++++
Mgeometry/quad.hh | 13+++++++++++++
Mgeometry/triangle.cpp | 4++++
Mgeometry/triangle.hh | 13+++++++++++++
Mmain.cpp | 2+-
Mrules/batiment/batimentquad.cpp | 57++++++++++++++++-----------------------------------------
Mrules/batiment/batimentquad.hh | 6++----
Mrules/batiment/batimentquadblock.cpp | 36+++++-------------------------------
Mrules/batiment/batimentquadblock.hh | 8++------
Mrules/batiment/batimentquadjardin.cpp | 31++++++-------------------------
Mrules/batiment/batimentquadjardin.hh | 7++-----
Mrules/batiment/batimentquadmaison.cpp | 50++++++++++++++------------------------------------
Mrules/batiment/batimentquadmaison.hh | 7++-----
Mrules/batiment/batimentquadmaisonpont.cpp | 87++++++++++++++++++-------------------------------------------------------------
Mrules/batiment/batimentquadmaisonpont.hh | 6++----
Mrules/batiment/batimentquadpont.cpp | 57+++++++++++++++++----------------------------------------
Mrules/batiment/batimentquadpont.hh | 8++------
Mrules/batiment/batimentquadtoit.cpp | 28++++------------------------
Mrules/batiment/batimentquadtoit.hh | 7++-----
Mrules/chose.cpp | 29++++++++++++++++++++++++++++-
Mrules/chose.hh | 17++++++++++++++---
Mrules/quartier/quartierquad.cpp | 52++++++++++++++++++----------------------------------
Mrules/quartier/quartierquad.hh | 7+++----
Mrules/quartier/quartierquadangle.cpp | 39+++++++++++++++++----------------------
Mrules/quartier/quartierquadangle.hh | 5++---
Mrules/quartier/quartierquadcarre.cpp | 13++++---------
Mrules/quartier/quartierquadcarre.hh | 3+--
Mrules/quartier/quartierquadrect.cpp | 13++++---------
Mrules/quartier/quartierquadrect.hh | 3+--
Mrules/quartier/quartiertri.cpp | 26+++++++-------------------
Mrules/quartier/quartiertri.hh | 7+++----
Mrules/quartier/quartiertrihauteur.cpp | 16++++++++--------
Mrules/quartier/quartiertrihauteur.hh | 2+-
Mrules/route/routequadcarrefour.cpp | 31+++++--------------------------
Mrules/route/routequadcarrefour.hh | 6++----
Mrules/route/routequadchaussee.cpp | 31+++++--------------------------
Mrules/route/routequadchaussee.hh | 6++----
Mrules/route/routetrichaussee.cpp | 22+++++-----------------
Mrules/route/routetrichaussee.hh | 5++---
Mrules/route/trottoirquadnormal.cpp | 34+++++-----------------------------
Mrules/route/trottoirquadnormal.hh | 8++++----
Mrules/terrain/terrainquadherbe.cpp | 22++++------------------
Mrules/terrain/terrainquadherbe.hh | 5++---
44 files changed, 287 insertions(+), 556 deletions(-)

diff --git a/geometry/directions.hh b/geometry/directions.hh @@ -23,4 +23,14 @@ inline Coin operator+(Coin c, int i) { return Coin((int(c) + int(i)) & 3); } +enum SommetTriangle { + LEFT = 0, + TOP = 1, + RIGHT = 2 +}; + +inline SommetTriangle operator+(SommetTriangle c, int i) { + return SommetTriangle((((int(c) + int(i)) % 3 ) + 3) % 3); +} + #endif diff --git a/geometry/quad.cpp b/geometry/quad.cpp @@ -100,3 +100,7 @@ float Quad::maxAngle() { } return a; } + +Quad operator+(const Quad& q, const Vertex& v) { + return Quad(q[NE] + v, q[SE] + v, q[SW] + v, q[NW] + v); +} diff --git a/geometry/quad.hh b/geometry/quad.hh @@ -11,6 +11,19 @@ class Quad { public : Quad(); Quad(Vertex ne, Vertex se, Vertex sw, Vertex nw); + inline Vertex& operator[] (Coin x) { + return c[x]; + } + inline const Vertex& operator[] (Coin x) const { + return c[x]; + } + inline Quad operator>> (int rot) { + return Quad(c[NE - rot], c[SE - rot], c[SW - rot], c[NW - rot]); + } + inline Quad operator<< (int rot) { + return Quad(c[NE + rot], c[SE + rot], c[SW + rot], c[NW + rot]); + } + friend Quad operator+(const Quad& t, const Vertex& v); void offset(Cardinal side, int offset); void offsetNESW(int offsetN, int offsetE, int offsetS, int offsetW); int minLengthNS(); diff --git a/geometry/triangle.cpp b/geometry/triangle.cpp @@ -28,3 +28,7 @@ void Triangle::offsetBase(int offset) { c[1] = q.c[0]; c[2] = q.c[2]; } + +Triangle operator+(const Triangle& t, const Vertex& v) { + return Triangle(t[LEFT] + v, t[TOP] + v, t[RIGHT] + v); +} diff --git a/geometry/triangle.hh b/geometry/triangle.hh @@ -10,6 +10,19 @@ class Triangle { public : Triangle(); Triangle(Vertex left, Vertex top, Vertex right); + inline Vertex& operator[] (SommetTriangle x) { + return c[x]; + } + inline const Vertex& operator[] (SommetTriangle x) const { + return c[x]; + } + inline Triangle operator>> (int rot) { + return Triangle(c[LEFT - rot], c[TOP - rot], c[RIGHT - rot]); + } + inline Triangle operator<< (int rot) { + return Triangle(c[LEFT + rot], c[TOP + rot], c[RIGHT + rot]); + } + friend Triangle operator+(const Triangle& t, const Vertex& v); float cosAngle(); // cosinus de l'angle en c[1]. float angle(); // angle en c[1], en degrés. TODO : le calcul ne donne que des angles entre 0 et 180 ! float minAngle(); // angle minimum du triangle (en c[0], c[1] ou c[2]). diff --git a/main.cpp b/main.cpp @@ -8,7 +8,7 @@ int main() { Vertex se(size, 0, 0); Vertex sw(0, 0, 0); Vertex nw(0, size, 0); - Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw); + Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, Quad(ne, se, sw, nw)); c->triangulation(); c->updateAABB(); diff --git a/rules/batiment/batimentquad.cpp b/rules/batiment/batimentquad.cpp @@ -1,28 +1,13 @@ #include "all_includes.hh" -BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal entry) : Chose() { - addEntropy(ne, se, sw, nw); - this->entry = entry; - c[NE] = ne;//-lctr; - c[SE] = se;//-lctr; - c[SW] = sw;//-lctr; - c[NW] = nw;//-lctr; -} - -BatimentQuad::~BatimentQuad() { - children.clear(); - triangles.clear(); +BatimentQuad::BatimentQuad(Quad c, Cardinal entry) : Chose(), c(c), entry(entry) { + addEntropy(c); + addEntropy(entry); } void BatimentQuad::getBoundingBoxPoints() { - addBBPoint(c[NE]); - addBBPoint(c[SE]); - addBBPoint(c[SW]); - addBBPoint(c[NW]); - addBBPoint(c[NE] + Vertex(0,0,maxHeight + maxHeight/2)); // TODO - addBBPoint(c[SE] + Vertex(0,0,maxHeight + maxHeight/2)); - addBBPoint(c[SW] + Vertex(0,0,maxHeight + maxHeight/2)); - addBBPoint(c[NW] + Vertex(0,0,maxHeight + maxHeight/2)); + addBBPoints(c); + addBBPoints(c + Vertex(0,0,maxHeight + maxHeight/2)); // TODO } bool BatimentQuad::split() { @@ -32,9 +17,8 @@ bool BatimentQuad::split() { Quad q = Quad(c[NE],c[SE],c[SW],c[NW]); // TODO ajouter une classe surface. //addQuad(c[SE],c[SW],c[NW],c[NE],0xDD,0xDD,0xDD); - addChild(new BatimentQuadMaisonPont(q.c[0],q.c[1],q.c[2],q.c[3],800)); - } - else { + addChild(new BatimentQuadMaisonPont(q,800)); + } else { int th = 20; // Terrain height. Quad q = Quad(c[NE],c[SE],c[SW],c[NW]); th = th; @@ -43,21 +27,16 @@ bool BatimentQuad::split() { q.offset(S,-140); q.offset(W,-140); - addChild(new TrottoirQuadNormal(c[NE],c[SE],q.c[1],q.c[0],th,E)); - addChild(new TrottoirQuadNormal(c[SE],c[SW],q.c[2],q.c[1],th,E)); - addChild(new TrottoirQuadNormal(c[SW],c[NW],q.c[3],q.c[2],th,E)); - addChild(new TrottoirQuadNormal(c[NW],c[NE],q.c[0],q.c[3],th,E)); - - q.c[0] = q.c[0] + Vertex(0,0,th); - q.c[1] = q.c[1] + Vertex(0,0,th); - q.c[2] = q.c[2] + Vertex(0,0,th); - q.c[3] = q.c[3] + Vertex(0,0,th); - - addChild(new BatimentQuadJardin(q.c[0],q.c[1],q.c[2],q.c[3])); + addChild(new TrottoirQuadNormal(Quad(c[NE],c[SE],q[SE],q[NE]),th,E)); + addChild(new TrottoirQuadNormal(Quad(c[SE],c[SW],q[SW],q[SE]),th,E)); + addChild(new TrottoirQuadNormal(Quad(c[SW],c[NW],q[NW],q[SW]),th,E)); + addChild(new TrottoirQuadNormal(Quad(c[NW],c[NE],q[NE],q[NW]),th,E)); - q.offset(this->entry,-400); + Quad qh = q + Vertex(0,0,th); + addChild(new BatimentQuadJardin(qh)); - addChild(new BatimentQuadMaison(q.c[0],q.c[1],q.c[2],q.c[3])); + qh.offset(this->entry,-400); + addChild(new BatimentQuadMaison(qh)); } return true; } @@ -68,10 +47,6 @@ void BatimentQuad::triangulation() { int h = hashInRange(seed,0,minHeight,maxHeight); int htoit = hashInRange(seed,0,minHeight/2,maxHeight/2); h += htoit; - Vertex neh = c[NE] + Vertex(0,0,h); - Vertex seh = c[SE] + Vertex(0,0,h); - Vertex nwh = c[NW] + Vertex(0,0,h); - Vertex swh = c[SW] + Vertex(0,0,h); - addOcto(c[NE],c[SE],c[SW],c[NW],neh,seh,swh,nwh,0xFF,0xFF,0x00); + addOcto(c, c + Vertex(0,0,h), 0xFF, 0xFF, 0x00); } diff --git a/rules/batiment/batimentquad.hh b/rules/batiment/batimentquad.hh @@ -6,18 +6,16 @@ class BatimentQuad : public Chose { private : - Vertex c[4]; + Quad c; Cardinal entry; public : static const int minHeight = 400; static const int maxHeight = 800; - BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal door); - virtual ~BatimentQuad(); + BatimentQuad(Quad c, Cardinal entry); virtual bool split(); virtual void triangulation(); - Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual void getBoundingBoxPoints(); }; diff --git a/rules/batiment/batimentquadblock.cpp b/rules/batiment/batimentquadblock.cpp @@ -1,40 +1,14 @@ #include "all_includes.hh" -BatimentQuadBlock::BatimentQuadBlock(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() { - addEntropy(ne, se, sw, nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; - this->height = height; -} - -BatimentQuadBlock::~BatimentQuadBlock() { - children.clear(); - triangles.clear(); +BatimentQuadBlock::BatimentQuadBlock(Quad c, int height) : Chose(), c(c), height(height) { + addEntropy(c); } void BatimentQuadBlock::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));// TODO -} - -bool BatimentQuadBlock::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,height)); // TODO } void BatimentQuadBlock::triangulation() { - //triangles.reserve(2); - Vertex seh = c[SE] + Vertex(0,0,height); - Vertex swh = c[SW] + Vertex(0,0,height); - Vertex nwh = c[NW] + Vertex(0,0,height); - Vertex neh = c[NE] + Vertex(0,0,height); - - addOcto(c[SE],c[SW],c[NW],c[NE],seh,swh,nwh,neh,0xF1,0xE0,0xE0); + addOcto(c, c + Vertex(0,0,height), 0xF1, 0xE0, 0xE0); } diff --git a/rules/batiment/batimentquadblock.hh b/rules/batiment/batimentquadblock.hh @@ -6,16 +6,12 @@ class BatimentQuadBlock : public Chose { private : - Vertex c[4]; + Quad c; int height; public : - - BatimentQuadBlock(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height); - virtual ~BatimentQuadBlock(); - virtual bool split(); + BatimentQuadBlock(Quad c, int height); virtual void triangulation(); - Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual void getBoundingBoxPoints(); }; diff --git a/rules/batiment/batimentquadjardin.cpp b/rules/batiment/batimentquadjardin.cpp @@ -1,36 +1,17 @@ #include "all_includes.hh" -BatimentQuadJardin::BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { - addEntropy(ne, se, sw, nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; -} - -BatimentQuadJardin::~BatimentQuadJardin() { - children.clear(); - triangles.clear(); +BatimentQuadJardin::BatimentQuadJardin(Quad c) : Chose(), c(c) { + addEntropy(c); } void BatimentQuadJardin::getBoundingBoxPoints() { - addBBPoint(c[NE]); - addBBPoint(c[SE]); - addBBPoint(c[SW]); - addBBPoint(c[NW]); - addBBPoint(c[NE] + Vertex(0,0,200)); // TODO - addBBPoint(c[SE] + Vertex(0,0,200)); - addBBPoint(c[SW] + Vertex(0,0,200)); - addBBPoint(c[NW] + Vertex(0,0,200)); -} - -bool BatimentQuadJardin::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,200)); // TODO } void BatimentQuadJardin::triangulation() { triangles.reserve(2); - addTriangle(new GPUTriangle(/*lctr+*/c[NE],/*lctr+*/c[NW],/*lctr+*/c[SW],0x12,0x64,0x12)); - addTriangle(new GPUTriangle(/*lctr+*/c[SW],/*lctr+*/c[SE],/*lctr+*/c[NE],0x12,0x64,0x12)); + addTriangle(new GPUTriangle(c[NE],c[NW],c[SW],0x12,0x64,0x12)); + addTriangle(new GPUTriangle(c[SW],c[SE],c[NE],0x12,0x64,0x12)); } diff --git a/rules/batiment/batimentquadjardin.hh b/rules/batiment/batimentquadjardin.hh @@ -6,17 +6,14 @@ class BatimentQuadJardin : public Chose { private : - Vertex c[4]; + Quad c; public : static const int minHeight = 400; static const int maxHeight = 800; - BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual ~BatimentQuadJardin(); - virtual bool split(); + BatimentQuadJardin(Quad c); virtual void triangulation(); - Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual void getBoundingBoxPoints(); }; diff --git a/rules/batiment/batimentquadmaison.cpp b/rules/batiment/batimentquadmaison.cpp @@ -1,31 +1,12 @@ #include "all_includes.hh" -BatimentQuadMaison::BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { - addEntropy(ne, se, sw, nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; -} - -BatimentQuadMaison::~BatimentQuadMaison() { - children.clear(); - triangles.clear(); +BatimentQuadMaison::BatimentQuadMaison(Quad c) : Chose(), c(c) { + addEntropy(c); } void BatimentQuadMaison::getBoundingBoxPoints() { - addBBPoint(c[NE]); - addBBPoint(c[SE]); - addBBPoint(c[SW]); - addBBPoint(c[NW]); - addBBPoint(c[NE] + Vertex(0,0,maxHeight + maxHeight/2)); // TODO - addBBPoint(c[SE] + Vertex(0,0,maxHeight + maxHeight/2)); - addBBPoint(c[SW] + Vertex(0,0,maxHeight + maxHeight/2)); - addBBPoint(c[NW] + Vertex(0,0,maxHeight + maxHeight/2)); -} - -bool BatimentQuadMaison::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,maxHeight + maxHeight/2)); // TODO } void BatimentQuadMaison::triangulation() { @@ -33,21 +14,18 @@ void BatimentQuadMaison::triangulation() { int h = hashInRange(seed,0,minHeight,maxHeight); int htoit = hashInRange(seed,0,minHeight/2,maxHeight/2); - Vertex neh = c[NE] + Vertex(0,0,h); - Vertex seh = c[SE] + Vertex(0,0,h); - Vertex nwh = c[NW] + Vertex(0,0,h); - Vertex swh = c[SW] + Vertex(0,0,h); - Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit); + Quad ch = c + Vertex(0,0,h); + Vertex toit = (ch[NE] + ch[SE] + ch[SW] + ch[NW]) / 4 + Vertex(0,0,htoit); // 4 Murs - addQuad(/*lctr+*/neh,/*lctr+*/seh,/*lctr+*/c[SE],/*lctr+*/c[NE],0xf1,0xe3,0xad); - addQuad(/*lctr+*/seh,/*lctr+*/swh,/*lctr+*/c[SW],/*lctr+*/c[SE],0xf1,0xe3,0xad); - addQuad(/*lctr+*/swh,/*lctr+*/nwh,/*lctr+*/c[NW],/*lctr+*/c[SW],0xf1,0xe3,0xad); - addQuad(/*lctr+*/nwh,/*lctr+*/neh,/*lctr+*/c[NE],/*lctr+*/c[NW],0xf1,0xe3,0xad); + addQuad(ch[NE],ch[SE],c[SE],c[NE],0xf1,0xe3,0xad); + addQuad(ch[SE],ch[SW],c[SW],c[SE],0xf1,0xe3,0xad); + addQuad(ch[SW],ch[NW],c[NW],c[SW],0xf1,0xe3,0xad); + addQuad(ch[NW],ch[NE],c[NE],c[NW],0xf1,0xe3,0xad); // 1 Toit - addTriangle(new GPUTriangle(/*lctr+*/neh,/*lctr+*/toit,/*lctr+*/seh,0x96,0x16,0x18)); - addTriangle(new GPUTriangle(/*lctr+*/seh,/*lctr+*/toit,/*lctr+*/swh,0x96,0x16,0x18)); - addTriangle(new GPUTriangle(/*lctr+*/swh,/*lctr+*/toit,/*lctr+*/nwh,0x96,0x16,0x18)); - addTriangle(new GPUTriangle(/*lctr+*/nwh,/*lctr+*/toit,/*lctr+*/neh,0x96,0x16,0x18)); + addTriangle(new GPUTriangle(ch[NE],toit,ch[SE],0x96,0x16,0x18)); + addTriangle(new GPUTriangle(ch[SE],toit,ch[SW],0x96,0x16,0x18)); + addTriangle(new GPUTriangle(ch[SW],toit,ch[NW],0x96,0x16,0x18)); + addTriangle(new GPUTriangle(ch[NW],toit,ch[NE],0x96,0x16,0x18)); } diff --git a/rules/batiment/batimentquadmaison.hh b/rules/batiment/batimentquadmaison.hh @@ -6,17 +6,14 @@ class BatimentQuadMaison : public Chose { private : - Vertex c[4]; + Quad c; public : static const int minHeight = 400; static const int maxHeight = 800; - BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual ~BatimentQuadMaison(); - virtual bool split(); + BatimentQuadMaison(Quad c); virtual void triangulation(); - Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual void getBoundingBoxPoints(); }; diff --git a/rules/batiment/batimentquadmaisonpont.cpp b/rules/batiment/batimentquadmaisonpont.cpp @@ -1,28 +1,12 @@ #include "all_includes.hh" -BatimentQuadMaisonPont::BatimentQuadMaisonPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() { - addEntropy(ne, se, sw, nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; - this->height = height; -} - -BatimentQuadMaisonPont::~BatimentQuadMaisonPont() { - children.clear(); - triangles.clear(); +BatimentQuadMaisonPont::BatimentQuadMaisonPont(Quad c, int height) : Chose(), c(c), height(height) { + addEntropy(c); } void BatimentQuadMaisonPont::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)); + addBBPoints(c); + addBBPoints(c + Vertex(0,0,height)); // TODO } bool BatimentQuadMaisonPont::split() { @@ -41,41 +25,12 @@ bool BatimentQuadMaisonPont::split() { qc.offset(E, -partLength); qc.offset(W, -partLength); - Vertex se = qa.c[0]; - Vertex sw = qa.c[1]; - Vertex nw = qa.c[2]; - Vertex ne = qa.c[3]; - - addChild(new BatimentQuadJardin(c[SE],c[SW],c[NW],c[NE])); - addChild(new BatimentQuadBlock(ne,se,sw,nw,partHeight)); - - se = qb.c[0]; - sw = qb.c[1]; - nw = qb.c[2]; - ne = qb.c[3]; - - addChild(new BatimentQuadBlock(ne,se,sw,nw,partHeight)); - - se = qh.c[0] + Vertex(0,0,partHeight); - sw = qh.c[1] + Vertex(0,0,partHeight); - nw = qh.c[2] + Vertex(0,0,partHeight); - ne = qh.c[3] + Vertex(0,0,partHeight); - - addChild(new BatimentQuadBlock(ne,se,sw,nw,partHeight)); - - se = qc.c[0]; - sw = qc.c[1]; - nw = qc.c[2]; - ne = qc.c[3]; - - addChild(new BatimentQuadPont(se,sw,nw,ne,partHeight)); - - Vertex seh = qh.c[0] + Vertex(0,0,2*partHeight); - Vertex swh = qh.c[1] + Vertex(0,0,2*partHeight); - Vertex nwh = qh.c[2] + Vertex(0,0,2*partHeight); - Vertex neh = qh.c[3] + Vertex(0,0,2*partHeight); - - addChild(new BatimentQuadToit(seh,swh,nwh,neh,150)); + addChild(new BatimentQuadJardin(c << 1)); + addChild(new BatimentQuadBlock(qa >> 1,partHeight)); + addChild(new BatimentQuadBlock(qb >> 1,partHeight)); + addChild(new BatimentQuadBlock((qh + Vertex(0,0,partHeight)) >> 1,partHeight)); + addChild(new BatimentQuadPont(qc,partHeight)); + addChild(new BatimentQuadToit(qh + Vertex(0,0,2*partHeight),150)); return true; } @@ -84,21 +39,17 @@ void BatimentQuadMaisonPont::triangulation() { //triangles.reserve(2); float h = 2.5*height/3.; Quad q = Quad(c[NE],c[SE],c[SW],c[NW]).makeParallelogram(); - Vertex seh = q.c[SE] + Vertex(0,0,h); - Vertex swh = q.c[SW] + Vertex(0,0,h); - Vertex nwh = q.c[NW] + Vertex(0,0,h); - Vertex neh = q.c[NE] + Vertex(0,0,h); - - addQuad(c[SE],c[SW],c[NW],c[NE],0x80,0x80,0x80); - addOcto(q.c[NE],q.c[SE],q.c[SW],q.c[NW],neh,seh,swh,nwh,0xF1,0xE0,0xE0); + Quad qh = q + Vertex(0,0,h); - Vertex ce = seh + (neh - seh)/2 + Vertex(0,0,0.5*height/3.); - Vertex cw = swh + (nwh - swh)/2 + Vertex(0,0,0.5*height/3.); + addQuad(c,0x80,0x80,0x80); + addOcto(q,qh,0xF1,0xE0,0xE0); - addTriangle(new GPUTriangle(swh,nwh,cw,0xF1,0xE0,0xE0)); - addTriangle(new GPUTriangle(neh,seh,ce,0xF1,0xE0,0xE0)); + Vertex ce = qh[SE] + (qh[NE] - qh[SE])/2 + Vertex(0,0,0.5*height/3.f); + Vertex cw = qh[SW] + (qh[NW] - qh[SW])/2 + Vertex(0,0,0.5*height/3.f); - addQuad(neh,nwh,cw,ce,0xE0,0x20,0x00); - addQuad(swh,seh,ce,cw,0xE0,0x20,0x00); + addTriangle(new GPUTriangle(qh[SW],qh[NW],cw,0xF1,0xE0,0xE0)); + addTriangle(new GPUTriangle(qh[NE],qh[SE],ce,0xF1,0xE0,0xE0)); + addQuad(qh[NE],qh[NW],cw,ce,0xE0,0x20,0x00); + addQuad(qh[SW],qh[SE],ce,cw,0xE0,0x20,0x00); } diff --git a/rules/batiment/batimentquadmaisonpont.hh b/rules/batiment/batimentquadmaisonpont.hh @@ -6,16 +6,14 @@ class BatimentQuadMaisonPont: public Chose { private : - Vertex c[4]; + Quad c; int height; public : - BatimentQuadMaisonPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height); - virtual ~BatimentQuadMaisonPont(); + BatimentQuadMaisonPont(Quad c, int height); virtual bool split(); virtual void triangulation(); - Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual void getBoundingBoxPoints(); }; diff --git a/rules/batiment/batimentquadpont.cpp b/rules/batiment/batimentquadpont.cpp @@ -1,32 +1,12 @@ #include "all_includes.hh" -BatimentQuadPont::BatimentQuadPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() { - addEntropy(ne, se, sw, nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; - this->height = height; -} - -BatimentQuadPont::~BatimentQuadPont() { - children.clear(); - triangles.clear(); +BatimentQuadPont::BatimentQuadPont(Quad c, int height) : Chose(), c(c), height(height) { + addEntropy(c); } void BatimentQuadPont::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 BatimentQuadPont::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,height)); // TODO } float ct(float x) { @@ -45,10 +25,7 @@ void BatimentQuadPont::triangulation() { height -= 20; Vertex pa = c[NW]; Vertex pb = c[SW]; - Vertex neh = c[NE] + Vertex(0,0,height+20); - Vertex seh = c[SE] + Vertex(0,0,height+20); - Vertex swh = c[SW] + Vertex(0,0,height+20); - Vertex nwh = c[NW] + Vertex(0,0,height+20); + Quad ch = c + Vertex(0,0,height+20); Vertex l1 = c[NE] - c[NW]; Vertex l2 = c[SW] - c[SE]; @@ -59,8 +36,8 @@ void BatimentQuadPont::triangulation() { int middle = steps/2; int n; - addTriangle(new GPUTriangle(c[SW],pb,swh,0xD0,0xD0,0xD0)); - addTriangle(new GPUTriangle(pa,c[NW],nwh,0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(c[SW],pb,ch[SW],0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(pa,c[NW],ch[NW],0xD0,0xD0,0xD0)); for(var=-1.7,n=0; var <= 1.7; var+=pas,n++) { q.offset(W,-n2); @@ -70,24 +47,24 @@ void BatimentQuadPont::triangulation() { addQuad(a,b,pb,pa,0xD0,0xD0,0xD0); if( n < middle) { - addTriangle(new GPUTriangle(pa,a,nwh,0xD0,0xD0,0xD0)); - addTriangle(new GPUTriangle(b,pb,swh,0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(pa,a,ch[NW],0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(b,pb,ch[SW],0xD0,0xD0,0xD0)); } else if(n == middle) { - addTriangle(new GPUTriangle(pa,a,nwh,0xD0,0xD0,0xD0)); - addTriangle(new GPUTriangle(b,pb,swh,0xD0,0xD0,0xD0)); - addTriangle(new GPUTriangle(a,neh,nwh,0xD0,0xD0,0xD0)); - addTriangle(new GPUTriangle(b,swh,seh,0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(pa,a,ch[NW],0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(b,pb,ch[SW],0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(a,ch[NE],ch[NW],0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(b,ch[SW],ch[SE],0xD0,0xD0,0xD0)); } else { - addTriangle(new GPUTriangle(pa,a,neh,0xD0,0xD0,0xD0)); - addTriangle(new GPUTriangle(b,pb,seh,0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(pa,a,ch[NE],0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(b,pb,ch[SE],0xD0,0xD0,0xD0)); } pa = a; pb = b; } - addTriangle(new GPUTriangle(c[SE],pb,seh,0xD0,0xD0,0xD0)); - addTriangle(new GPUTriangle(c[NE],pa,neh,0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(c[SE],pb,ch[SE],0xD0,0xD0,0xD0)); + addTriangle(new GPUTriangle(c[NE],pa,ch[NE],0xD0,0xD0,0xD0)); } diff --git a/rules/batiment/batimentquadpont.hh b/rules/batiment/batimentquadpont.hh @@ -6,16 +6,12 @@ class BatimentQuadPont: public Chose { private : - Vertex c[4]; + Quad c; int height; public : - - BatimentQuadPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height); - virtual ~BatimentQuadPont(); - virtual bool split(); + BatimentQuadPont(Quad c, int height); virtual void triangulation(); - Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual void getBoundingBoxPoints(); }; diff --git a/rules/batiment/batimentquadtoit.cpp b/rules/batiment/batimentquadtoit.cpp @@ -1,32 +1,12 @@ #include "all_includes.hh" -BatimentQuadToit::BatimentQuadToit(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() { - addEntropy(ne, se, sw, nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; - this->height = height; -} - -BatimentQuadToit::~BatimentQuadToit() { - children.clear(); - triangles.clear(); +BatimentQuadToit::BatimentQuadToit(Quad c, int height) : Chose(), c(c), height(height) { + addEntropy(c); } void BatimentQuadToit::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 BatimentQuadToit::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,height)); // TODO } void BatimentQuadToit::triangulation() { diff --git a/rules/batiment/batimentquadtoit.hh b/rules/batiment/batimentquadtoit.hh @@ -6,16 +6,13 @@ // TOTO en faire un classe abstraite et définir des classe filles pour les différents types de toits. class BatimentQuadToit: public Chose { private : - Vertex c[4]; + Quad c; int height; public : - BatimentQuadToit(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height); - virtual ~BatimentQuadToit(); - virtual bool split(); + BatimentQuadToit(Quad c, int height); virtual void triangulation(); - Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); virtual void getBoundingBoxPoints(); }; diff --git a/rules/chose.cpp b/rules/chose.cpp @@ -3,6 +3,12 @@ Chose::Chose() : seed(initialSeed), children() { } +// TODO : Est-ce vraiment nécessaire ? +Chose::~Chose() { + children.clear(); + triangles.clear(); +} + void Chose::addChild(Chose* c) { children.push_back(c); } @@ -22,6 +28,10 @@ void Chose::addQuad(Vertex u, Vertex v, Vertex w, Vertex x, char r, char g, char this->addTriangle(new GPUTriangle(w,v,u,r,g,b)); } +void Chose::addQuad(Quad q, char r, char g, char b) { + addQuad(q[NE], q[SE], q[SW], q[NW], r, g, b); +} + void Chose::addOcto(Vertex a, Vertex b, Vertex c, Vertex d, Vertex e, Vertex f, Vertex g, Vertex h, char red, char green, char blue) { this->addQuad(a,b,c,d,red,green,blue); @@ -32,6 +42,10 @@ void Chose::addOcto(Vertex a, Vertex b, Vertex c, Vertex d, this->addQuad(a,d,h,e,red,green,blue); } +void Chose::addOcto(Quad q1, Quad q2, char red, char green, char blue) { + addOcto(q1[NE], q1[SE], q1[SW], q1[NW], q2[NE], q2[SE], q2[SW], q2[NW], red, green, blue); +} + void Chose::display() { if (children.size() > 0) { std::vector<Chose*>::iterator it; @@ -46,7 +60,7 @@ void Chose::display() { } } -void Chose::addBBPoint(Vertex v) { +void Chose::addBBPoint(const Vertex v) { if (lod.firstBBPoint) { lod.firstBBPoint = false; lod.aabb[0] = v.x; @@ -65,6 +79,19 @@ void Chose::addBBPoint(Vertex v) { } } +void Chose::addBBPoints(const Triangle t) { + addBBPoint(t[LEFT]); + addBBPoint(t[TOP]); + addBBPoint(t[RIGHT]); +} + +void Chose::addBBPoints(const Quad q) { + addBBPoint(q[NE]); + addBBPoint(q[SE]); + addBBPoint(q[SW]); + addBBPoint(q[NW]); +} + void Chose::updateAABB() { lod.firstBBPoint = true; getBoundingBoxPoints(); diff --git a/rules/chose.hh b/rules/chose.hh @@ -15,15 +15,18 @@ class Chose { public : void display(); void drawAABB(); // DEBUG - virtual bool split() = 0; + virtual bool split() { return false; }; virtual bool merge(); - virtual void triangulation() = 0; + virtual void triangulation() { triangles.clear(); }; virtual void updateAABB(); protected : - void addBBPoint(Vertex v); + void addBBPoint(const Vertex v); + void addBBPoints(const Triangle t); + void addBBPoints(const Quad q); virtual void getBoundingBoxPoints() = 0; Chose(); + ~Chose(); inline void addEntropy(unsigned int x1) { seed = hash2(seed, x1); } @@ -48,10 +51,18 @@ class Chose { inline void addEntropy(Vertex v1, Vertex v2, Vertex v3, Vertex v4) { addEntropy(v1, v2); addEntropy(v3, v4); } + inline void addEntropy(Quad q) { + addEntropy(q[NE], q[SE], q[SW], q[NW]); + } + inline void addEntropy(Triangle t) { + addEntropy(t[LEFT], t[TOP], t[RIGHT]); + } void addChild(Chose* c); void addTriangle(GPUTriangle* t); void addQuad(Vertex u, Vertex v, Vertex w, Vertex x, char r, char g, char b); + void addQuad(Quad q, char r, char g, char b); void addOcto(Vertex a,Vertex b,Vertex c,Vertex d,Vertex e,Vertex f,Vertex g,Vertex h,char red,char green,char blue); + void addOcto(Quad q1, Quad q2, char red, char green, char blue); }; #endif diff --git a/rules/quartier/quartierquad.cpp b/rules/quartier/quartierquad.cpp @@ -1,51 +1,35 @@ #include "all_includes.hh" -QuartierQuad::QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { - addEntropy(ne, se, sw, nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; -} - -QuartierQuad::~QuartierQuad() { - children.clear(); - triangles.clear(); +QuartierQuad::QuartierQuad(Quad c) : Chose(), c(c) { + addEntropy(c); } void QuartierQuad::getBoundingBoxPoints() { - addBBPoint(c[NE]); - addBBPoint(c[SE]); - addBBPoint(c[SW]); - addBBPoint(c[NW]); - addBBPoint(c[NE] + Vertex(0,0,1000)); // TODO - addBBPoint(c[SE] + Vertex(0,0,1000)); - addBBPoint(c[SW] + Vertex(0,0,1000)); - addBBPoint(c[NW] + Vertex(0,0,1000)); + addBBPoints(c); + addBBPoints(c + Vertex(0,0,1000)); } -Chose* QuartierQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw) { - Quad q = Quad(ne,se,sw,nw); - bool small = q.minLength() < 2500; - bool big = q.maxLength() >= 5000; - bool anglesAcceptable = q.minAngle() > Angle::d2r(90-60) && q.maxAngle() < Angle::d2r(90+60); - bool anglesOk = q.minAngle() > Angle::d2r(90-40) && q.maxAngle() < Angle::d2r(90+40); - bool tooWideX = q.minLengthEW() * 2 < q.maxLengthNS(); // trop allongé (côté E ou W deux fois plus petit que le côté N ou S). - bool tooWideY = q.minLengthNS() * 2 < q.maxLengthEW(); // trop allongé (côté N ou S deux fois plus petit que le côté E ou W). +Chose* QuartierQuad::factory(int seed, int n, Quad c) { + bool small = c.minLength() < 2500; + bool big = c.maxLength() >= 5000; + bool anglesAcceptable = c.minAngle() > Angle::d2r(90-60) && c.maxAngle() < Angle::d2r(90+60); + bool anglesOk = c.minAngle() > Angle::d2r(90-40) && c.maxAngle() < Angle::d2r(90+40); + bool tooWideX = c.minLengthEW() * 2 < c.maxLengthNS(); // trop allongé (côté E ou W deux fois plus petit que le côté N ou S). + bool tooWideY = c.minLengthNS() * 2 < c.maxLengthEW(); // trop allongé (côté N ou S deux fois plus petit que le côté E ou W). if (!big && proba(seed, n, 1, 20)) { - return new TerrainQuadHerbe(ne, se, sw, nw); + return new TerrainQuadHerbe(c); } else if (small && anglesAcceptable) { - return new BatimentQuad(ne, se, sw, nw, N); + return new BatimentQuad(c, N); } else if (!small && !anglesOk) { - return new QuartierQuadAngle(ne, se, sw, nw); + return new QuartierQuadAngle(c); } else if (!small && tooWideY) { - return new QuartierQuadRect(nw, ne, se, sw); + return new QuartierQuadRect(Quad(c[NW], c[NE], c[SE], c[SW])); } else if (!small && tooWideX) { - return new QuartierQuadRect(ne, se, sw, nw); + return new QuartierQuadRect(c); } else if (!small) { - return new QuartierQuadCarre(ne, se, sw, nw); + return new QuartierQuadCarre(c); } else { - return new TerrainQuadHerbe(ne, se, sw, nw); + return new TerrainQuadHerbe(c); } } diff --git a/rules/quartier/quartierquad.hh b/rules/quartier/quartierquad.hh @@ -6,13 +6,12 @@ class QuartierQuad : public Chose { public: - Vertex c[4]; + Quad c; public: - QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual ~QuartierQuad(); + QuartierQuad(Quad c); virtual bool split(); virtual void triangulation(); - static Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); + static Chose* factory(int seed, int n, Quad c); virtual void getBoundingBoxPoints(); }; diff --git a/rules/quartier/quartierquadangle.cpp b/rules/quartier/quartierquadangle.cpp @@ -1,11 +1,6 @@ #include "all_includes.hh" -QuartierQuadAngle::QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) { -} - -QuartierQuadAngle::~QuartierQuadAngle() { - children.clear(); - triangles.clear(); +QuartierQuadAngle::QuartierQuadAngle(Quad c) : QuartierQuad(c) { } bool QuartierQuadAngle::split() { @@ -15,11 +10,11 @@ bool QuartierQuadAngle::split() { t1.offsetBase(-hrw); Triangle t2(c[SW+i], c[NW+i], c[NE+i]); t2.offsetBase(-hrw); - addChild(QuartierTri::factory(seed, 0, t1.c[0], t1.c[1], t1.c[2])); - addChild(QuartierTri::factory(seed, 1, t2.c[0], t2.c[1], t2.c[2])); - addChild(new RouteQuadChaussee(t1.c[0], t1.c[2], t2.c[0], t2.c[2])); - addChild(new RouteTriChaussee(t1.c[0], c[NE+i], t2.c[2])); - addChild(new RouteTriChaussee(t2.c[0], c[SW+i], t1.c[2])); + addChild(QuartierTri::factory(seed, 0, t1)); + addChild(QuartierTri::factory(seed, 1, t2)); + addChild(new RouteQuadChaussee(Quad(t1[LEFT], t1[RIGHT], t2[LEFT], t2[RIGHT]))); + addChild(new RouteTriChaussee(Triangle(t1[LEFT], c[NE+i], t2[RIGHT]))); + addChild(new RouteTriChaussee(Triangle(t2[LEFT], c[SW+i], t1[RIGHT]))); return true; } } @@ -34,27 +29,27 @@ bool QuartierQuadAngle::split() { Quad q; if (tn.minAngle() > te.minAngle()) { q = Quad(n, c[SE+i], c[SW+i], c[NW+i]); - Vertex oldtnc2 = tn.c[2]; + Vertex oldtnright = tn[RIGHT]; tn.offsetBase(-hrw); q.offset(E, -hrw); - addChild(QuartierTri::factory(seed, 0, tn.c[0], tn.c[1], tn.c[2])); - addChild(QuartierQuad::factory(seed, 1, q.c[0], q.c[1], q.c[2], q.c[3])); - addChild(new RouteQuadChaussee(tn.c[0], tn.c[2], q.c[1], q.c[0])); - addChild(new RouteTriChaussee(q.c[1], oldtnc2, tn.c[2])); + addChild(QuartierTri::factory(seed, 0, tn)); + addChild(QuartierQuad::factory(seed, 1, q)); + addChild(new RouteQuadChaussee(Quad(tn[LEFT], tn[RIGHT], q[SE], q[NE]))); + addChild(new RouteTriChaussee(Triangle(q[SE], oldtnright, tn[RIGHT]))); } else { q = Quad(c[NW+i], e, c[SE+i], c[SW+i]); - Vertex oldtec0 = te.c[0]; + Vertex oldteleft = te[LEFT]; te.offsetBase(-hrw); q.offset(E, -hrw); - addChild(QuartierTri::factory(seed, 0, te.c[0], te.c[1], te.c[2])); - addChild(QuartierQuad::factory(seed, 1, q.c[0], q.c[1], q.c[2], q.c[3])); - addChild(new RouteQuadChaussee(te.c[0], te.c[2], q.c[1], q.c[0])); - addChild(new RouteTriChaussee(te.c[0], oldtec0, q.c[0])); + addChild(QuartierTri::factory(seed, 0, te)); + addChild(QuartierQuad::factory(seed, 1, q)); + addChild(new RouteQuadChaussee(Quad(te[LEFT], te[RIGHT], q[SE], q[NE]))); + addChild(new RouteTriChaussee(Triangle(te[LEFT], oldteleft, q[NE]))); } return true; } } // Ne devait jamais arriver ici ! - addChild(new TerrainQuadHerbe(c[NE], c[SE], c[SW], c[NW])); + addChild(new TerrainQuadHerbe(c)); return true; } diff --git a/rules/quartier/quartierquadangle.hh b/rules/quartier/quartierquadangle.hh @@ -6,11 +6,10 @@ // QuadAngle est un quadrilatère avec des angles malfichus (< 90-40 ou > 90+40). class QuartierQuadAngle : public QuartierQuad { private : - static const int hrw = 150; // half road width : 2,50m. + static const int hrw = 150; // half road width : 1,50m. public : - QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual ~QuartierQuadAngle(); + QuartierQuadAngle(Quad c); virtual bool split(); private : diff --git a/rules/quartier/quartierquadcarre.cpp b/rules/quartier/quartierquadcarre.cpp @@ -1,11 +1,6 @@ #include "all_includes.hh" -QuartierQuadCarre::QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) { -} - -QuartierQuadCarre::~QuartierQuadCarre() { - children.clear(); - triangles.clear(); +QuartierQuadCarre::QuartierQuadCarre(Quad c) : QuartierQuad(c) { } bool QuartierQuadCarre::split() { @@ -23,10 +18,10 @@ bool QuartierQuadCarre::split() { q[i] = Quad(c[NE+i], middle[E+i], center, middle[N+i]); q[i].offset(W,-hrw); q[i].offset(S,-hrw); } - addChild(new RouteQuadCarrefour(q[0].c[SW], q[1].c[SW], q[2].c[SW], q[3].c[SW])); + addChild(new RouteQuadCarrefour(Quad(q[0][SW], q[1][SW], q[2][SW], q[3][SW]))); for (int i = 0; i < 4; i++) { - addChild(new RouteQuadChaussee(q[NE+i].c[NW], q[NE+i].c[SW], q[NW+i].c[SW], q[NW+i].c[SE])); - addChild(QuartierQuad::factory(seed, 4+i, q[i].c[0], q[i].c[1], q[i].c[2], q[i].c[3])); + addChild(new RouteQuadChaussee(Quad(q[NE+i][NW], q[NE+i][SW], q[NW+i][SW], q[NW+i][SE]))); + addChild(QuartierQuad::factory(seed, 4+i, q[i])); } return true; } diff --git a/rules/quartier/quartierquadcarre.hh b/rules/quartier/quartierquadcarre.hh @@ -9,8 +9,7 @@ class QuartierQuadCarre : public QuartierQuad { static const int hrw = 250; // half road width : 2,50m. public : - QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual ~QuartierQuadCarre(); + QuartierQuadCarre(Quad c); virtual bool split(); }; diff --git a/rules/quartier/quartierquadrect.cpp b/rules/quartier/quartierquadrect.cpp @@ -1,11 +1,6 @@ #include "all_includes.hh" -QuartierQuadRect::QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) { -} - -QuartierQuadRect::~QuartierQuadRect() { - children.clear(); - triangles.clear(); +QuartierQuadRect::QuartierQuadRect(Quad c) : QuartierQuad(c) { } bool QuartierQuadRect::split() { @@ -17,8 +12,8 @@ bool QuartierQuadRect::split() { qe.offset(W,-hrw); qw.offset(W,-hrw); - addChild(new RouteQuadChaussee(qe.c[NW], qe.c[SW], qw.c[NW], qw.c[SW])); - addChild(QuartierQuad::factory(seed, 2, qe.c[0], qe.c[1], qe.c[2], qe.c[3])); - addChild(QuartierQuad::factory(seed, 3, qw.c[0], qw.c[1], qw.c[2], qw.c[3])); + addChild(new RouteQuadChaussee(Quad(qe[NW], qe[SW], qw[NW], qw[SW]))); + addChild(QuartierQuad::factory(seed, 2, qe)); + addChild(QuartierQuad::factory(seed, 3, qw)); return true; } diff --git a/rules/quartier/quartierquadrect.hh b/rules/quartier/quartierquadrect.hh @@ -9,8 +9,7 @@ class QuartierQuadRect : public QuartierQuad { static const int hrw = 250; // half road width : 2,50m. public : - QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual ~QuartierQuadRect(); + QuartierQuadRect(Quad c); virtual bool split(); }; diff --git a/rules/quartier/quartiertri.cpp b/rules/quartier/quartiertri.cpp @@ -1,31 +1,19 @@ #include "all_includes.hh" -QuartierTri::QuartierTri(Vertex left, Vertex top, Vertex right) : Chose() { - addEntropy(left, top, right); - c[0] = left; - c[1] = top; - c[2] = right; -} - -QuartierTri::~QuartierTri() { - children.clear(); - triangles.clear(); +QuartierTri::QuartierTri(Triangle c) : Chose(), c(c) { + addEntropy(c); } void QuartierTri::getBoundingBoxPoints() { - addBBPoint(c[0]); - addBBPoint(c[1]); - addBBPoint(c[2]); - addBBPoint(c[0] + Vertex(0,0,1000)); // TODO - addBBPoint(c[1] + Vertex(0,0,1000)); - addBBPoint(c[2] + Vertex(0,0,1000)); + addBBPoints(c); + addBBPoints(c + Vertex(0,0,1000)); // TODO } -Chose* QuartierTri::factory(int seed, int n, Vertex left, Vertex top, Vertex right) { +Chose* QuartierTri::factory(int seed, int n, Triangle c) { (void)seed; (void)n; // TODO - return new QuartierTri(left, top, right); + return new QuartierTri(c); } bool QuartierTri::split() { @@ -34,5 +22,5 @@ bool QuartierTri::split() { void QuartierTri::triangulation() { triangles.reserve(1); - addTriangle(new GPUTriangle(c[0], c[1], c[2], 0xf0, 0xc0, 0xc0)); + addTriangle(new GPUTriangle(c[LEFT], c[TOP], c[RIGHT], 0xf0, 0xc0, 0xc0)); } diff --git a/rules/quartier/quartiertri.hh b/rules/quartier/quartiertri.hh @@ -6,14 +6,13 @@ class QuartierTri : public Chose { public : - Vertex c[3]; + Triangle c; public : - QuartierTri(Vertex left, Vertex top, Vertex right); - virtual ~QuartierTri(); + QuartierTri(Triangle c); virtual bool split(); virtual void triangulation(); - static Chose* factory(int seed, int n, Vertex left, Vertex top, Vertex right); + static Chose* factory(int seed, int n, Triangle c); virtual void getBoundingBoxPoints(); }; diff --git a/rules/quartier/quartiertrihauteur.cpp b/rules/quartier/quartiertrihauteur.cpp @@ -1,19 +1,19 @@ #include "all_includes.hh" -QuartierTriHauteur::QuartierTriHauteur(Vertex left, Vertex top, Vertex right) : QuartierTri(left, top, right) { +QuartierTriHauteur::QuartierTriHauteur(Triangle c) : QuartierTri(c) { } bool QuartierTriHauteur::split() { - Vertex baseCenter = Segment(c[0], c[2]).randomPos(seed, 0, 33, 67); + Vertex baseCenter = Segment(c[LEFT], c[RIGHT]).randomPos(seed, 0, 33, 67); - Triangle tl = Triangle(baseCenter, c[0], c[1]); - Triangle tr = Triangle(c[1], c[2], baseCenter); + Triangle tl = Triangle(baseCenter, c[LEFT], c[TOP]); + Triangle tr = Triangle(c[TOP], c[RIGHT], baseCenter); tl.offsetBase(-hrw); tr.offsetBase(-hrw); - addChild(new RouteQuadChaussee(tr.c[0], tr.c[2], tl.c[0], tl.c[2])); - addChild(new RouteTriChaussee(tl.c[2], c[1], tr.c[0])); - addChild(QuartierTri::factory(seed, 1, tl.c[2], tl.c[0], tl.c[1])); - addChild(QuartierTri::factory(seed, 2, tr.c[1], tr.c[2], tr.c[0])); + addChild(new RouteQuadChaussee(Quad(tr[LEFT], tr[RIGHT], tl[LEFT], tl[RIGHT]))); + addChild(new RouteTriChaussee(Triangle(tl[RIGHT], c[TOP], tr[LEFT]))); + addChild(QuartierTri::factory(seed, 1, tl >> 1)); + addChild(QuartierTri::factory(seed, 2, tr << 1)); return true; } diff --git a/rules/quartier/quartiertrihauteur.hh b/rules/quartier/quartiertrihauteur.hh @@ -8,7 +8,7 @@ class QuartierTriHauteur : public QuartierTri { static const int hrw = 250; // half road width : 2,50m. public : - QuartierTriHauteur(Vertex left, Vertex top, Vertex right); + QuartierTriHauteur(Triangle c); virtual bool split(); }; diff --git a/rules/route/routequadcarrefour.cpp b/rules/route/routequadcarrefour.cpp @@ -1,35 +1,14 @@ #include "all_includes.hh" -RouteQuadCarrefour::RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { - addEntropy(ne,se,sw,nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; -} - -RouteQuadCarrefour::~RouteQuadCarrefour() { - children.clear(); - triangles.clear(); +RouteQuadCarrefour::RouteQuadCarrefour(Quad c) : Chose(), c(c) { + addEntropy(c); } void RouteQuadCarrefour::getBoundingBoxPoints() { - addBBPoint(c[NE]); - addBBPoint(c[SE]); - addBBPoint(c[SW]); - addBBPoint(c[NW]); - addBBPoint(c[NE] + Vertex(0,0,1000)); // TODO - addBBPoint(c[SE] + Vertex(0,0,1000)); - addBBPoint(c[SW] + Vertex(0,0,1000)); - addBBPoint(c[NW] + Vertex(0,0,1000)); -} - -bool RouteQuadCarrefour::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,1000)); // TODO } void RouteQuadCarrefour::triangulation() { - triangles.reserve(2); - addTriangle(new GPUTriangle(c[NE], c[NW], c[SW], 0x36, 0x36, 0x36)); - addTriangle(new GPUTriangle(c[SW], c[SE], c[NE], 0x36, 0x36, 0x36)); + addQuad(c, 0x36, 0x36, 0x36); } diff --git a/rules/route/routequadcarrefour.hh b/rules/route/routequadcarrefour.hh @@ -5,12 +5,10 @@ class RouteQuadCarrefour : public Chose { private : - Vertex c[4]; + Quad c; public : - RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual ~RouteQuadCarrefour(); - virtual bool split(); + RouteQuadCarrefour(Quad c); virtual void triangulation(); virtual void getBoundingBoxPoints(); }; diff --git a/rules/route/routequadchaussee.cpp b/rules/route/routequadchaussee.cpp @@ -1,35 +1,14 @@ #include "all_includes.hh" -RouteQuadChaussee::RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { - addEntropy(ne,se,sw,nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; -} - -RouteQuadChaussee::~RouteQuadChaussee() { - children.clear(); - triangles.clear(); +RouteQuadChaussee::RouteQuadChaussee(Quad c) : Chose(), c(c) { + addEntropy(c); } void RouteQuadChaussee::getBoundingBoxPoints() { - addBBPoint(c[NE]); - addBBPoint(c[SE]); - addBBPoint(c[SW]); - addBBPoint(c[NW]); - addBBPoint(c[NE] + Vertex(0,0,1000)); // TODO - addBBPoint(c[SE] + Vertex(0,0,1000)); - addBBPoint(c[SW] + Vertex(0,0,1000)); - addBBPoint(c[NW] + Vertex(0,0,1000)); -} - -bool RouteQuadChaussee::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,1000)); // TODO } void RouteQuadChaussee::triangulation() { - triangles.reserve(2); - addTriangle(new GPUTriangle(c[NE], c[NW], c[SW], 0x36, 0x36, 0x36)); - addTriangle(new GPUTriangle(c[SW], c[SE], c[NE], 0x36, 0x36, 0x36)); + addQuad(c, 0x36, 0x36, 0x36); } diff --git a/rules/route/routequadchaussee.hh b/rules/route/routequadchaussee.hh @@ -5,12 +5,10 @@ class RouteQuadChaussee : public Chose { private : - Vertex c[4]; + Quad c; public : - RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual ~RouteQuadChaussee(); - virtual bool split(); + RouteQuadChaussee(Quad c); virtual void triangulation(); virtual void getBoundingBoxPoints(); }; diff --git a/rules/route/routetrichaussee.cpp b/rules/route/routetrichaussee.cpp @@ -1,26 +1,14 @@ #include "all_includes.hh" -RouteTriChaussee::RouteTriChaussee(Vertex left, Vertex top, Vertex right) : Chose() { - addEntropy(left, top, right); - c[0] = left; - c[1] = top; - c[2] = right; +RouteTriChaussee::RouteTriChaussee(Triangle c) : Chose(), c(c) { + addEntropy(c); } void RouteTriChaussee::getBoundingBoxPoints() { - addBBPoint(c[0]); - addBBPoint(c[1]); - addBBPoint(c[2]); - addBBPoint(c[0] + Vertex(0,0,1000)); // TODO - addBBPoint(c[1] + Vertex(0,0,1000)); - addBBPoint(c[2] + Vertex(0,0,1000)); -} - -bool RouteTriChaussee::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,1000)); // TODO } void RouteTriChaussee::triangulation() { - triangles.reserve(1); - addTriangle(new GPUTriangle(c[0], c[1], c[2], 0x36, 0x36, 0x36)); + addTriangle(new GPUTriangle(c[LEFT], c[TOP], c[RIGHT], 0x36, 0x36, 0x36)); } diff --git a/rules/route/routetrichaussee.hh b/rules/route/routetrichaussee.hh @@ -5,11 +5,10 @@ class RouteTriChaussee : public Chose { private : - Vertex c[3]; + Triangle c; public : - RouteTriChaussee(Vertex left, Vertex top, Vertex right); - virtual bool split(); + RouteTriChaussee(Triangle c); virtual void triangulation(); virtual void getBoundingBoxPoints(); }; diff --git a/rules/route/trottoirquadnormal.cpp b/rules/route/trottoirquadnormal.cpp @@ -1,34 +1,11 @@ #include "all_includes.hh" -TrottoirQuadNormal::TrottoirQuadNormal(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height, Cardinal border) { - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; - this->height = height; - this->border = border; - // TODO : pas besoin de ce champ : il suffit d'orienter - // correctement le trottoir lorsqu'on le crée. -} - -TrottoirQuadNormal::~TrottoirQuadNormal() { - children.clear(); - triangles.clear(); +TrottoirQuadNormal::TrottoirQuadNormal(Quad c, int height, Cardinal border) : Chose(), c(c), height(height), border(border) { } 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() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,height)); // TODO } void TrottoirQuadNormal::triangulation() { @@ -39,7 +16,7 @@ void TrottoirQuadNormal::triangulation() { q.offset(E,-15); addTriangle(new GPUTriangle(q.c[0] + h, q.c[3] + h, q.c[2] + h, 0x66, 0x66, 0x66)); addTriangle(new GPUTriangle(q.c[2] + h, q.c[1] + h, q.c[0] + h, 0x66, 0x66, 0x66)); - addTriangle(new GPUTriangle(c[NE] + h,q.c[0] + h, q.c[1] + h, 0xAA, 0xAA, 0xAA)); + addTriangle(new GPUTriangle(c[NE] + h, q.c[0] + h, q.c[1] + h, 0xAA, 0xAA, 0xAA)); addTriangle(new GPUTriangle(q.c[1] + h, c[SE] + h, c[NE] + h, 0xAA, 0xAA, 0xAA)); addTriangle(new GPUTriangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66)); @@ -51,8 +28,7 @@ void TrottoirQuadNormal::triangulation() { addTriangle(new GPUTriangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66)); addTriangle(new GPUTriangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66)); addTriangle(new GPUTriangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66)); - } - else { + } else { addTriangle(new GPUTriangle(q.c[0] + h, q.c[3] + h, q.c[2] + h, 0x66, 0x66, 0x66)); addTriangle(new GPUTriangle(q.c[2] + h, q.c[1] + h, q.c[0] + h, 0x66, 0x66, 0x66)); diff --git a/rules/route/trottoirquadnormal.hh b/rules/route/trottoirquadnormal.hh @@ -5,14 +5,14 @@ class TrottoirQuadNormal : public Chose { private : - Vertex c[4]; + Quad c; int height; + // TODO : pas besoin de ce champ : il suffit d'orienter + // correctement le trottoir lorsqu'on le crée. Cardinal border; public : - TrottoirQuadNormal(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height, Cardinal border); - virtual ~TrottoirQuadNormal(); - virtual bool split(); + TrottoirQuadNormal(Quad c, int height, Cardinal border); virtual void triangulation(); virtual void getBoundingBoxPoints(); }; diff --git a/rules/terrain/terrainquadherbe.cpp b/rules/terrain/terrainquadherbe.cpp @@ -1,26 +1,12 @@ #include "all_includes.hh" -TerrainQuadHerbe::TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() { - addEntropy(ne, se, sw, nw); - c[NE] = ne; - c[SE] = se; - c[SW] = sw; - c[NW] = nw; +TerrainQuadHerbe::TerrainQuadHerbe(Quad c) : Chose(), c(c) { + addEntropy(c); } void TerrainQuadHerbe::getBoundingBoxPoints() { - addBBPoint(c[NE]); - addBBPoint(c[SE]); - addBBPoint(c[SW]); - addBBPoint(c[NW]); - addBBPoint(c[NE] + Vertex(0,0,1000)); // TODO - addBBPoint(c[SE] + Vertex(0,0,1000)); - addBBPoint(c[SW] + Vertex(0,0,1000)); - addBBPoint(c[NW] + Vertex(0,0,1000)); -} - -bool TerrainQuadHerbe::split() { - return false; + addBBPoints(c); + addBBPoints(c + Vertex(0,0,1000)); // TODO } void TerrainQuadHerbe::triangulation() { diff --git a/rules/terrain/terrainquadherbe.hh b/rules/terrain/terrainquadherbe.hh @@ -6,11 +6,10 @@ class TerrainQuadHerbe : public Chose { private : - Vertex c[4]; + Quad c; public : - TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw); - virtual bool split(); + TerrainQuadHerbe(Quad c); virtual void triangulation(); virtual void getBoundingBoxPoints(); };