commit afac9ff4e551c35fc2b75958ef6863e38e764ebf
parent 6bfc5872effce2e6885267f14aaca394372c8273
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Thu, 19 Jan 2012 10:47:26 +0100
Ajout de 0 à 3 arbres sur les terrains.
Diffstat:
3 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/rules/architecture/arbre.cpp b/rules/architecture/arbre.cpp
@@ -1,5 +1,19 @@
#include "all_includes.hh"
+Arbre::Arbre(Vertex _start, Triangle plane) : start(_start), type(ARBRE) {
+ addEntropy(start);
+ addEntropy(plane);
+
+ Vertex h = plane.normalizedNormal();
+ Vertex l = (plane[TOP] - plane[LEFT]).normalize();
+ Vertex u = h * l;
+
+ rotation = Angle3D(h, l, u);
+ rotation = rotation.rotateH(floatInRange(seed, -3, 0, 2*Angle::Pi));
+ rotation = rotation.rotateU(floatInRange(seed, -4, Angle::d2r(-10), Angle::d2r(10)));
+ length = floatInRange(seed, -5, 3*100, 4*100);
+}
+
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);
@@ -58,6 +72,10 @@ float Arbre::limitLength() const {
return length * limitLengthFactor;
}
+float Arbre::maxRadius(float length) {
+ return length * (1+limitLengthFactor);
+}
+
void Arbre::tronc() {
float radius = length/16;
Vertex hTronc = end(1.f) - start;
diff --git a/rules/architecture/arbre.hh b/rules/architecture/arbre.hh
@@ -20,6 +20,8 @@ private:
static float calcLimitLengthFactor();
static const float limitLengthFactor;
public:
+ static float maxRadius(float length);
+ Arbre(Vertex _start, Triangle plane);
Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type = ARBRE);
virtual bool split();
virtual void triangulation();
diff --git a/rules/architecture/quartier.cpp b/rules/architecture/quartier.cpp
@@ -135,10 +135,18 @@ void QuartierQuad::batiments() {
addChild(new BatimentQuad_(qbatiments));
} else {
addChild(new TerrainQuad(qbatiments));
- Vertex h = qbatiments.normalizedNormal();
- Vertex l = (qbatiments[NE] - qbatiments[SE]).normalize();
- Vertex u = h * l;
- addChild(new Arbre(qbatiments.moyenne(), Angle3D(h, l, u), 3*100));
+ 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])));
+ }
+ }
+ }
}
}