commit 1bca125a1a71ccaa38805fd9b61a87754361a6b6
parent b9ef26c6483bd5d961cba0263b80e3b142d8d03c
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Mon, 9 Jan 2012 01:13:40 +0100
Ajout de QuartierTriCentre.
Diffstat:
8 files changed, 67 insertions(+), 13 deletions(-)
diff --git a/all_includes.hh b/all_includes.hh
@@ -54,6 +54,7 @@ class Chose;
#include "rules/quartier/quartiertri.hh"
#include "rules/quartier/quartiertrihauteur.hh"
#include "rules/quartier/quartiertritrapeze.hh"
+#include "rules/quartier/quartiertricentre.hh"
#include "rules/route/routequadcarrefour.hh"
#include "rules/route/routequadchaussee.hh"
diff --git a/geometry/triangle.cpp b/geometry/triangle.cpp
@@ -15,10 +15,10 @@ float Triangle::angle() const {
}
float Triangle::minAngle() const {
- float a2 = angle();
- float a3 = Triangle(c[1],c[2],c[0]).angle();
- float a1 = Angle::Pi - a2 - a3;
- return std::min(std::min(a1, a2), a3);
+ float at = angle();
+ float a3 = Triangle(c[TOP],c[RIGHT],c[LEFT]).angle();
+ float a1 = Angle::Pi - at - a3;
+ return std::min(std::min(a1, at), a3);
}
float Triangle::minLength() const {
@@ -35,6 +35,16 @@ Triangle Triangle::inset(CoteTriangle side, float offset) const {
return (Triangle(q[SE], q[SW], q[NW]) >> side);
}
+Triangle Triangle::insetLTR(float offset) const {
+ return (*this).inset(LEFTSIDE, offset).inset(RIGHTSIDE, offset).inset(BASE, offset);
+}
+
Triangle operator+(const Triangle& t, const Vertex& v) {
return Triangle(t[LEFT] + v, t[TOP] + v, t[RIGHT] + v);
}
+
+Vertex Triangle::randomPoint(int seed, int n) const {
+ float rndl = hashInRange(seed, n, 0, 100);
+ float rndr = hashInRange(seed, hash2(n, 42), 0, 100 - rndl);
+ return c[TOP] + (c[LEFT] - c[TOP]) * (rndl/100.f) + (c[RIGHT] - c[TOP]) * (rndr/100.f);
+}
diff --git a/geometry/triangle.hh b/geometry/triangle.hh
@@ -29,6 +29,8 @@ class Triangle {
float minLength() const;
float maxLength() const;
Triangle inset(CoteTriangle side, float offset) const;
+ Triangle insetLTR(float offset) const;
+ Vertex randomPoint(int seed, int n) const;
void display();
};
diff --git a/geometry/vertex.cpp b/geometry/vertex.cpp
@@ -80,10 +80,6 @@ Vertex operator*(const Vertex& u, const Vertex& v) {
);
}
-Vertex operator/(const Vertex& v, const int n) {
- return Vertex(v.x / n, v.y / n, v.z / n);
-}
-
Vertex operator/(const Vertex& v, const float f) {
return Vertex(v.x / f, v.y / f, v.z / f);
}
diff --git a/geometry/vertex.hh b/geometry/vertex.hh
@@ -29,7 +29,6 @@ class Vertex {
friend Vertex operator-(const Vertex& v);
friend Vertex operator*(const Vertex& v, const float n);
friend Vertex operator*(const Vertex& u, const Vertex& v);
- friend Vertex operator/(const Vertex& v, const int n);
friend Vertex operator/(const Vertex& v, const float f);
};
diff --git a/rules/quartier/quartiertri.cpp b/rules/quartier/quartiertri.cpp
@@ -14,10 +14,16 @@ Chose* QuartierTri::factory(int seed, int n, Triangle c) {
bool big = c.maxLength() >= 5000;
if (small && !big) {
return new BatimentTri(c);
- } else if (!small && proba(seed, n, 1, 2)) {
- return new QuartierTriHauteur(c);
- } else if (!small) {
- return new QuartierTriTrapeze(c);
+ } else if (big) {
+ int choice = hashInRange(seed, n, 0, 3);
+ if (choice == 0) {
+ // TODO : condition : générer seulement si les 3 angles sont proches de 60°
+ return new QuartierTriCentre(c);
+ } else if (choice == 1) {
+ return new QuartierTriHauteur(c);
+ } else {
+ return new QuartierTriTrapeze(c);
+ }
} else {
return new TerrainTriHerbe(c);
}
diff --git a/rules/quartier/quartiertricentre.cpp b/rules/quartier/quartiertricentre.cpp
@@ -0,0 +1,25 @@
+#include "all_includes.hh"
+
+QuartierTriCentre::QuartierTriCentre(Triangle c) : QuartierTri(c) {
+}
+
+bool QuartierTriCentre::split() {
+ // TODO : maxLength / 6 au lieu de 1000
+ Vertex center = c.insetLTR(1000).randomPoint(seed, 0);
+ Vertex edgePoint[3];
+ for (int i = 0; i < 3; i++)
+ edgePoint[LEFTSIDE+i] = Segment(c[LEFT+i], c[TOP+i]).randomPos(seed, i+1, 33, 67);
+
+ Quad q[3];
+ for (int i = 0; i < 3; i++) {
+ q[i] = Quad(c[TOP+i], edgePoint[RIGHTSIDE+i], center, edgePoint[LEFTSIDE+i]);
+ q[i] = q[i].inset(S, hrw).inset(W, hrw);
+ }
+
+ for (int i = 0; i < 3; i++) {
+ addChild(QuartierQuad::factory(seed, i+4, q[i]));
+ addChild(new RouteQuadChaussee(Quad(q[(i+1)%3][NW], q[(i+1)%3][SW], q[i][SW], q[i][SE])));
+ }
+ addChild(new RouteTriChaussee(Triangle(q[0][SW], q[1][SW], q[2][SW])));
+ return true;
+}
diff --git a/rules/quartier/quartiertricentre.hh b/rules/quartier/quartiertricentre.hh
@@ -0,0 +1,15 @@
+#ifndef _RULES_QUARTIER_QUARTIERTRIORTHOCENTRE_HH_
+#define _RULES_QUARTIER_QUARTIERTRIORTHOCENTRE_HH_
+
+#include "all_includes.hh"
+
+class QuartierTriCentre : public QuartierTri {
+ private :
+ static const int hrw = 250; // half road width : 2,50m.
+
+ public :
+ QuartierTriCentre(Triangle c);
+ virtual bool split();
+};
+
+#endif