This commit is contained in:
Georges Dupéron 2012-01-19 10:33:13 +01:00
parent 933d479147
commit 9fb650404d
4 changed files with 87 additions and 25 deletions

View File

@ -1,40 +1,79 @@
#include "all_includes.hh" #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() { bool Arbre::split() {
if (length < 5) return false; if (type == ARBRE && length > floatInRange(seed, -1, 10, 20)) {
return false; 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() { void Arbre::triangulation() {
float radius = length/16; if (type == ARBRE || type == TRONC) tronc();
float limitLength = length; if (type == ARBRE) feuille();
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);
} }
void Arbre::getBoundingBoxPoints() { void Arbre::getBoundingBoxPoints() {
// TODO // TODO
Vertex u = rotation.u * 100; Vertex u = rotation.u * limitLength() / 2.f;
Vertex l = rotation.l * 100; Vertex l = rotation.l * limitLength() / 2.f;
Quad c(start +u +l, start +u -l, start -u -l, start -u +l); Quad c(start +u +l, start -u +l, start -u -l, start +u -l);
addBBPoints(c); addBBPoints(c, length + limitLength());
} }
void Arbre::branche() { 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;
}
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() { 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);
} }

View File

@ -4,16 +4,28 @@
#include "all_includes.hh" #include "all_includes.hh"
class Arbre : public Chose { class Arbre : public Chose {
public:
enum Type {
ARBRE,
TRONC
};
private: private:
Vertex start; Vertex start;
Angle3D rotation; Angle3D rotation;
float length; float length;
Type type;
Vertex end(float position) const;
float limitLength() const;
static float tauxMax();
static float calcLimitLengthFactor();
static const float limitLengthFactor;
public: public:
Arbre(Vertex _start, Angle3D _rotation, float _length); Arbre(Vertex _start, Angle3D _rotation, float _length, Type _type = ARBRE);
virtual bool split(); virtual bool split();
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();
void branche(); virtual float LODFactor();
void tronc();
void feuille(); void feuille();
}; };

View File

@ -48,6 +48,11 @@ void Chose::addGPUQuad(Quad q, unsigned int rgb) {
addGPUQuad(q[NE], q[SE], q[SW], q[NW], 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, void Chose::addGPUOcto(Vertex ne, Vertex se, Vertex sw, Vertex nw,
Vertex neh, Vertex seh, Vertex swh, Vertex nwh, unsigned int rgb) { Vertex neh, Vertex seh, Vertex swh, Vertex nwh, unsigned int rgb) {
addGPUOcto(Quad(ne,se,sw,nw), Quad(neh,seh,swh,nwh), 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() { void Chose::updateAABB() {
float splitFactor = 5.f; float splitFactor = 5.f * LODFactor();
float mergeFactor = 6.f; float mergeFactor = 6.f * LODFactor();
float nonFacingFactor = 2.f/3.f; float nonFacingFactor = 2.f/3.f;
lod.firstBBPoint = true; lod.firstBBPoint = true;
getBoundingBoxPoints(); getBoundingBoxPoints();
@ -153,6 +158,10 @@ void Chose::updateAABB() {
} }
} }
float Chose::LODFactor() {
return 1.f;
}
// DEBUG // DEBUG
void Chose::drawAABB() { void Chose::drawAABB() {
addGPUOcto( addGPUOcto(

View File

@ -28,6 +28,7 @@ protected :
void addBBPoints(const Quad q); void addBBPoints(const Quad q);
void addBBPoints(const Quad q, float height); void addBBPoints(const Quad q, float height);
virtual void getBoundingBoxPoints() = 0; virtual void getBoundingBoxPoints() = 0;
virtual float LODFactor();
Chose(); Chose();
~Chose(); ~Chose();
inline void addEntropy(unsigned int x1) { inline void addEntropy(unsigned int x1) {
@ -66,6 +67,7 @@ protected :
void addGPUTriangle(Triangle t, unsigned int rgb); void addGPUTriangle(Triangle t, unsigned int rgb);
void addGPUQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, unsigned int rgb); void addGPUQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, unsigned int rgb);
void addGPUQuad(Quad q, 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, void addGPUOcto(Vertex ne, Vertex se, Vertex sw, Vertex nw,
Vertex neh, Vertex seh, Vertex swh, Vertex nwh, Vertex neh, Vertex seh, Vertex swh, Vertex nwh,
unsigned int rgb); unsigned int rgb);