Début de QuadRoutes.
This commit is contained in:
parent
e035eac1c8
commit
22f44ce632
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ CCWARN=-Wall -Wextra -Werror
|
||||||
# -flto (nécessite GCC 4.5) -m32 ou -m64
|
# -flto (nécessite GCC 4.5) -m32 ou -m64
|
||||||
CFLAGS=-O3 -g3 -I. $(CCWARN)
|
CFLAGS=-O3 -g3 -I. $(CCWARN)
|
||||||
|
|
||||||
OBJECTS = main.o view.o hash.o segment.o vertex.o triangle.o rules/chose.o rules/rectangleroutes.o rules/route.o rules/carrefour.o rules/batiment.o
|
OBJECTS = main.o view.o hash.o segment.o vertex.o triangle.o rules/chose.o rules/rectangleroutes.o rules/quadroutes.o rules/route.o rules/carrefour.o rules/batiment.o
|
||||||
LIBS = -lm -lGL -lGLU -lSDL -lGLEW
|
LIBS = -lm -lGL -lGLU -lSDL -lGLEW
|
||||||
EXECUTABLE = city
|
EXECUTABLE = city
|
||||||
|
|
||||||
|
|
|
@ -25,5 +25,6 @@ class Chose;
|
||||||
#include "rules/carrefour.hh"
|
#include "rules/carrefour.hh"
|
||||||
#include "rules/route.hh"
|
#include "rules/route.hh"
|
||||||
#include "rules/rectangleroutes.hh"
|
#include "rules/rectangleroutes.hh"
|
||||||
|
#include "rules/quadroutes.hh"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
7
main.cpp
7
main.cpp
|
@ -16,9 +16,12 @@ void recursiveSubdivide(Chose* c) {
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Générer une tile de base
|
// Générer une tile de base
|
||||||
Vertex ne(50, 50, 0);
|
int size = 50;
|
||||||
|
Vertex ne(size, size, 0);
|
||||||
|
Vertex se(size, 0, 0);
|
||||||
Vertex sw(0, 0, 0);
|
Vertex sw(0, 0, 0);
|
||||||
Chose* c = new RectangleRoutes(ne,sw);//new RectangleRoutes(ne, sw);
|
Vertex nw(0, size, 0);
|
||||||
|
Chose* c = new QuadRoutes(ne,se,sw,nw);
|
||||||
recursiveSubdivide(c);
|
recursiveSubdivide(c);
|
||||||
|
|
||||||
new View(c);
|
new View(c);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
Batiment::Batiment(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) {
|
Batiment::Batiment(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) {
|
||||||
addEntropy(ne, sw);
|
addEntropy(ne, se, sw, nw);
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
71
rules/quadroutes.cpp
Normal file
71
rules/quadroutes.cpp
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
#include "all_includes.hh"
|
||||||
|
|
||||||
|
QuadRoutes::QuadRoutes(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) {
|
||||||
|
addEntropy(ne, se, sw, nw);
|
||||||
|
triangulation();
|
||||||
|
}
|
||||||
|
|
||||||
|
int QuadRoutes::width() { return std::abs(this->ne.x - this->sw.x); }
|
||||||
|
|
||||||
|
int QuadRoutes::height() { return std::abs(this->ne.y - this->sw.y); }
|
||||||
|
|
||||||
|
bool QuadRoutes::subdivide() {
|
||||||
|
children.reserve(9);
|
||||||
|
int splitXMin = this->sw.x + std::max(4, this->width()*1/4);
|
||||||
|
int splitXMax = this->ne.x - std::max(4, this->width()*1/4);
|
||||||
|
int splitYMin = this->sw.y + std::max(4, this->height()*1/4);
|
||||||
|
int splitYMax = this->ne.y - std::max(4, this->height()*1/4);
|
||||||
|
Vertex split(
|
||||||
|
hashInRange(this->seed, 0, splitXMin, splitXMax),
|
||||||
|
hashInRange(this->seed, 1, splitYMin, splitYMax),
|
||||||
|
0 // TODO
|
||||||
|
);
|
||||||
|
// TODO : addChild(…);
|
||||||
|
addChild(new Carrefour(split + Vertex(1,1,0), split + Vertex(1,-1,0), split + Vertex(-1,-1,0), split + Vertex(-1,1,0)));
|
||||||
|
// routes au NESW du carrefour
|
||||||
|
// TODO : la plupart des zéros en z sont faux…
|
||||||
|
Vertex roadEndN(split.x, this->ne.y, 0);
|
||||||
|
Vertex roadEndE(this->ne.x, split.y, 0);
|
||||||
|
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), 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(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(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuadRoutes::triangulation() {
|
||||||
|
triangles.reserve(2);
|
||||||
|
Vertex nw(this->sw.x, this->ne.y, 0);
|
||||||
|
Vertex se(this->ne.x, this->sw.y, 0);
|
||||||
|
addTriangle(new Triangle(this->ne, nw, this->sw, 0xc0, 0xc0, 0xc0));
|
||||||
|
addTriangle(new Triangle(this->sw, se, this->ne, 0xc0, 0xc0, 0xc0));
|
||||||
|
}
|
||||||
|
|
||||||
|
Chose* QuadRoutes::sub(Vertex ne, Vertex sw) {
|
||||||
|
Segment rect = Segment(ne,sw);
|
||||||
|
if (rect.width() < 10 || rect.height() < 10) {
|
||||||
|
return new Batiment(ne, Vertex(ne.x, sw.y, 0), sw, Vertex(sw.x, ne.y, 0));
|
||||||
|
} else {
|
||||||
|
return new QuadRoutes(ne, Vertex(ne.x, sw.y, 0), sw, Vertex(sw.x, ne.y, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const QuadRoutes* r) {
|
||||||
|
return os << *r;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const QuadRoutes& r) {
|
||||||
|
return os << "QuadRoutes " << r.ne << "-" << r.sw;
|
||||||
|
}
|
27
rules/quadroutes.hh
Normal file
27
rules/quadroutes.hh
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef _RULES_QUADROUTES_HH_
|
||||||
|
#define _RULES_QUADROUTES_HH_
|
||||||
|
|
||||||
|
#include "all_includes.hh"
|
||||||
|
|
||||||
|
// QuadRoutes est un quadrilatère de routes avec des angles aux coins entre 70° et 110°, et des côtés de longueur >= 10.
|
||||||
|
class QuadRoutes : public Chose {
|
||||||
|
public:
|
||||||
|
Vertex ne;
|
||||||
|
Vertex se;
|
||||||
|
Vertex sw;
|
||||||
|
Vertex nw;
|
||||||
|
public:
|
||||||
|
QuadRoutes(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
|
int width();
|
||||||
|
int height();
|
||||||
|
virtual bool subdivide();
|
||||||
|
virtual void triangulation();
|
||||||
|
private:
|
||||||
|
Chose* sub(Vertex ne, Vertex sw);
|
||||||
|
public:
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const QuadRoutes& r);
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const QuadRoutes* r);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°.
|
// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°, et des côtés de longueur >= 10.
|
||||||
class RectangleRoutes : public Chose {
|
class RectangleRoutes : public Chose {
|
||||||
public:
|
public:
|
||||||
Vertex ne;
|
Vertex ne;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user