www

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

commit 05836fd3612a039badc681f72a1b2208c0e8f205
parent 46f1cf4e438cb9b5040ef14a03a027408be9c675
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Thu, 19 Jan 2012 22:11:55 +0100

Ajout des arches.

Diffstat:
Mgeometry/segment.cpp | 4++++
Mgeometry/segment.hh | 1+
Mrules/arche.cpp | 22++++++++++++++--------
Mrules/arche.hh | 1+
Mrules/batiment.cpp | 6+++++-
Mview.cpp | 2+-
6 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/geometry/segment.cpp b/geometry/segment.cpp @@ -31,3 +31,7 @@ Vertex Segment::randomPos(int seed, int n, float a, float b) { float pos = floatInRange(seed, n, a, b); return (u * pos + v * (1-pos)); } + +Segment operator+(const Segment& s, const Vertex& voff) { + return Segment(s.u + voff, s.v + voff); +} diff --git a/geometry/segment.hh b/geometry/segment.hh @@ -17,6 +17,7 @@ class Segment { Vertex at(float); Segment reduce(float value); Vertex randomPos(int seed, int n, float a, float b); // Renvoie un vertex sur le segment [u,v], à une position entre a et b. + friend Segment operator+(const Segment& t, const Vertex& v); }; #endif diff --git a/rules/arche.cpp b/rules/arche.cpp @@ -6,19 +6,23 @@ ArcheQuad::ArcheQuad(Quad _c, float _height, float _start, float _end) : Chose() } bool ArcheQuad::split() { - if (std::abs(end - start) < 0.01) + if (std::abs(end - start) < 0.1 && std::abs(f(end) - f(start)) < 0.05) return false; float mid = (start + end) / 2; - addChild(new ArcheQuad(c, height, start, mid)); - addChild(new ArcheQuad(c, height, mid, end)); + Vertex n = (c[NW] + c[NE]) / 2.f; + Vertex s = (c[SE] + c[SW]) / 2.f; + addChild(new ArcheQuad(Quad(n, s, c[SW], c[NW]), height, start, mid)); + addChild(new ArcheQuad(Quad(c[NE], c[SE], s, n), height, mid, end)); return true; } void ArcheQuad::triangulation() { - Quad che = c.offsetNormal(f(end) * height); - Quad chw = c.offsetNormal(f(start) * height); - addGPUQuad(Quad(c[NW], c[NE], che[NE], chw[NW]), Couleurs::mur); - addGPUQuad(Quad(c[SE], c[SW], chw[SW], che[SE]), Couleurs::mur); + Quad ch = c.offsetNormal(height); + Quad che = c.offsetNormal(f(end) * height * 0.9); + Quad chw = c.offsetNormal(f(start) * height * 0.9); + addGPUQuad(Quad(ch[NW], chw[NW], che[NE], ch[NE]), Couleurs::mur); + addGPUQuad(Quad(ch[SE], che[SE], chw[SW], ch[SW]), Couleurs::mur); + addGPUQuad(Quad(che[SE], che[NE], chw[NW], chw[SW]), Couleurs::cielHaut); /* // Doivent être dessiné par le bâtiment englobant. if (start == 0) @@ -33,6 +37,7 @@ void ArcheQuad::getBoundingBoxPoints() { } float ArcheQuad::f(float x) { + return berceau(x); switch(hash2(seed, 0) % 2){ case 0: return ogive(x); case 1: @@ -41,9 +46,10 @@ float ArcheQuad::f(float x) { } float ArcheQuad::ogive(float x) { + // TODO : mettre x à l'échelle return sin(acos(abs(x / 2.f) + 1.f/2.f)); } float ArcheQuad::berceau(float x) { - return sin(acos(x)); + return sin(acos(2*x-1)); } diff --git a/rules/arche.hh b/rules/arche.hh @@ -3,6 +3,7 @@ #include "all_includes.hh" +// Arche du nord au sud class ArcheQuad : public Chose { private: Quad c; diff --git a/rules/batiment.cpp b/rules/batiment.cpp @@ -73,7 +73,11 @@ void BatimentQuad_::etages() { Quad qh; for (int i = 0; i < nbEtages; i++) { qh = q.offsetNormal(floatInRange(seed, 1+i, Dimensions::hauteurEtage*0.9f, Dimensions::hauteurEtage*1.1f)); - addChild(new EtageQuad(q,qh)); + if (i == 0 && w[N] && w[S]) { + addChild(new ArcheQuad(q, Segment(qh[NE],q[NE]).length())); + } else { + addChild(new EtageQuad(q,qh)); + } q = qh; } addChild(new ToitQuad(qh, Dimensions::hauteurToit)); diff --git a/view.cpp b/view.cpp @@ -170,7 +170,7 @@ void View::mainLoop() { short continuer = 1; SDL_Event event; SDL_EnableKeyRepeat(40,40); - SDL_WM_GrabInput(SDL_GRAB_ON); + SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_DISABLE); while ( SDL_PollEvent(&event) ); // empty queue.