commit 9fb650404dd683c7ab29a50ae90bbdf9cd373330
parent 933d479147d5aa9eecfc1187bb9e39ac444b63a2
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Thu, 19 Jan 2012 10:33:13 +0100
Arbres.
Diffstat:
4 files changed, 87 insertions(+), 25 deletions(-)
diff --git a/rules/architecture/arbre.cpp b/rules/architecture/arbre.cpp
@@ -1,40 +1,79 @@
#include "all_includes.hh"
-Arbre::Arbre(Vertex _start, Angle3D _rotation, float _length) : start(_start), rotation(_rotation), length(_length) {}
+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);
+ addEntropy((int)(type));
+}
bool Arbre::split() {
- if (length < 5) return false;
- return false;
+ if (type == ARBRE && length > floatInRange(seed, -1, 10, 20)) {
+ int nbBranches = 2 + (hash2(seed, -2) % 3);
+ for (int i = 0; i < nbBranches; i++) {
+ Vertex bStart = end(floatInRange(seed, 4*i, 0.7f, 0.9f));
+ Angle3D rot = rotation;
+ rot = rot.rotateH(Angle::d2r(floatInRange(seed, 4*i+1, 25.f, 37.f) + i*(360.f / (float)nbBranches)));
+ rot = rot.rotateU(Angle::d2r(floatInRange(seed, 4*i+2, 35.f, 55.f)));
+ float len = length * floatInRange(seed, 4*i+3, tauxMax()*2.f/3.f, tauxMax());
+ addChild(new Arbre(bStart, rot, len, ARBRE));
+ }
+ addChild(new Arbre(start, rotation, length, TRONC));
+ }
+ return true;
}
void Arbre::triangulation() {
- float radius = length/16;
- float limitLength = length;
- Vertex hTronc = rotation.h * length;
- Vertex uTronc = rotation.u * radius;
- Vertex lTronc = rotation.l * radius;
- Vertex hFeuillage = rotation.h * limitLength;
- Vertex uFeuillage = rotation.u * limitLength / 2;
- Vertex lFeuillage = rotation.l * limitLength / 2;
- Quad cTronc(start +uTronc +lTronc, start +uTronc -lTronc, start -uTronc -lTronc, start -uTronc +lTronc);
- addGPUOcto(cTronc, cTronc + hTronc, Couleurs::tronc);
-
- Quad cFeuillage(start +uFeuillage +lFeuillage, start +uFeuillage -lFeuillage, start -uFeuillage -lFeuillage, start -uFeuillage +lFeuillage);
- addGPUOcto(cFeuillage + hTronc, cFeuillage + hTronc + hFeuillage, Couleurs::feuillage);
+ if (type == ARBRE || type == TRONC) tronc();
+ if (type == ARBRE) feuille();
}
void Arbre::getBoundingBoxPoints() {
// TODO
- Vertex u = rotation.u * 100;
- Vertex l = rotation.l * 100;
- Quad c(start +u +l, start +u -l, start -u -l, start -u +l);
- addBBPoints(c);
+ Vertex u = rotation.u * limitLength() / 2.f;
+ Vertex l = rotation.l * limitLength() / 2.f;
+ Quad c(start +u +l, start -u +l, start -u -l, start +u -l);
+ addBBPoints(c, length + limitLength());
+}
+
+float Arbre::LODFactor() {
+ return 4.f;
+}
+
+Vertex Arbre::end(float position) const {
+ return (start + rotation.h * length * position);
+}
+
+float Arbre::tauxMax() {
+ return 0.6f;
+}
+const float Arbre::limitLengthFactor = calcLimitLengthFactor();
+float Arbre::calcLimitLengthFactor() {
+ float limit = 0;
+ for (float i = 1; i > 0.001; i = i * tauxMax())
+ limit += i;
+ return limit - 1;
}
-void Arbre::branche() {
+float Arbre::limitLength() const {
+ return length * limitLengthFactor;
+}
+void Arbre::tronc() {
+ float radius = length/16;
+ Vertex hTronc = end(1.f) - start;
+ Vertex uTronc = rotation.u * radius;
+ Vertex lTronc = rotation.l * radius;
+ Quad cTronc(start +uTronc +lTronc, start -uTronc +lTronc, start -uTronc -lTronc, start +uTronc -lTronc);
+ addGPUQuad(cTronc + hTronc, Couleurs::tronc);
+ addGPUFourQuads(cTronc, cTronc + hTronc, Couleurs::tronc);
}
void Arbre::feuille() {
+ Vertex hFeuillage = rotation.h * limitLength();
+ Vertex uFeuillage = rotation.u * limitLength() / 2.f;
+ Vertex lFeuillage = rotation.l * limitLength() / 2.f;
+ Vertex startFeuillage = end(1.f);
+ Quad cFeuillage(startFeuillage +uFeuillage +lFeuillage, startFeuillage -uFeuillage +lFeuillage, startFeuillage -uFeuillage -lFeuillage, startFeuillage +uFeuillage -lFeuillage);
+ addGPUOcto(cFeuillage, cFeuillage + hFeuillage, Couleurs::feuillage);
}
diff --git a/rules/architecture/arbre.hh b/rules/architecture/arbre.hh
@@ -4,16 +4,28 @@
#include "all_includes.hh"
class Arbre : public Chose {
+public:
+ enum Type {
+ ARBRE,
+ TRONC
+ };
private:
Vertex start;
Angle3D rotation;
float length;
+ Type type;
+ Vertex end(float position) const;
+ float limitLength() const;
+ static float tauxMax();
+ static float calcLimitLengthFactor();
+ static const float limitLengthFactor;
public:
- Arbre(Vertex _start, Angle3D _rotation, float _length);
+ Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type = ARBRE);
virtual bool split();
virtual void triangulation();
virtual void getBoundingBoxPoints();
- void branche();
+ virtual float LODFactor();
+ void tronc();
void feuille();
};
diff --git a/rules/chose.cpp b/rules/chose.cpp
@@ -48,6 +48,11 @@ void Chose::addGPUQuad(Quad q, unsigned int rgb) {
addGPUQuad(q[NE], q[SE], q[SW], q[NW], rgb);
}
+void Chose::addGPUFourQuads(Quad q, Quad qh, unsigned int rgb) {
+ for (int i = 0; i < 4; i++)
+ addGPUQuad(Quad(qh[NE+i], q[NE+i], q[SE+i], qh[SE+i]), rgb);
+}
+
void Chose::addGPUOcto(Vertex ne, Vertex se, Vertex sw, Vertex nw,
Vertex neh, Vertex seh, Vertex swh, Vertex nwh, unsigned int rgb) {
addGPUOcto(Quad(ne,se,sw,nw), Quad(neh,seh,swh,nwh), rgb);
@@ -131,8 +136,8 @@ void Chose::addBBPoints(const Quad q, float height) {
}
void Chose::updateAABB() {
- float splitFactor = 5.f;
- float mergeFactor = 6.f;
+ float splitFactor = 5.f * LODFactor();
+ float mergeFactor = 6.f * LODFactor();
float nonFacingFactor = 2.f/3.f;
lod.firstBBPoint = true;
getBoundingBoxPoints();
@@ -153,6 +158,10 @@ void Chose::updateAABB() {
}
}
+float Chose::LODFactor() {
+ return 1.f;
+}
+
// DEBUG
void Chose::drawAABB() {
addGPUOcto(
diff --git a/rules/chose.hh b/rules/chose.hh
@@ -28,6 +28,7 @@ protected :
void addBBPoints(const Quad q);
void addBBPoints(const Quad q, float height);
virtual void getBoundingBoxPoints() = 0;
+ virtual float LODFactor();
Chose();
~Chose();
inline void addEntropy(unsigned int x1) {
@@ -66,6 +67,7 @@ protected :
void addGPUTriangle(Triangle t, unsigned int rgb);
void addGPUQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, unsigned int rgb);
void addGPUQuad(Quad q, unsigned int rgb);
+ void addGPUFourQuads(Quad q, Quad qh, unsigned int rgb);
void addGPUOcto(Vertex ne, Vertex se, Vertex sw, Vertex nw,
Vertex neh, Vertex seh, Vertex swh, Vertex nwh,
unsigned int rgb);