www

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

commit 6b3bb44a4ae9881417ee191ff529a5069a2da90e
parent 01824d8c12efeb3e6e94a511a6136cdd9544ec65
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Wed, 21 Dec 2011 16:40:49 +0100

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

Conflicts:
	rules/batiment/batimentquad.cpp
	rules/batiment/batimentquadjardin.cpp
	rules/batiment/batimentquadmaison.cpp
	rules/chose.hh

Diffstat:
Mall_includes.hh | 3+++
Mmain.cpp | 1+
Mquad.cpp | 27+++++++++++++++++++++++++++
Mquad.hh | 1+
Mrules/batiment/batimentquad.cpp | 89+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mrules/batiment/batimentquad.hh | 2+-
Mrules/batiment/batimentquadmaison.cpp | 8++++----
Arules/batiment/batimentquadmaisonblock.cpp | 46++++++++++++++++++++++++++++++++++++++++++++++
Arules/batiment/batimentquadmaisonblock.hh | 27+++++++++++++++++++++++++++
Arules/batiment/batimentquadmaisonpont.cpp | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arules/batiment/batimentquadmaisonpont.hh | 27+++++++++++++++++++++++++++
Arules/batiment/batimentquadpont.cpp | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arules/batiment/batimentquadpont.hh | 27+++++++++++++++++++++++++++
Mrules/chose.cpp | 15+++++++++++++++
Mrules/chose.hh | 2++
Msegment.cpp | 7++++++-
Msegment.hh | 5+++--
17 files changed, 448 insertions(+), 53 deletions(-)

