www

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

commit 556974a38da74e317925cbd7bdb44ed719590a6e
parent 6b692b48a5ab67a713de68cf257880522d15c5b5
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Thu, 19 Jan 2012 11:28:28 +0100

Utilisation des arbres dans les TerrainQuad.

Diffstat:
Mrules/architecture/arbre.cpp | 12+++++++++++-
Mrules/architecture/arbre.hh | 2++
Mrules/architecture/quartier.cpp | 12------------
Mrules/architecture/terrain.cpp | 28+++++++++++++++++++++++++++-
Mrules/architecture/terrain.hh | 4+++-
5 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/rules/architecture/arbre.cpp b/rules/architecture/arbre.cpp @@ -1,6 +1,8 @@ #include "all_includes.hh" -Arbre::Arbre(Vertex _start, Triangle plane) : start(_start), type(ARBRE) { +void Arbre::initPlane(Vertex _start, Triangle plane) { + start = _start; + type = ARBRE; addEntropy(start); addEntropy(plane); @@ -14,6 +16,14 @@ Arbre::Arbre(Vertex _start, Triangle plane) : start(_start), type(ARBRE) { length = floatInRange(seed, -5, 3*100, 4*100); } +Arbre::Arbre(Vertex _start, Triangle plane) { + initPlane(_start, plane); +} + +Arbre::Arbre(Vertex _start, Quad plane) { + initPlane(_start, Triangle(plane[NE], plane[SE], plane[SW])); +} + Arbre::Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type) : start(_start), rotation(_rotation), length(_length), type(_type) { addEntropy(start, rotation.h, rotation.l, rotation.u); addEntropy(length); diff --git a/rules/architecture/arbre.hh b/rules/architecture/arbre.hh @@ -19,8 +19,10 @@ private: static float tauxMax(); static float calcLimitLengthFactor(); static const float limitLengthFactor; + void initPlane(Vertex _start, Triangle plane); public: static float maxRadius(float length); + Arbre(Vertex _start, Quad plane); Arbre(Vertex _start, Triangle plane); Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type = ARBRE); virtual bool split(); diff --git a/rules/architecture/quartier.cpp b/rules/architecture/quartier.cpp @@ -135,18 +135,6 @@ void QuartierQuad::batiments() { addChild(new BatimentQuad_(qbatiments)); } else { addChild(new TerrainQuad(qbatiments)); - Vertex p1 = qbatiments.insetProportionnal(0.7).randomPoint(seed, 1); - Vertex p2 = qbatiments.insetProportionnal(0.7).randomPoint(seed, 2); - Vertex p3 = qbatiments.insetProportionnal(0.7).randomPoint(seed, 3); - if (proba(seed, 4, 3, 4)) { - addChild(new Arbre(p1, Triangle(qbatiments[NE], qbatiments[SE], qbatiments[SW]))); - if (proba(seed, 5, 3, 4) && Segment(p1,p2).length() > 3 * 100) { - addChild(new Arbre(p2, Triangle(qbatiments[NE], qbatiments[SE], qbatiments[SW]))); - if (proba(seed, 6, 3, 4) && Segment(p2,p3).length() > 3 * 100 && Segment(p1,p3).length() > 3 * 100) { - addChild(new Arbre(p3, Triangle(qbatiments[NE], qbatiments[SE], qbatiments[SW]))); - } - } - } } } diff --git a/rules/architecture/terrain.cpp b/rules/architecture/terrain.cpp @@ -1,9 +1,35 @@ #include "all_includes.hh" -TerrainQuad::TerrainQuad(Quad _c) : Chose(), c(_c) { +TerrainQuad::TerrainQuad(Quad _c, bool _addTrees) : Chose(), c(_c), addTrees(_addTrees) { addEntropy(c); } +bool TerrainQuad::split() { + if (!addTrees) return false; + + addChild(new TerrainQuad(c, false)); + + int maxNArbres = 10; + Vertex p[maxNArbres]; + int pi = 0; + int nArbres = hash2(seed, -1) % (maxNArbres + 1); + for (int essai = 0; essai < nArbres * 2 && pi < nArbres; essai++) { + p[pi] = c.insetProportionnal(0.7).randomPoint(seed, essai); + bool success = true; + for (int j = 0; j < pi; j++) { + if (Segment(p[j], p[pi]).length() < 3 * 100) { + success = false; + break; + } + } + if (success) pi++; + } + for (int i = 0; i < pi; i++) { + addChild(new Arbre(p[i], c)); + } + return true; +} + void TerrainQuad::getBoundingBoxPoints() { addBBPoints(c); } diff --git a/rules/architecture/terrain.hh b/rules/architecture/terrain.hh @@ -16,9 +16,11 @@ class TerrainTri : public Chose { class TerrainQuad : public Chose { private : Quad c; + bool addTrees; public : - TerrainQuad(Quad _c); + TerrainQuad(Quad _c, bool _addTrees = true); + virtual bool split(); virtual void triangulation(); virtual void getBoundingBoxPoints(); };