Vertex en 3D.

This commit is contained in:
Georges Dupéron 2011-11-24 01:01:04 +01:00
parent 96d8b12b04
commit 699e0fa520
6 changed files with 48 additions and 50 deletions

View File

@ -1,2 +1 @@
* Route et Carrefour à mettre à jour pour qu'ils soient sous-classe de Chose.
* Vertex en 3D

View File

@ -9,8 +9,8 @@
int main() {
// Générer une tile de base
Vertex ne(100, 100);
Vertex sw(0, 0);
Vertex ne(100, 100, 0);
Vertex sw(0, 0, 0);
RectangleRoutes r(ne, sw);
r.subdivide();
// tile.subdivide tant qu'on n'a pas le niveau de détail désiré.

View File

@ -13,25 +13,30 @@ void Batiment::subdivide() {
}
void Batiment::triangulation() {
// // abcd sont les quatre coins du bâtiment.
// int h = 6;
// 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);
// abcd sont les quatre coins du bâtiment.
Vertex a = this->ne;
Vertex b = Vertex(this->ne.x, this->sw.y, 0);
Vertex c = this->sw;
Vertex d = Vertex(this->sw.x, this->ne.y, 0);
int h = 6;
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);
// // 4 Murs
// new Triangle(a,bh,ah); new Triangle(a,b,bh); // a-b-bh-ah
// new Triangle(b,dh,bh); new Triangle(b,d,dh); // b-d-dh-bh
// new Triangle(d,ch,dh); new Triangle(d,c,ch); // d-c-ch-dh
// new Triangle(c,ah,ch); new Triangle(c,a,ah); // c-a-ah-ch
// 4 Murs
new Triangle(a,bh,ah); new Triangle(a,b,bh); // a-b-bh-ah
new Triangle(b,dh,bh); new Triangle(b,d,dh); // b-d-dh-bh
new Triangle(d,ch,dh); new Triangle(d,c,ch); // d-c-ch-dh
new Triangle(c,ah,ch); new Triangle(c,a,ah); // c-a-ah-ch
// // 1 Toit
// new Triangle(ah,toit,bh);
// new Triangle(bh,toit,dh);
// new Triangle(dh,toit,ch);
// new Triangle(ch,toit,ah);
// 1 Toit
new Triangle(ah,toit,bh);
new Triangle(bh,toit,dh);
new Triangle(dh,toit,ch);
new Triangle(ch,toit,ah);
}
std::ostream& operator<<(std::ostream& os, const Batiment* r) {

View File

@ -13,23 +13,25 @@ int RectangleRoutes::height() { return this->ne.y - this->sw.y; }
void RectangleRoutes::subdivide() {
Vertex split(
hashInRange(this->seed, 0, this->sw.x + this->width()*1/4, this->sw.x + this->width()*3/4),
hashInRange(this->seed, 1, this->sw.y + this->height()*1/4, this->sw.y + this->height()*3/4)
hashInRange(this->seed, 1, this->sw.y + this->height()*1/4, this->sw.y + this->height()*3/4),
0 // TODO
);
Carrefour c(split.add(1,1), split.add(1,-1), split.add(-1,-1), split.add(-1,1));
Carrefour c(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
Vertex roadEndN(this->ne.y, split.x);
Vertex roadEndE(this->ne.x, split.y);
Vertex roadEndS(this->sw.y, split.x);
Vertex roadEndW(this->sw.x, split.y);
Route rn(roadEndN.add(-1,0), roadEndN.add(+1,0), split.add(+1,+1), split.add(-1,+1));
Route re(roadEndE.add(0,+1), roadEndE.add(0,-1), split.add(+1,-1), split.add(+1,+1));
Route rs(roadEndS.add(+1,0), roadEndS.add(-1,0), split.add(-1,-1), split.add(+1,-1));
Route rw(roadEndW.add(0,-1), roadEndW.add(0,+1), split.add(-1,+1), split.add(-1,-1));
// TODO : la plupart des zéros en z sont faux…
Vertex roadEndN(this->ne.y, split.x, 0);
Vertex roadEndE(this->ne.x, split.y, 0);
Vertex roadEndS(this->sw.y, split.x, 0);
Vertex roadEndW(this->sw.x, split.y, 0);
Route rn(roadEndN + Vertex(-1,0,0), roadEndN + Vertex(+1,0,0), split + Vertex(+1,+1,0), split + Vertex(-1,+1,0));
Route re(roadEndE + Vertex(0,+1,0), roadEndE + Vertex(0,-1,0), split + Vertex(+1,-1,0), split + Vertex(+1,+1,0));
Route rs(roadEndS + Vertex(+1,0,0), roadEndS + Vertex(-1,0,0), split + Vertex(-1,-1,0), split + Vertex(+1,-1,0));
Route rw(roadEndW + Vertex(0,-1,0), roadEndW + Vertex(0,+1,0), split + Vertex(-1,+1,0), split + Vertex(-1,-1,0));
// Sous-quartiers
Chose* rrne = sub(this->ne, re.corners[NW]);
Chose* rrse = sub(re.corners[SE], rs.corners[SE]);
Chose* rrsw = sub(rs.corners[NW], this->sw);
Chose* rrnw = sub(Vertex(this->sw.x, this->ne.y), rn.corners[SW]);
Chose* rrnw = sub(Vertex(this->sw.x, this->ne.y, 0), rn.corners[SW]);
// TODO : stocker ces objets quelque part.
(void)rrne;
(void)rrse;
@ -38,8 +40,8 @@ void RectangleRoutes::subdivide() {
}
void RectangleRoutes::triangulation() {
Vertex nw(this->sw.x, this->ne.y);
Vertex se(this->ne.x, this->sw.y);
Vertex nw(this->sw.x, this->ne.y, 0);
Vertex se(this->ne.x, this->sw.y, 0);
new Triangle(this->sw, nw, this->ne);
new Triangle(this->sw, se, this->ne);
}

View File

@ -2,35 +2,28 @@
Vertex::Vertex() {}
Vertex::Vertex(int x, int y): x(x), y(y) {}
Vertex Vertex::add(int dx, int dy) {
Vertex v = *this;
v.x += dx;
v.y += dy;
return v;
}
Vertex::Vertex(int x, int y, int z): x(x), y(y), z(z) {}
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
return os << "(" << v.x << "," << v.y << ")";
return os << "(" << v.x << "," << v.y << "," << v.z << ")";
}
Vertex operator+(const Vertex& u, const Vertex& v) {
return Vertex(u.x + v.x, u.y + v.y);
return Vertex(u.x + v.x, u.y + v.y, u.z + v.z);
}
Vertex operator-(const Vertex& u, const Vertex& v) {
return Vertex(u.x + v.x, u.y + v.y);
return Vertex(u.x + v.x, u.y + v.y, u.z + v.z);
}
Vertex operator-(const Vertex& v) {
return Vertex(-v.x, -v.y);
return Vertex(-v.x, -v.y, -v.z);
}
Vertex operator*(const Vertex& v, const int n) {
return Vertex(v.x * n, v.y * n);
return Vertex(v.x * n, v.y * n, v.z * n);
}
Vertex operator/(const Vertex& v, const int n) {
return Vertex(v.x / n, v.y / n);
return Vertex(v.x / n, v.y / n, v.z / n);
}

View File

@ -7,11 +7,10 @@ class Vertex {
public:
int x;
int y;
//int z;
int z;
public:
Vertex();
Vertex(int x, int y);
Vertex add(int dx, int dy);
Vertex(int x, int y, int z);
public:
friend std::ostream& operator<<(std::ostream& os, const Vertex& v);
friend Vertex operator+(const Vertex& u, const Vertex& v);