www

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

commit 933d479147d5aa9eecfc1187bb9e39ac444b63a2
parent bacf9446849125d4cb91e224bdcacdd9c5431526
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Thu, 19 Jan 2012 09:07:29 +0100

Début des arbres.

Diffstat:
Mall_includes.hh | 3++-
Mgeometry/angle.cpp | 16++++++++++++++++
Mgeometry/angle.hh | 14++++++++++++++
Mgeometry/quad.cpp | 8++++++++
Mgeometry/quad.hh | 2++
Mgeometry/vertex.cpp | 4++++
Mgeometry/vertex.hh | 3++-
Arules/architecture/arbre.cpp | 40++++++++++++++++++++++++++++++++++++++++
Arules/architecture/arbre.hh | 20++++++++++++++++++++
Mrules/architecture/couleursDimensions.hh | 4+++-
Mrules/architecture/quartier.cpp | 4++++
11 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/all_includes.hh b/all_includes.hh @@ -20,9 +20,9 @@ class Chose; #include <GL/glu.h> #include <GL/gl.h> -#include "geometry/angle.hh" #include "geometry/directions.hh" #include "geometry/vertex.hh" +#include "geometry/angle.hh" #include "geometry/segment.hh" #include "geometry/triangle.hh" #include "geometry/quad.hh" @@ -38,6 +38,7 @@ class Chose; #include "rules/chose.hh" #include "rules/architecture/couleursDimensions.hh" +#include "rules/architecture/arbre.hh" #include "rules/architecture/arche.hh" #include "rules/architecture/batiment.hh" #include "rules/architecture/quartier.hh" diff --git a/geometry/angle.cpp b/geometry/angle.cpp @@ -2,3 +2,19 @@ float Angle::r2d(float rad) { return rad / Pi * 180; } float Angle::d2r(float deg) { return deg / 180 * Pi; } + +Angle3D::Angle3D() : h(Vertex(1,0,0)), l(Vertex(0,1,0)), u(Vertex(0,0,1)) {} +Angle3D::Angle3D(Vertex _h, Vertex _l, Vertex _u) : h(_h), l(_l), u(_u) {} + +// Formules : http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-94to95/hwchen/ +Angle3D Angle3D::rotateH(float angle) const { + return Angle3D(h, l*std::cos(angle) + u*std::sin(angle), l*-std::sin(angle) + u*std::cos(angle)); +} + +Angle3D Angle3D::rotateL(float angle) const { + return Angle3D(h*std::cos(angle) + u*std::sin(angle), l, h*-std::sin(angle) + u*std::cos(angle)); +} + +Angle3D Angle3D::rotateU(float angle) const { + return Angle3D(h*std::cos(angle) + l*-std::sin(angle), h*std::sin(angle) + l*std::cos(angle), u); +} diff --git a/geometry/angle.hh b/geometry/angle.hh @@ -1,6 +1,8 @@ #ifndef _GEOMETRY_ANGLE_HH_ #define _GEOMETRY_ANGLE_HH_ +#include "all_includes.hh" + namespace Angle { const double dPi = 3.141592653589793238462643383279; const float Pi = (float)(dPi); @@ -8,4 +10,16 @@ namespace Angle { float d2r(float deg); } +class Angle3D { +public: + Vertex h; + Vertex l; + Vertex u; + Angle3D(); + Angle3D(Vertex _h, Vertex _l, Vertex _u); + Angle3D rotateH(float angle) const; + Angle3D rotateL(float angle) const; + Angle3D rotateU(float angle) const; +}; + #endif diff --git a/geometry/quad.cpp b/geometry/quad.cpp @@ -230,3 +230,11 @@ Quad Quad::offsetNormal(float offset) const { Vertex Quad::normal() const { return Triangle(c[NE], c[SE], c[SW]).normal(); } + +Vertex Quad::normalizedNormal() const { + return Triangle(c[NE], c[SE], c[SW]).normalizedNormal(); +} + +Vertex Quad::moyenne() const { + return ((c[NE] + c[SE] + c[SW] + c[NW]) / 4.f); +} diff --git a/geometry/quad.hh b/geometry/quad.hh @@ -50,6 +50,8 @@ class Quad { Quad makeParallelogram() const; Quad offsetNormal(float offset) const; Vertex normal() const; + Vertex normalizedNormal() const; + Vertex moyenne() const; }; diff --git a/geometry/vertex.cpp b/geometry/vertex.cpp @@ -21,6 +21,10 @@ Vertex Vertex::setNorm(float n) const { return (*this * n / norm()); } +Vertex Vertex::normalize() const { + return (*this / norm()); +} + float Vertex::cosAngle(Vertex v) const { // http://www.developpez.net/forums/d202580/applications/developpement-2d-3d-jeux/contribuez/faq-mat-quat-ajout-calculs-vectoriels/ return ((this->x*v.x + this->y*v.y + this->z*v.z) / (norm()*v.norm())); diff --git a/geometry/vertex.hh b/geometry/vertex.hh @@ -15,6 +15,7 @@ class Vertex { float norm() const; Vertex projectOn(Vertex v) const; Vertex setNorm(float n) const; + Vertex normalize() const; float cosAngle(Vertex v) const; // cosinus de l'angle entre this et v. float angle(Vertex v) const; // Angle entre this et v. static Vertex fromSpherical(float r, float xAngle, float yAngle); @@ -24,7 +25,7 @@ class Vertex { friend Vertex operator+(const Vertex& u, const Vertex& v); friend Vertex operator-(const Vertex& u, const Vertex& v); friend Vertex operator-(const Vertex& v); - friend Vertex operator*(const Vertex& v, const float n); + friend Vertex operator*(const Vertex& v, const float n); // Cross product friend Vertex operator*(const Vertex& u, const Vertex& v); friend Vertex operator/(const Vertex& v, const float f); }; diff --git a/rules/architecture/arbre.cpp b/rules/architecture/arbre.cpp @@ -0,0 +1,40 @@ +#include "all_includes.hh" + +Arbre::Arbre(Vertex _start, Angle3D _rotation, float _length) : start(_start), rotation(_rotation), length(_length) {} + +bool Arbre::split() { + if (length < 5) return false; + return false; +} + +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); +} + +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); +} + +void Arbre::branche() { + +} + +void Arbre::feuille() { + +} diff --git a/rules/architecture/arbre.hh b/rules/architecture/arbre.hh @@ -0,0 +1,20 @@ +#ifndef _RULES_ARCHITECTURE_ARBRE_HH_ +#define _RULES_ARCHITECTURE_ARBRE_HH_ + +#include "all_includes.hh" + +class Arbre : public Chose { +private: + Vertex start; + Angle3D rotation; + float length; +public: + Arbre(Vertex _start, Angle3D _rotation, float _length); + virtual bool split(); + virtual void triangulation(); + virtual void getBoundingBoxPoints(); + void branche(); + void feuille(); +}; + +#endif diff --git a/rules/architecture/couleursDimensions.hh b/rules/architecture/couleursDimensions.hh @@ -24,7 +24,9 @@ public: static const unsigned int route = 0x363636; static const unsigned int trottoir = 0x666666; static const unsigned int bordureTrottoir = 0xAAAAAA; - static const unsigned int herbe = 0x0c4010; // 11AA22 + static const unsigned int herbe = 0x0c4010; + static const unsigned int feuillage = 0x11AA22; + static const unsigned int tronc = 0x906050; static const unsigned int cielHaut = 0x3c14ff; static const unsigned int cielBas = 0x7F7FFF; static const unsigned int fog; // définie dans couleurs.cpp . diff --git a/rules/architecture/quartier.cpp b/rules/architecture/quartier.cpp @@ -135,6 +135,10 @@ 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)); } }