From e7a3fb6ea588888980d08e1d86c45de1a90fe843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Thu, 19 Jan 2012 20:32:23 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20jardins,=20d=C3=A9placement=20de?= =?UTF-8?q?=20quelques=20constantes=20dans=20CouleursDimensions.{hh,cpp}?= =?UTF-8?q?=20.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geometry/quad.cpp | 2 +- hash.cpp | 4 ++-- hash.hh | 2 +- rules/architecture/batiment.cpp | 19 +++++++++++++------ rules/architecture/couleursDimensions.cpp | 3 +++ rules/architecture/couleursDimensions.hh | 9 +++++++++ rules/architecture/quartier.cpp | 10 +++++----- rules/batiment/batimentquad.cpp | 2 +- rules/chose.cpp | 11 +++++------ view.cpp | 10 +++++----- view.hh | 4 ---- 11 files changed, 45 insertions(+), 31 deletions(-) diff --git a/geometry/quad.cpp b/geometry/quad.cpp index cee2abf..fbf85df 100644 --- a/geometry/quad.cpp +++ b/geometry/quad.cpp @@ -208,7 +208,7 @@ Vertex Quad::randomPoint(int seed, int n) const { Triangle sw(c[SE], c[SW], c[NW]); float surfacene = ne.surface(); float surfacesw = sw.surface(); - if (proba(seed, n, surfacene, surfacene + surfacesw)) { + if (proba(seed, n, surfacene / (surfacene + surfacesw))) { return ne.randomPoint(seed, hash2(n, 42)); } else { return sw.randomPoint(seed, hash2(n, 42)); diff --git a/hash.cpp b/hash.cpp index cd60d8c..60857b1 100644 --- a/hash.cpp +++ b/hash.cpp @@ -29,8 +29,8 @@ float floatInRange(int seed, int n, float a, float b) { return (float)(hash2(seed, n) & 0xffffff) / (float)(0x1000000) * (b-a) + a; } -bool proba(int seed, int n, float a, float b) { - return floatInRange(seed, n, 0, b) < a; +bool proba(int seed, int n, float proba) { + return floatInRange(seed, n, 0, 1) < proba; } unsigned int float2uint(float f) { diff --git a/hash.hh b/hash.hh index b7cc96a..dd62e62 100644 --- a/hash.hh +++ b/hash.hh @@ -7,7 +7,7 @@ int random_seed(); unsigned int hash2(unsigned int a, unsigned int b); float floatInRange(int seed, int n, float a, float b); // Renvoie le n-ième nombre aléatoire dérivé de seed entre a et b (a inclus, b non inclus). -bool proba(int seed, int n, float a, float b); // Renvoie vrai avec `a` fois sur `b`. +bool proba(int seed, int n, float proba); // Renvoie vrai avec une probabilité de `proba`. typedef union FloatUIntUnion { float f; unsigned int ui; diff --git a/rules/architecture/batiment.cpp b/rules/architecture/batiment.cpp index 2e19c96..7458b11 100644 --- a/rules/architecture/batiment.cpp +++ b/rules/architecture/batiment.cpp @@ -17,16 +17,23 @@ bool BatimentQuad_::split() { Vertex n = Segment(q[NW], q[NE]).randomPos(seed, 0, 1.f/3.f, 1.f/2.f); Vertex s = Segment(q[SE], q[SW]).randomPos(seed, 1, 1.f/3.f, 1.f/2.f); - addChild(new BatimentQuad_(Quad(q[SE], s, n, q[NE]), true, QuadBool(qb[E],qb[S],false,qb[N]))); - addChild(new BatimentQuad_(Quad(q[NW], n, s, q[SW]), true, QuadBool(qb[W],qb[N],false,qb[S]))); + if (qb[E] && proba(seed, 2, 0.3f)) { + addChild(new TerrainQuad(Quad(q[SE], s, n, q[NE]))); + addChild(new BatimentQuad_(Quad(q[NW], n, s, q[SW]), true, QuadBool(qb[W],qb[N],true,qb[S]))); + } else if (qb[W] && proba(seed, 2, 0.5f)) { + addChild(new BatimentQuad_(Quad(q[SE], s, n, q[NE]), true, QuadBool(qb[E],qb[S],true,qb[N]))); + addChild(new TerrainQuad(Quad(q[NW], n, s, q[SW]))); + } else { + addChild(new BatimentQuad_(Quad(q[SE], s, n, q[NE]), true, QuadBool(qb[E],qb[S],false,qb[N]))); + addChild(new BatimentQuad_(Quad(q[NW], n, s, q[SW]), true, QuadBool(qb[W],qb[N],false,qb[S]))); + } } else { - float randEtages = floatInRange(seed, 2, 0.f, 1.f); + float randEtages = floatInRange(seed, 0, 0.f, 1.f); int nbEtages = 1 + (int)(randEtages * randEtages * (Dimensions::maxEtages - 1)); - Quad q = c; - //ch = ch.insetNESW(30); + Quad q = c; // c.insetNESW(30) Quad qh; for (int i = 0; i < nbEtages; i++) { - qh = q.offsetNormal(floatInRange(seed, 3+i, Dimensions::hauteurEtage*0.9f, Dimensions::hauteurEtage*1.1f)); + qh = q.offsetNormal(floatInRange(seed, 1+i, Dimensions::hauteurEtage*0.9f, Dimensions::hauteurEtage*1.1f)); addChild(new EtageQuad(q,qh)); q = qh; } diff --git a/rules/architecture/couleursDimensions.cpp b/rules/architecture/couleursDimensions.cpp index 5f24a86..836a1ed 100644 --- a/rules/architecture/couleursDimensions.cpp +++ b/rules/architecture/couleursDimensions.cpp @@ -1,3 +1,6 @@ #include "all_includes.hh" const unsigned int Couleurs::fog = mix(cielHaut, cielBas, 0.5); + +const float Dimensions::frontFrustum = 1; +const float Dimensions::backFrustum = 4000 * 100; // 4km diff --git a/rules/architecture/couleursDimensions.hh b/rules/architecture/couleursDimensions.hh index 84b61e5..fd4f40a 100644 --- a/rules/architecture/couleursDimensions.hh +++ b/rules/architecture/couleursDimensions.hh @@ -43,6 +43,15 @@ public: static const unsigned int hauteurToit = 200; static const unsigned int hauteurTrottoir = 20; static const unsigned int hauteurMaxBatiment = hauteurTrottoir + hauteurEtage + hauteurToit; + + // Qualité + // TODO : devrait être 5.f et 6.f + static const unsigned int splitFactor = 2.f; + static const unsigned int mergeFactor = 3.f; + static const unsigned int windowWidth = 1024; + static const unsigned int windowHeight = 768; + static const float frontFrustum; + static const float backFrustum; }; #endif diff --git a/rules/architecture/quartier.cpp b/rules/architecture/quartier.cpp index 851d77a..f1d4d4b 100644 --- a/rules/architecture/quartier.cpp +++ b/rules/architecture/quartier.cpp @@ -20,9 +20,9 @@ bool QuartierQuad::split() { concave(); else if (nearConcave) angleAngle(); - else if (big && anglesOk && proba(seed, -2, 1, 4)) + else if (big && anglesOk && proba(seed, -2, 0.25f)) longueRue(); - else if (!small && !anglesOk && proba(seed, -3, 1, 2)) + else if (!small && !anglesOk && proba(seed, -3, 0.5f)) angleAngle(); else if (!small && !anglesOk) angleCote(); @@ -131,7 +131,7 @@ void QuartierQuad::batiments() { bool anglesAcceptable = c.minAngle() > Angle::d2r(90-60) && c.maxAngle() < Angle::d2r(90+60); - if (anglesAcceptable && proba(seed, 0, 19, 20)) { + if (anglesAcceptable && proba(seed, 0, 0.95f)) { addChild(new BatimentQuad_(qbatiments)); } else { addChild(new TerrainQuad(qbatiments)); @@ -155,7 +155,7 @@ bool QuartierTri::split() { bool angleObtus = maxAngle > Angle::d2r(120); bool angleAigu = minAngle < Angle::d2r(30); bool anglesAcceptable = !angleAigu && !angleObtus; - if (!big && proba(seed, -1, 1, 20)) { + if (!big && proba(seed, -1, 0.05f)) { batiments(); } else if (big && anglesAcceptable) { switch (hash2(seed, -2) % 3) { @@ -228,7 +228,7 @@ void QuartierTri::batiments() { bool big = tbatiments.maxLength() >= 5000; bool anglesAcceptable = tbatiments.minAngle() > Angle::d2r(30) && tbatiments.maxAngle() < Angle::d2r(120); - if (!big && proba(seed, 0, 1, 20)) { + if (!big && proba(seed, 0, 0.05f)) { addChild(new TerrainTri(tbatiments)); } else if (small && anglesAcceptable) { addChild(new BatimentTri_(tbatiments)); diff --git a/rules/batiment/batimentquad.cpp b/rules/batiment/batimentquad.cpp index 69feec8..7074bce 100644 --- a/rules/batiment/batimentquad.cpp +++ b/rules/batiment/batimentquad.cpp @@ -10,7 +10,7 @@ void BatimentQuad::getBoundingBoxPoints() { } bool BatimentQuad::split() { - if(proba(seed, 0, 1, 10)) { + if(proba(seed, 0, 0.1f)) { addChild(new BatimentQuadMaisonPont(c,3)); } else { addChild(new BatimentQuadJardin(c)); diff --git a/rules/chose.cpp b/rules/chose.cpp index cbd4f37..e4c2616 100644 --- a/rules/chose.cpp +++ b/rules/chose.cpp @@ -141,9 +141,8 @@ void Chose::addBBPoints(const Quad q, float height) { } void Chose::updateAABB() { - // TODO : Debug : devrait être 5.f, 6.f - float splitFactor = 2.f * LODFactor(); - float mergeFactor = 3.f * LODFactor(); + float splitFactor = Dimensions::splitFactor * LODFactor(); + float mergeFactor = Dimensions::mergeFactor * LODFactor(); float nonFacingFactor = 2.f/3.f; lod.firstBBPoint = true; getBoundingBoxPoints(); @@ -155,8 +154,8 @@ void Chose::updateAABB() { areaFacing[i] = size[(i+1)%3]*size[(i+1)%3]; for (int i = 0; i < 3; i++) { float pseudoLength = std::max(1.f, std::sqrt(areaFacing[i] + areaFacing[(i+1)%3] * nonFacingFactor + areaFacing[(i+1)%3] * nonFacingFactor)); - float splitIncrement = std::min((float)View::backFrustum, splitFactor * pseudoLength); - float mergeIncrement = std::min(View::backFrustum * mergeFactor/splitFactor, mergeFactor * pseudoLength); + float splitIncrement = std::min(Dimensions::backFrustum, splitFactor * pseudoLength); + float mergeIncrement = std::min(Dimensions::backFrustum * mergeFactor/splitFactor, mergeFactor * pseudoLength); lod.splitBox[2*i] = lod.aabb[2*i] - splitIncrement; lod.splitBox[2*i+1] = lod.aabb[2*i+1] + splitIncrement; lod.mergeBox[2*i] = lod.aabb[2*i] - mergeIncrement; @@ -183,4 +182,4 @@ void Chose::drawAABB() { ); } -unsigned int Chose::initialSeed = 1896509207;//random_seed(); +unsigned int Chose::initialSeed = random_seed(); diff --git a/view.cpp b/view.cpp index c3e197c..e464ecb 100644 --- a/view.cpp +++ b/view.cpp @@ -26,10 +26,10 @@ void View::setColor(unsigned char r, unsigned char g, unsigned char b) { void View::initWindow() { SDL_Init(SDL_INIT_VIDEO); SDL_WM_SetCaption("Sortie terrain OpenGL",NULL); - SDL_SetVideoMode(windowWidth, windowHeight, 32, SDL_OPENGL); + SDL_SetVideoMode(Dimensions::windowWidth, Dimensions::windowHeight, 32, SDL_OPENGL); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); - gluPerspective(70,(double)windowWidth/windowHeight,frontFrustum,backFrustum); + gluPerspective(70,Dimensions::windowWidth/Dimensions::windowHeight,Dimensions::frontFrustum,Dimensions::backFrustum); glEnable(GL_DEPTH_TEST); glewInit(); @@ -49,8 +49,8 @@ void View::initWindow() { glEnable (GL_FOG); glFogi (GL_FOG_MODE, GL_LINEAR); glFogfv (GL_FOG_COLOR, fogColor); - glFogf (GL_FOG_START, backFrustum / sqrt(3) / 2.f); - glFogf (GL_FOG_END, backFrustum / sqrt(3) * 0.9); + glFogf (GL_FOG_START, Dimensions::backFrustum / sqrt(3) / 2.f); + glFogf (GL_FOG_END, Dimensions::backFrustum / sqrt(3) * 0.9); //glHint (GL_FOG_HINT, GL_NICEST); } @@ -94,7 +94,7 @@ void View::displayAxes() { void View::setSkybox() { //int z = 40000; - float d = View::backFrustum / std::sqrt(3) * 0.9; + float d = Dimensions::backFrustum / std::sqrt(3) * 0.9; glDisable(GL_FOG); glDisable(GL_LIGHTING); glPushMatrix(); diff --git a/view.hh b/view.hh index ab5d5b2..8b382b6 100644 --- a/view.hh +++ b/view.hh @@ -37,13 +37,9 @@ private : public : Camera camera; - static const float frontFrustum = 1; - static const float backFrustum = 400000; // 1km private: Lod lod; GLfloat fogColor[4]; - static const int windowWidth = 1024; - static const int windowHeight = 768; public : View(Chose* root);