diff --git a/all_includes.hh b/all_includes.hh @@ -35,6 +35,9 @@ class Chose; #include "rules/batiment/batimentquad.hh" #include "rules/batiment/batimentquadmaison.hh" #include "rules/batiment/batimentquadjardin.hh" +#include "rules/batiment/batimentquadpont.hh" +#include "rules/batiment/batimentquadmaisonpont.hh" +#include "rules/batiment/batimentquadmaisonblock.hh" #include "rules/quartier/quartierquad.hh" #include "rules/quartier/quartierquadangle.hh" diff --git a/main.cpp b/main.cpp @@ -26,6 +26,7 @@ int main() { Vertex se(size, 0, 0); Vertex sw(0, 0, 0); Vertex nw(0, size, 0); + Chose::initialSeed = 1889676033; Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw); c->triangulation(); c->updateAABB(); diff --git a/quad.cpp b/quad.cpp @@ -22,6 +22,33 @@ void Quad::offsetNESW(int offsetN, int offsetE, int offsetS, int offsetW) { this->offset(W,offsetW); } +Quad Quad::makeParallelogram() { + int l1, l2; + + if(Segment(corner[NW],corner[NE]).length() < Segment(corner[SE],corner[SW]).length()) { + if((l1 = Segment(corner[NE],corner[SE]).length()) < (l2 = Segment(corner[SW],corner[NW]).length())) { + corner[SW] = Segment(corner[NW],corner[SW]).reduce(l1).v; + corner[SE] = corner[SW] + (corner[NE] - corner[NW]); + } + else if((l1 = Segment(corner[NE],corner[SE]).length()) > (l2 = Segment(corner[SW],corner[NW]).length())) { + corner[SE] = Segment(corner[NE],corner[SE]).reduce(l2).v; + corner[SW] = corner[SE] + (corner[NW] - corner[NE]); + } + } + else { + if((l1 = Segment(corner[NE],corner[SE]).length()) < (l2 = Segment(corner[SW],corner[NW]).length())) { + corner[NW] = Segment(corner[SW],corner[NW]).reduce(l1).v; + corner[NE] = corner[NW] + (corner[SE] - corner[SW]); + } + else if((l1 = Segment(corner[NE],corner[SE]).length()) > (l2 = Segment(corner[SW],corner[NW]).length())) { + corner[NE] = Segment(corner[SE],corner[NE]).reduce(l2).v; + corner[NW] = corner[NE] + (corner[SW] - corner[SE]); + } + } + + return Quad(corner[0],corner[1],corner[2],corner[3]); +} + int Quad::minLengthNS() { return std::min( Segment(corner[NW],corner[NE]).length(), diff --git a/quad.hh b/quad.hh @@ -21,6 +21,7 @@ class Quad { int maxLength(); float minAngle(); float maxAngle(); + Quad makeParallelogram(); }; diff --git a/rules/batiment/batimentquad.cpp b/rules/batiment/batimentquad.cpp @@ -4,10 +4,10 @@ BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal addEntropy(ne, se, sw, nw); this->entry = entry; lctr = (ne + se + sw + nw) / 4; - corner[NE] = ne;//-lctr; - corner[SE] = se;//-lctr; - corner[SW] = sw;//-lctr; - corner[NW] = nw;//-lctr; + c[NE] = ne;//-lctr; + c[SE] = se;//-lctr; + c[SW] = sw;//-lctr; + c[NW] = nw;//-lctr; } BatimentQuad::~BatimentQuad() { @@ -16,39 +16,48 @@ BatimentQuad::~BatimentQuad() { } void BatimentQuad::getBoundingBoxPoints() { - addBBPoint(corner[NE]); - addBBPoint(corner[SE]); - addBBPoint(corner[SW]); - addBBPoint(corner[NW]); - addBBPoint(corner[NE] + Vertex(0,0,maxHeight + maxHeight/2)); // TODO - addBBPoint(corner[SE] + Vertex(0,0,maxHeight + maxHeight/2)); - addBBPoint(corner[SW] + Vertex(0,0,maxHeight + maxHeight/2)); - addBBPoint(corner[NW] + Vertex(0,0,maxHeight + maxHeight/2)); + 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 BatimentQuad::split() { - int th = 20; // Terrain height. - Quad q = Quad(corner[NE],corner[SE],corner[SW],corner[NW]); - q.offset(N,-140); - q.offset(E,-140); - q.offset(S,-140); - q.offset(W,-140); + int rand = this->seed % 20; // TODO : utiliser les fonctions random in range & co. - addChild(new TrottoirQuadNormal(/*lctr+*/corner[NE],/*lctr+*/corner[SE],/*lctr+*/q.corner[1],/*lctr+*/q.corner[0],th,E)); - addChild(new TrottoirQuadNormal(/*lctr+*/corner[SE],/*lctr+*/corner[SW],/*lctr+*/q.corner[2],/*lctr+*/q.corner[1],th,E)); - addChild(new TrottoirQuadNormal(/*lctr+*/corner[SW],/*lctr+*/corner[NW],/*lctr+*/q.corner[3],/*lctr+*/q.corner[2],th,E)); - addChild(new TrottoirQuadNormal(/*lctr+*/corner[NW],/*lctr+*/corner[NE],/*lctr+*/q.corner[0],/*lctr+*/q.corner[3],th,E)); + if(rand <= 2) { + Quad q = Quad(c[NE],c[SE],c[SW],c[NW]).makeParallelogram(); + addChild(new BatimentQuadMaisonPont(q.corner[0],q.corner[1],q.corner[2],q.corner[3],800)); + } + else if(rand <= 15) { + int th = 20; // Terrain height. + Quad q = Quad(c[NE],c[SE],c[SW],c[NW]); + th = th; + q.offset(N,-140); + q.offset(E,-140); + q.offset(S,-140); + q.offset(W,-140); - q.corner[0] = q.corner[0] + Vertex(0,0,th); - q.corner[1] = q.corner[1] + Vertex(0,0,th); - q.corner[2] = q.corner[2] + Vertex(0,0,th); - q.corner[3] = q.corner[3] + Vertex(0,0,th); + addChild(new TrottoirQuadNormal(c[NE],c[SE],q.corner[1],q.corner[0],th,E)); + addChild(new TrottoirQuadNormal(c[SE],c[SW],q.corner[2],q.corner[1],th,E)); + addChild(new TrottoirQuadNormal(c[SW],c[NW],q.corner[3],q.corner[2],th,E)); + addChild(new TrottoirQuadNormal(c[NW],c[NE],q.corner[0],q.corner[3],th,E)); - addChild(new BatimentQuadJardin(/*lctr+*/q.corner[0],/*lctr+*/q.corner[1],/*lctr+*/q.corner[2],/*lctr+*/q.corner[3])); + q.corner[0] = q.corner[0] + Vertex(0,0,th); + q.corner[1] = q.corner[1] + Vertex(0,0,th); + q.corner[2] = q.corner[2] + Vertex(0,0,th); + q.corner[3] = q.corner[3] + Vertex(0,0,th); - q.offset(this->entry,-400); + addChild(new BatimentQuadJardin(q.corner[0],q.corner[1],q.corner[2],q.corner[3])); - addChild(new BatimentQuadMaison(/*lctr+*/q.corner[0],/*lctr+*/q.corner[1],/*lctr+*/q.corner[2],/*lctr+*/q.corner[3])); + q.offset(this->entry,-400); + + addChild(new BatimentQuadMaison(q.corner[0],q.corner[1],q.corner[2],q.corner[3])); + } return true; } @@ -57,21 +66,11 @@ void BatimentQuad::triangulation() { int h = hashInRange(seed,0,minHeight,maxHeight); int htoit = hashInRange(seed,0,minHeight/2,maxHeight/2); - Vertex neh = corner[NE] + Vertex(0,0,h); - Vertex seh = corner[SE] + Vertex(0,0,h); - Vertex nwh = corner[NW] + Vertex(0,0,h); - Vertex swh = corner[SW] + Vertex(0,0,h); - Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit); - - // 4 Murs - addTriangle(new Triangle(neh,seh,corner[NE],0xf1,0xe3,0xad)); addTriangle(new Triangle(seh,corner[SE],corner[NE],0xf1,0xe3,0xad)); // ne-se-seh-neh - addTriangle(new Triangle(seh,swh,corner[SE],0xf1,0xe3,0xad)); addTriangle(new Triangle(swh,corner[SW],corner[SE],0xf1,0xe3,0xad)); // se-sw-swh-seh - addTriangle(new Triangle(swh,nwh,corner[SW],0xf1,0xe3,0xad)); addTriangle(new Triangle(nwh,corner[NW],corner[SW],0xf1,0xe3,0xad)); // sw-nw-nwh-swh - addTriangle(new Triangle(nwh,neh,corner[NW],0xf1,0xe3,0xad)); addTriangle(new Triangle(neh,corner[NE],corner[NW],0xf1,0xe3,0xad)); // nw-ne-neh-nwh + 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); - // 1 Toit - addTriangle(new Triangle(neh,toit,seh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(seh,toit,swh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(swh,toit,nwh,0x9a,0x48,0x3c)); - addTriangle(new Triangle(nwh,toit,neh,0x9a,0x48,0x3c)); + addOcto(c[NE],c[SE],c[SW],c[NW],neh,seh,swh,nwh,0xFF,0xFF,0x00); } diff --git a/rules/batiment/batimentquad.hh b/rules/batiment/batimentquad.hh @@ -6,7 +6,7 @@ // RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°. class BatimentQuad : public Chose { private : - Vertex corner[4]; + Vertex c[4]; Cardinal entry; public : diff --git a/rules/batiment/batimentquadmaison.cpp b/rules/batiment/batimentquadmaison.cpp @@ -41,10 +41,10 @@ void BatimentQuadMaison::triangulation() { Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit); // 4 Murs - addTriangle(new Triangle(/*lctr+*/neh,/*lctr+*/seh,/*lctr+*/corner[NE],0xf1,0xe3,0xad)); addTriangle(new Triangle(/*lctr+*/seh,/*lctr+*/corner[SE],/*lctr+*/corner[NE],0xf1,0xe3,0xad)); // ne-se-seh-neh - addTriangle(new Triangle(/*lctr+*/seh,/*lctr+*/swh,/*lctr+*/corner[SE],0xf1,0xe3,0xad)); addTriangle(new Triangle(/*lctr+*/swh,/*lctr+*/corner[SW],/*lctr+*/corner[SE],0xf1,0xe3,0xad)); // se-sw-swh-seh - addTriangle(new Triangle(/*lctr+*/swh,/*lctr+*/nwh,/*lctr+*/corner[SW],0xf1,0xe3,0xad)); addTriangle(new Triangle(/*lctr+*/nwh,/*lctr+*/corner[NW],/*lctr+*/corner[SW],0xf1,0xe3,0xad)); // sw-nw-nwh-swh - addTriangle(new Triangle(/*lctr+*/nwh,/*lctr+*/neh,/*lctr+*/corner[NW],0xf1,0xe3,0xad)); addTriangle(new Triangle(/*lctr+*/neh,/*lctr+*/corner[NE],/*lctr+*/corner[NW],0xf1,0xe3,0xad)); // nw-ne-neh-nwh + addQuad(/*lctr+*/neh,/*lctr+*/seh,/*lctr+*/corner[SE],/*lctr+*/corner[NE],0xf1,0xe3,0xad); + addQuad(/*lctr+*/seh,/*lctr+*/swh,/*lctr+*/corner[SW],/*lctr+*/corner[SE],0xf1,0xe3,0xad); + addQuad(/*lctr+*/swh,/*lctr+*/nwh,/*lctr+*/corner[NW],/*lctr+*/corner[SW],0xf1,0xe3,0xad); + addQuad(/*lctr+*/nwh,/*lctr+*/neh,/*lctr+*/corner[NE],/*lctr+*/corner[NW],0xf1,0xe3,0xad); // 1 Toit addTriangle(new Triangle(/*lctr+*/neh,/*lctr+*/toit,/*lctr+*/seh,0x9a,0x48,0x3c)); diff --git a/rules/batiment/batimentquadmaisonblock.cpp b/rules/batiment/batimentquadmaisonblock.cpp @@ -0,0 +1,46 @@ +#include "all_includes.hh" + +BatimentQuadMaisonBlock::BatimentQuadMaisonBlock() { +} + +BatimentQuadMaisonBlock::BatimentQuadMaisonBlock(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() { + addEntropy(ne, se, sw, nw); + lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); + this->ne = ne-lctr; + this->se = se-lctr; + this-> sw = sw-lctr; + this->nw = nw-lctr; + this->height = height; + triangulation(); +} + +BatimentQuadMaisonBlock::~BatimentQuadMaisonBlock() { + children.clear(); + triangles.clear(); +} + +void BatimentQuadMaisonBlock::getBoundingBoxPoints() { + // TODO +} + +bool BatimentQuadMaisonBlock::split() { + return false; +} + +bool BatimentQuadMaisonBlock::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + +void BatimentQuadMaisonBlock::triangulation() { + //triangles.reserve(2); + Vertex seh = se + Vertex(0,0,height); + Vertex swh = sw + Vertex(0,0,height); + Vertex nwh = nw + Vertex(0,0,height); + Vertex neh = ne + Vertex(0,0,height); + + addOcto(lctr+se,lctr+sw,lctr+nw,lctr+ne,lctr+seh,lctr+swh,lctr+nwh,lctr+neh,0xFF,0x36,0x00); +} diff --git a/rules/batiment/batimentquadmaisonblock.hh b/rules/batiment/batimentquadmaisonblock.hh @@ -0,0 +1,27 @@ +#ifndef _RULES_BATIMENTMAISONBLOCK_HH_ +#define _RULES_BATIMENTMAISONBLOCK_HH_ + +#include "all_includes.hh" + +// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°. +class BatimentQuadMaisonBlock : public Chose { + private : + Vertex ne; + Vertex se; + Vertex sw; + Vertex nw; + int height; + + public : + + BatimentQuadMaisonBlock(); + BatimentQuadMaisonBlock(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height); + virtual ~BatimentQuadMaisonBlock(); + virtual bool split(); + virtual bool merge(); + virtual void triangulation(); + Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); + virtual void getBoundingBoxPoints(); +}; + +#endif diff --git a/rules/batiment/batimentquadmaisonpont.cpp b/rules/batiment/batimentquadmaisonpont.cpp @@ -0,0 +1,115 @@ +#include "all_includes.hh" + +BatimentQuadMaisonPont::BatimentQuadMaisonPont() { +} + +BatimentQuadMaisonPont::BatimentQuadMaisonPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() { + addEntropy(ne, se, sw, nw); + lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); + this->ne = ne-lctr; + this->se = se-lctr; + this-> sw = sw-lctr; + this->nw = nw-lctr; + this->height = height; + triangulation(); +} + +BatimentQuadMaisonPont::~BatimentQuadMaisonPont() { + children.clear(); + triangles.clear(); +} + +void BatimentQuadMaisonPont::getBoundingBoxPoints() { + // TODO +} + +bool BatimentQuadMaisonPont::split() { + + Quad q = Quad(ne,se,sw,nw); + q.makeParallelogram(); + if(Segment(q.corner[0],q.corner[3]).length() < Segment(q.corner[0],q.corner[1]).length()) + q = Quad(q.corner[1],q.corner[2],q.corner[3],q.corner[0]); + float partLength = Segment(q.corner[0],q.corner[3]).length() / 3; + int partHeight = 2.5*height/3.; + Quad qa = q; + Quad qb = q; + Quad qc = q; + Quad qh = q; + qa.offset(E,-2*partLength); + qb.offset(W,-2*partLength); + qc.offset(E, -partLength); + qc.offset(W, -partLength); + + se = lctr+qa.corner[0]; + sw = lctr+qa.corner[1]; + nw = lctr+qa.corner[2]; + ne = lctr+qa.corner[3]; + + addChild(new BatimentQuadMaisonBlock(ne,se,sw,nw,partHeight)); + + se = lctr+qb.corner[0]; + sw = lctr+qb.corner[1]; + nw = lctr+qb.corner[2]; + ne = lctr+qb.corner[3]; + + addChild(new BatimentQuadMaisonBlock(ne,se,sw,nw,partHeight)); + + se = lctr+qh.corner[0] + Vertex(0,0,partHeight); + sw = lctr+qh.corner[1] + Vertex(0,0,partHeight); + nw = lctr+qh.corner[2] + Vertex(0,0,partHeight); + ne = lctr+qh.corner[3] + Vertex(0,0,partHeight); + + addChild(new BatimentQuadMaisonBlock(ne,se,sw,nw,partHeight)); + + se = lctr+qc.corner[0]; + sw = lctr+qc.corner[1]; + nw = lctr+qc.corner[2]; + ne = lctr+qc.corner[3]; + + addChild(new BatimentQuadPont(se,sw,nw,ne,partHeight)); +/* + Vertex seh = qh.corner[0] + Vertex(0,0,partHeight); + Vertex swh = qh.corner[1] + Vertex(0,0,partHeight); + Vertex nwh = qh.corner[2] + Vertex(0,0,partHeight); + Vertex neh = qh.corner[3] + Vertex(0,0,partHeight); + + 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.); + + addTriangle(new Triangle(swh,nwh,cw,0xDD,0xDD,0xDD)); + addTriangle(new Triangle(neh,seh,ce,0xDD,0xDD,0xDD)); + + addQuad(neh,nwh,cw,ce,0xE0,0x20,0x00); + addQuad(swh,seh,ce,cw,0xE0,0x20,0x00); +*/ + return true; +} + +bool BatimentQuadMaisonPont::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + +void BatimentQuadMaisonPont::triangulation() { + //triangles.reserve(2); + float h = 2.5*height/3.; + Vertex seh = se + Vertex(0,0,h); + Vertex swh = sw + Vertex(0,0,h); + Vertex nwh = nw + Vertex(0,0,h); + Vertex neh = ne + Vertex(0,0,h); + + addOcto(ne,se,sw,nw,neh,seh,swh,nwh,0xDD,0xDD,0xDD); + + 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.); + + addTriangle(new Triangle(swh,nwh,cw,0xDD,0xDD,0xDD)); + addTriangle(new Triangle(neh,seh,ce,0xDD,0xDD,0xDD)); + + addQuad(neh,nwh,cw,ce,0xE0,0x20,0x00); + addQuad(swh,seh,ce,cw,0xE0,0x20,0x00); + +} diff --git a/rules/batiment/batimentquadmaisonpont.hh b/rules/batiment/batimentquadmaisonpont.hh @@ -0,0 +1,27 @@ +#ifndef _RULES_BATIMENTMAISONPONT_HH_ +#define _RULES_BATIMENTMAISONPONT_HH_ + +#include "all_includes.hh" + +// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°. +class BatimentQuadMaisonPont: public Chose { + private : + Vertex ne; + Vertex se; + Vertex sw; + Vertex nw; + int height; + + public : + + BatimentQuadMaisonPont(); + BatimentQuadMaisonPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height); + virtual ~BatimentQuadMaisonPont(); + virtual bool split(); + virtual bool merge(); + virtual void triangulation(); + Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); + virtual void getBoundingBoxPoints(); +}; + +#endif diff --git a/rules/batiment/batimentquadpont.cpp b/rules/batiment/batimentquadpont.cpp @@ -0,0 +1,99 @@ +#include "all_includes.hh" + +BatimentQuadPont::BatimentQuadPont() { +} + +BatimentQuadPont::BatimentQuadPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() { + addEntropy(ne, se, sw, nw); + lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f); + this->ne = ne-lctr; + this->se = se-lctr; + this-> sw = sw-lctr; + this->nw = nw-lctr; + this->height = height; + triangulation(); +} + +BatimentQuadPont::~BatimentQuadPont() { + children.clear(); + triangles.clear(); +} + +void BatimentQuadPont::getBoundingBoxPoints() { + // TODO ! +} + +bool BatimentQuadPont::split() { + return true; +} + +bool BatimentQuadPont::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + +float ct(float x) { + return -(1.*cosh(x/1.))+1; +} + +float nt(double x, int height) { + return (ct(x) + -ct(-1.7))/(ct(0)+ -ct(-1.7)) * height; +} + +void BatimentQuadPont::triangulation() { + //triangles.reserve(2); + float var; + Quad q = Quad(ne,se,sw,nw); + Vertex a,b; + height -= 20; + Vertex pa = nw; + Vertex pb = sw; + Vertex neh = ne + Vertex(0,0,height+20); + Vertex seh = se + Vertex(0,0,height+20); + Vertex swh = sw + Vertex(0,0,height+20); + Vertex nwh = nw + Vertex(0,0,height+20); + Vertex l1 = ne - nw; + Vertex l2 = sw - se; + + float pas = 0.1; + int steps = (2*1.7/pas); + float n2 = l2.norm()/(2*1.7/pas); + n2=n2; + int middle = steps/2; + int n; + + addTriangle(new Triangle(lctr+pb,lctr+sw,lctr+swh,0xD0,0xD0,0xD0)); + addTriangle(new Triangle(lctr+pa,lctr+nw,lctr+nwh,0xD0,0xD0,0xD0)); + + for(var=-1.7,n=0; var <= 1.7; var+=pas,n++) { + q.offset(W,-n2); + a = q.corner[3] + Vertex(0,0,nt(var,height)); + b = q.corner[2] + Vertex(0,0,nt(var,height)); + + addQuad(lctr+b,lctr+a,lctr+pa,lctr+pb,0xD0,0xD0,0xD0); + + if( n < middle) { + addTriangle(new Triangle(lctr+a,lctr+pa,lctr+nwh,0xD0,0xD0,0xD0)); + addTriangle(new Triangle(lctr+pb,lctr+b,lctr+swh,0xD0,0xD0,0xD0)); + } + else if(n == middle) { + addTriangle(new Triangle(lctr+a,lctr+pa,lctr+nwh,0xD0,0xD0,0xD0)); + addTriangle(new Triangle(lctr+pb,lctr+b,lctr+swh,0xD0,0xD0,0xD0)); + addTriangle(new Triangle(lctr+a,lctr+nwh,lctr+neh,0xD0,0xD0,0xD0)); + addTriangle(new Triangle(lctr+b,lctr+seh,lctr+swh,0xD0,0xD0,0xD0)); + } + else { + addTriangle(new Triangle(lctr+a,lctr+pa,lctr+neh,0xD0,0xD0,0xD0)); + addTriangle(new Triangle(lctr+pb,lctr+b,lctr+seh,0xD0,0xD0,0xD0)); + } + + pa = a; + pb = b; + } + + addTriangle(new Triangle(lctr+se,lctr+pb,lctr+seh,0xD0,0xD0,0xD0)); + addTriangle(new Triangle(lctr+ne,lctr+pa,lctr+neh,0xD0,0xD0,0xD0)); +} diff --git a/rules/batiment/batimentquadpont.hh b/rules/batiment/batimentquadpont.hh @@ -0,0 +1,27 @@ +#ifndef _RULES_BATIMENTPONT_HH_ +#define _RULES_BATIMENTPONT_HH_ + +#include "all_includes.hh" + +// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°. +class BatimentQuadPont: public Chose { + private : + Vertex ne; + Vertex se; + Vertex sw; + Vertex nw; + int height; + + public : + + BatimentQuadPont(); + BatimentQuadPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height); + virtual ~BatimentQuadPont(); + virtual bool split(); + virtual bool merge(); + virtual void triangulation(); + Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); + virtual void getBoundingBoxPoints(); +}; + +#endif diff --git a/rules/chose.cpp b/rules/chose.cpp @@ -18,6 +18,21 @@ bool Chose::merge() { return true; } +void Chose::addQuad(Vertex u, Vertex v, Vertex w, Vertex x, char r, char g, char b) { + this->addTriangle(new Triangle(u,x,w,r,g,b)); + this->addTriangle(new Triangle(w,v,u,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); + this->addQuad(e,f,g,h,red,green,blue); + this->addQuad(b,a,e,f,red,green,blue); + this->addQuad(c,b,f,g,red,green,blue); + this->addQuad(d,c,g,h,red,green,blue); + this->addQuad(a,d,h,e,red,green,blue); +} + void Chose::display() { if (children.size() > 0) { std::vector<Chose*>::iterator it; diff --git a/rules/chose.hh b/rules/chose.hh @@ -53,6 +53,8 @@ class Chose { } void addChild(Chose* c); void addTriangle(Triangle* t); + void addQuad(Vertex u, Vertex v, Vertex w, Vertex x, 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); }; #endif diff --git a/segment.cpp b/segment.cpp @@ -2,10 +2,15 @@ Segment::Segment(Vertex u, Vertex v): u(u), v(v) {} -int Segment::length() { +float Segment::length() { return (u-v).norm(); } +Segment Segment::reduce(float value) { + float reduc = (float)length()/(float)value; + return Segment(u,u+((v - u) / reduc)); +} + int Segment::width() { return std::abs(u.x - v.x); } diff --git a/segment.hh b/segment.hh @@ -4,15 +4,16 @@ #include "all_includes.hh" class Segment { - private : + public : Vertex u; Vertex v; public : Segment(Vertex u, Vertex v); - int length(); + float length(); int width(); int height(); + Segment reduce(float value); Vertex randomPos(int seed, int n, int a, int b); // Renvoir un vertex sur le segment [u,v], à une position entre a% and b%. };