Ajout des arches.

This commit is contained in:
Georges Dupéron 2012-01-19 22:11:55 +01:00
parent 46f1cf4e43
commit 05836fd361
6 changed files with 26 additions and 10 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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));
}

View File

@ -3,6 +3,7 @@
#include "all_includes.hh"
// Arche du nord au sud
class ArcheQuad : public Chose {
private:
Quad c;

View File

@ -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));

View File

@ -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.