commit 89d409c776e9b1ebee2befe2403461c96c23177f
parent 5d581f103b83457b0521aac258986e1a4648c477
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Tue, 29 Nov 2011 13:41:10 +0100
Une ballade en ville (attention les triangles sont dessinés en taille *10).
Diffstat:
11 files changed, 34 insertions(+), 39 deletions(-)
diff --git a/hash.hh b/hash.hh
@@ -5,7 +5,7 @@
unsigned int hash2(unsigned int a, unsigned int b);
unsigned int hash3(unsigned int seed, int x, int y);
-int hashInRange(int seed, int n, int a, int b);
+int hashInRange(int seed, int n, int a, int b); // Renvoie le n-ième nombre aléatoire dérivé de seed entre a et b.
int newSeed(int seed, int n);
#endif
diff --git a/main.cpp b/main.cpp
@@ -16,9 +16,9 @@ void recursiveSubdivide(Chose* c) {
int main() {
// Générer une tile de base
- Vertex ne(10, 10, 0);
+ Vertex ne(50, 50, 0);
Vertex sw(0, 0, 0);
- Chose* c = new Batiment(ne, sw);//new RectangleRoutes(ne, sw);
+ Chose* c = new RectangleRoutes(ne, sw);
recursiveSubdivide(c);
new View(c);
diff --git a/rules/batiment.cpp b/rules/batiment.cpp
@@ -22,13 +22,13 @@ void Batiment::triangulation() {
Vertex b = Vertex(this->ne.x, this->sw.y, 0);
Vertex c = Vertex(this->sw.x, this->ne.y, 0);
Vertex d = this->sw;
-
- int h = 6;
+
+ int h = hashInRange(seed,0,4,8);
Vertex ah = a + Vertex(0,0,h);
Vertex bh = b + Vertex(0,0,h);
Vertex ch = c + Vertex(0,0,h);
Vertex dh = d + Vertex(0,0,h);
- Vertex toit = (ah + bh + ch + dh) / 4 + Vertex(0,0,h/5);
+ Vertex toit = (ah + bh + ch + dh) / 4 + Vertex(0,0,h/2);
// 4 Murs
addTriangle(new Triangle(a,bh,ah,0xf1,0xe3,0xad)); addTriangle(new Triangle(a,b,bh,0xf1,0xe3,0xad)); // a-b-bh-ah
diff --git a/rules/batiment.hh b/rules/batiment.hh
@@ -8,7 +8,6 @@ class Batiment : public Chose {
public:
Vertex ne;
Vertex sw;
- int seed;
public:
Batiment(Vertex ne, Vertex sw);
int width();
diff --git a/rules/carrefour.cpp b/rules/carrefour.cpp
@@ -1,10 +1,7 @@
#include "carrefour.hh"
-Carrefour::Carrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
- corners[NE]=ne;
- corners[SE]=se;
- corners[SW]=sw;
- corners[NW]=nw;
+Carrefour::Carrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) {
+ addEntropy(ne,se,sw,nw);
triangulation();
}
@@ -18,11 +15,11 @@ std::ostream& operator<<(std::ostream& os, const Carrefour* c) {
}
std::ostream& operator<<(std::ostream& os, const Carrefour& c) {
- return os << "Carrefour " << c.corners[NE] << "-" << c.corners[SE] << "-" << c.corners[NW] << "-" << c.corners[SW];
+ return os << "Carrefour " << c.ne << "-" << c.se << "-" << c.sw << "-" << c.nw;
}
void Carrefour::triangulation() {
triangles.reserve(2);
- addTriangle(new Triangle(corners[SW], corners[NW], corners[NE], 0x80, 0x80, 0x80));
- addTriangle(new Triangle(corners[SW], corners[SE], corners[NE], 0x80, 0x80, 0x80));
+ addTriangle(new Triangle(sw, nw, ne, 0x80, 0x80, 0x80));
+ addTriangle(new Triangle(sw, se, ne, 0x80, 0x80, 0x80));
}
diff --git a/rules/carrefour.hh b/rules/carrefour.hh
@@ -5,7 +5,10 @@
class Carrefour : public Chose {
public:
- Vertex corners[4];
+ Vertex ne;
+ Vertex se;
+ Vertex sw;
+ Vertex nw;
public:
Carrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw);
virtual bool subdivide();
diff --git a/rules/rectangleroutes.cpp b/rules/rectangleroutes.cpp
@@ -25,19 +25,19 @@ bool RectangleRoutes::subdivide() {
Vertex roadEndS(split.x, this->sw.y, 0);
Vertex roadEndW(this->sw.x, split.y, 0);
// TODO : addChild(…);
- Route* rn = new Route(roadEndN + Vertex(-1,0,0), roadEndN + Vertex(+1,0,0), split + Vertex(+1,+1,0), split + Vertex(-1,+1,0)); // N
+ Route* rn = new Route(roadEndN + Vertex(+1,0,0), split + Vertex(+1,+1,0), split + Vertex(-1,+1,0), roadEndN + Vertex(-1,0,0)); // N
Route* re = new Route(roadEndE + Vertex(0,+1,0), roadEndE + Vertex(0,-1,0), split + Vertex(+1,-1,0), split + Vertex(+1,+1,0)); // E
- Route* rs = new Route(roadEndS + Vertex(+1,0,0), roadEndS + Vertex(-1,0,0), split + Vertex(-1,-1,0), split + Vertex(+1,-1,0)); // S
- Route* rw = new Route(roadEndW + Vertex(0,-1,0), roadEndW + Vertex(0,+1,0), split + Vertex(-1,+1,0), split + Vertex(-1,-1,0)); // W
+ Route* rs = new Route(split + Vertex(+1,-1,0), roadEndS + Vertex(+1,0,0), roadEndS + Vertex(-1,0,0), split + Vertex(-1,-1,0)); // S
+ Route* rw = new Route(split + Vertex(-1,+1,0), split + Vertex(-1,-1,0), roadEndW + Vertex(0,-1,0), roadEndW + Vertex(0,+1,0)); // W
addChild(rn);
addChild(re);
addChild(rs);
addChild(rw);
// Sous-quartiers
- addChild(sub(rn->corners[NE], re->corners[NE])); // sous-quartier NE
- addChild(sub(re->corners[SE], rs->corners[SE])); // sous-quartier SE
- addChild(sub(rs->corners[SW], rw->corners[SW])); // sous-quartier SW
- addChild(sub(rw->corners[NW], rn->corners[NW])); // sous-quartier NW
+ addChild(sub(ne, re->nw)); // sous-quartier NE
+ addChild(sub(re->se, rs->se)); // sous-quartier SE
+ addChild(sub(rs->nw, sw)); // sous-quartier SW
+ addChild(sub(rn->nw, rw->nw)); // sous-quartier NW
return true;
}
@@ -51,7 +51,6 @@ void RectangleRoutes::triangulation() {
Chose* RectangleRoutes::sub(Vertex ne, Vertex sw) {
Segment rect = Segment(ne,sw);
- std::cout << this << " ne=" << ne << " sw=" << sw << std::endl;
if (rect.width() < 10 || rect.height() < 10) {
return new Batiment(ne, sw);
} else {
diff --git a/rules/route.cpp b/rules/route.cpp
@@ -2,11 +2,7 @@
#include "../vertex.hh"
#include "../directions.hh"
-Route::Route(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
- corners[NE]=ne;
- corners[SE]=se;
- corners[SW]=sw;
- corners[NW]=nw;
+Route::Route(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) {
triangulation();
}
@@ -20,11 +16,11 @@ std::ostream& operator<<(std::ostream& os, const Route* r) {
}
std::ostream& operator<<(std::ostream& os, const Route& r) {
- return os << "Route " << r.corners[NE] << "-" << r.corners[SE] << "-" << r.corners[NW] << "-" << r.corners[SW];
+ return os << "Route " << r.ne << "-" << r.se << "-" << r.sw << "-" << r.nw;
}
void Route::triangulation() {
triangles.reserve(2);
- addTriangle(new Triangle(corners[SW], corners[NW], corners[NE], 0x6c, 0x6c, 0x6c));
- addTriangle(new Triangle(corners[SW], corners[SE], corners[NE], 0x6c, 0x6c, 0x6c));
+ addTriangle(new Triangle(sw, nw, ne, 0x6c, 0x6c, 0x6c));
+ addTriangle(new Triangle(sw, se, ne, 0x6c, 0x6c, 0x6c));
}
diff --git a/rules/route.hh b/rules/route.hh
@@ -5,7 +5,10 @@
class Route : public Chose {
public:
- Vertex corners[4];
+ Vertex ne;
+ Vertex se;
+ Vertex sw;
+ Vertex nw;
public:
Route(Vertex ne, Vertex se, Vertex sw, Vertex nw);
virtual bool subdivide();
diff --git a/triangle.cpp b/triangle.cpp
@@ -14,13 +14,11 @@ std::ostream& operator<<(std::ostream& os, const Triangle& t) {
}
void Triangle::display() {
- //glColor3ub(r, g, b);
View::setColor(r,g,b);
- //std::cout << (int)r << "," << (int)g << "," << (int)b << std::endl;
glNormal3d(normal.x,normal.y,normal.z);
glBegin(GL_TRIANGLES);
- glVertex3d(v1.x,v1.y,v1.z);
- glVertex3d(v2.x,v2.y,v2.z);
- glVertex3d(v3.x,v3.y,v3.z);
+ glVertex3d(v1.x*10,v1.y*10,v1.z*10);
+ glVertex3d(v2.x*10,v2.y*10,v2.z*10);
+ glVertex3d(v3.x*10,v3.y*10,v3.z*10);
glEnd();
}
diff --git a/view.cpp b/view.cpp
@@ -1,6 +1,6 @@
#include "all_includes.hh"
-View::View(Chose* root) : root(root), cameraCenter(500,-500,100), xAngle(135), yAngle(102), moveDist(10) {
+View::View(Chose* root) : root(root), cameraCenter(100,-100,30), xAngle(135), yAngle(102), moveDist(10) {
cameraSight = cameraCenter + Vertex::fromSpherical(100, yAngle, xAngle);
initWindow();
mainLoop();