Ajout d'une fonction de reduction d'un segment, et d'une fonction
permettant d'extraire un parallélogramme à partir d'un quadrilatère.
This commit is contained in:
parent
b0b5fb2fe0
commit
7b7575d120
3
main.cpp
3
main.cpp
|
@ -21,11 +21,12 @@ void recursiveSubdivide(Chose* c) {
|
||||||
int main() {
|
int main() {
|
||||||
// Générer une tile de base
|
// Générer une tile de base
|
||||||
std::cout << "Initial seed = " << Chose::initialSeed << std::endl;
|
std::cout << "Initial seed = " << Chose::initialSeed << std::endl;
|
||||||
int size = 10000;
|
int size = 20000;
|
||||||
Vertex ne(size, size, 0);
|
Vertex ne(size, size, 0);
|
||||||
Vertex se(size, 0, 0);
|
Vertex se(size, 0, 0);
|
||||||
Vertex sw(0, 0, 0);
|
Vertex sw(0, 0, 0);
|
||||||
Vertex nw(0, size, 0);
|
Vertex nw(0, size, 0);
|
||||||
|
//Chose::initialSeed = 1440907084;
|
||||||
Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw);
|
Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw);
|
||||||
// c->split();
|
// c->split();
|
||||||
recursiveSubdivide(c);
|
recursiveSubdivide(c);
|
||||||
|
|
25
quad.cpp
25
quad.cpp
|
@ -22,6 +22,31 @@ void Quad::offsetNESW(int offsetN, int offsetE, int offsetS, int offsetW) {
|
||||||
this->offset(W,offsetW);
|
this->offset(W,offsetW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Quad::makeParallelogram() {
|
||||||
|
int l1, l2;
|
||||||
|
|
||||||
|
if(Segment(corner[NW],corner[NE]).length() < Segment(corner[SE],corner[SW]).length()) {
|
||||||
|
if((l1 = Segment(corner[NE],corner[SE]).length()) < (l2 = Segment(corner[SW],corner[NW]).length())) {
|
||||||
|
corner[SW] = Segment(corner[NW],corner[SW]).reduce(l1).v;
|
||||||
|
corner[SE] = corner[SW] + (corner[NE] - corner[NW]);
|
||||||
|
}
|
||||||
|
else if((l1 = Segment(corner[NE],corner[SE]).length()) > (l2 = Segment(corner[SW],corner[NW]).length())) {
|
||||||
|
corner[SE] = Segment(corner[NE],corner[SE]).reduce(l2).v;
|
||||||
|
corner[SW] = corner[SE] + (corner[NW] - corner[NE]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if((l1 = Segment(corner[NE],corner[SE]).length()) < (l2 = Segment(corner[SW],corner[NW]).length())) {
|
||||||
|
corner[NW] = Segment(corner[SW],corner[NW]).reduce(l1).v;
|
||||||
|
corner[NE] = corner[NW] + (corner[SE] - corner[SW]);
|
||||||
|
}
|
||||||
|
else if((l1 = Segment(corner[NE],corner[SE]).length()) > (l2 = Segment(corner[SW],corner[NW]).length())) {
|
||||||
|
corner[NE] = Segment(corner[SE],corner[NE]).reduce(l2).v;
|
||||||
|
corner[NW] = corner[NE] + (corner[SW] - corner[SE]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Quad::minLengthNS() {
|
int Quad::minLengthNS() {
|
||||||
return std::min(
|
return std::min(
|
||||||
Segment(corner[NW],corner[NE]).length(),
|
Segment(corner[NW],corner[NE]).length(),
|
||||||
|
|
1
quad.hh
1
quad.hh
|
@ -21,6 +21,7 @@ class Quad {
|
||||||
int maxLength();
|
int maxLength();
|
||||||
float minAngle();
|
float minAngle();
|
||||||
float maxAngle();
|
float maxAngle();
|
||||||
|
void makeParallelogram();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,33 +40,41 @@ bool BatimentQuad::merge() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Chose* BatimentQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw) {
|
Chose* BatimentQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw) {
|
||||||
int th = 20; // Terrain height.
|
int rand = this->seed % 20;
|
||||||
Quad q = Quad(ne,se,sw,nw);
|
|
||||||
seed = seed;
|
|
||||||
n = n;
|
|
||||||
th = th;
|
|
||||||
q.offset(N,-140);
|
|
||||||
q.offset(E,-140);
|
|
||||||
q.offset(S,-140);
|
|
||||||
q.offset(W,-140);
|
|
||||||
/*
|
|
||||||
addChild(new TrottoirQuadNormal(lctr+ne,lctr+se,lctr+q.corner[1],lctr+q.corner[0],th,E));
|
|
||||||
addChild(new TrottoirQuadNormal(lctr+se,lctr+sw,lctr+q.corner[2],lctr+q.corner[1],th,E));
|
|
||||||
addChild(new TrottoirQuadNormal(lctr+sw,lctr+nw,lctr+q.corner[3],lctr+q.corner[2],th,E));
|
|
||||||
addChild(new TrottoirQuadNormal(lctr+nw,lctr+ne,lctr+q.corner[0],lctr+q.corner[3],th,E));
|
|
||||||
|
|
||||||
q.corner[0] = q.corner[0] + Vertex(0,0,th);
|
if(rand <= 2) {
|
||||||
q.corner[1] = q.corner[1] + Vertex(0,0,th);
|
Quad q = Quad(ne,se,sw,nw);
|
||||||
q.corner[2] = q.corner[2] + Vertex(0,0,th);
|
addChild(new BatimentQuadPont(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3],300));
|
||||||
q.corner[3] = q.corner[3] + Vertex(0,0,th);
|
}
|
||||||
|
else if(rand <= 15) {
|
||||||
|
int th = 20; // Terrain height.
|
||||||
|
Quad q = Quad(ne,se,sw,nw);
|
||||||
|
seed = seed;
|
||||||
|
n = n;
|
||||||
|
th = th;
|
||||||
|
q.offset(N,-140);
|
||||||
|
q.offset(E,-140);
|
||||||
|
q.offset(S,-140);
|
||||||
|
q.offset(W,-140);
|
||||||
|
|
||||||
addChild(new BatimentQuadJardin(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3]));
|
addChild(new TrottoirQuadNormal(lctr+ne,lctr+se,lctr+q.corner[1],lctr+q.corner[0],th,E));
|
||||||
|
addChild(new TrottoirQuadNormal(lctr+se,lctr+sw,lctr+q.corner[2],lctr+q.corner[1],th,E));
|
||||||
|
addChild(new TrottoirQuadNormal(lctr+sw,lctr+nw,lctr+q.corner[3],lctr+q.corner[2],th,E));
|
||||||
|
addChild(new TrottoirQuadNormal(lctr+nw,lctr+ne,lctr+q.corner[0],lctr+q.corner[3],th,E));
|
||||||
|
|
||||||
q.offset(this->entry,-400);
|
q.corner[0] = q.corner[0] + Vertex(0,0,th);
|
||||||
|
q.corner[1] = q.corner[1] + Vertex(0,0,th);
|
||||||
|
q.corner[2] = q.corner[2] + Vertex(0,0,th);
|
||||||
|
q.corner[3] = q.corner[3] + Vertex(0,0,th);
|
||||||
|
|
||||||
|
q.makeParallelogram();
|
||||||
|
addChild(new BatimentQuadJardin(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3]));
|
||||||
|
|
||||||
|
q.offset(this->entry,-400);
|
||||||
|
|
||||||
|
addChild(new BatimentQuadMaison(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3]));
|
||||||
|
}
|
||||||
|
|
||||||
addChild(new BatimentQuadMaison(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3]));
|
|
||||||
*/
|
|
||||||
addChild(new BatimentQuadPont(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3],300));
|
|
||||||
return NULL; // pour compilation, à virer.
|
return NULL; // pour compilation, à virer.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,5 +43,8 @@ void BatimentQuadJardin::triangulation() {
|
||||||
triangles.reserve(2);
|
triangles.reserve(2);
|
||||||
|
|
||||||
addTriangle(new Triangle(lctr+ne,lctr+nw,lctr+sw,0x12,0x64,0x12));
|
addTriangle(new Triangle(lctr+ne,lctr+nw,lctr+sw,0x12,0x64,0x12));
|
||||||
addTriangle(new Triangle(lctr+sw,lctr+se,lctr+ne,0x10,0x60,0x10));
|
addTriangle(new Triangle(lctr+sw,lctr+se,lctr+ne,0x12,0x64,0x12));
|
||||||
|
|
||||||
|
//addTriangle(new Triangle(lctr+ne,lctr+nw,lctr+sw,0xFF,0xFF,0x00));
|
||||||
|
//addTriangle(new Triangle(lctr+sw,lctr+se,lctr+ne,0xFF,0xFF,0x00));
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,14 +68,10 @@ void BatimentQuadPont::triangulation() {
|
||||||
int middle = steps/2;
|
int middle = steps/2;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
std::cout << std::endl << l1.norm() << std::endl;
|
|
||||||
|
|
||||||
addTriangle(new Triangle(lctr+pb,lctr+sw,lctr+swh,0x10,0xFF,0x10));
|
addTriangle(new Triangle(lctr+pb,lctr+sw,lctr+swh,0x10,0xFF,0x10));
|
||||||
addTriangle(new Triangle(lctr+pa,lctr+nw,lctr+nwh,0x10,0xFF,0x10));
|
addTriangle(new Triangle(lctr+pa,lctr+nw,lctr+nwh,0x10,0xFF,0x10));
|
||||||
|
|
||||||
for(var=-1.7,n=0; var <= 1.7; var+=pas,n++) {
|
for(var=-1.7,n=0; var <= 1.7; var+=pas,n++) {
|
||||||
std::cout << var << std::endl;
|
|
||||||
//std::cout << var << " \t " << nt(var,height) << std::endl;
|
|
||||||
q.offset(W,-n2);
|
q.offset(W,-n2);
|
||||||
a = q.corner[3] + Vertex(0,0,nt(var,height));
|
a = q.corner[3] + Vertex(0,0,nt(var,height));
|
||||||
b = q.corner[2] + Vertex(0,0,nt(var,height));
|
b = q.corner[2] + Vertex(0,0,nt(var,height));
|
||||||
|
|
|
@ -6,6 +6,11 @@ int Segment::length() {
|
||||||
return (u-v).norm();
|
return (u-v).norm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Segment Segment::reduce(int value) {
|
||||||
|
float reduc = (float)length()/(float)value;
|
||||||
|
return Segment(u,u+((v - u) / reduc));
|
||||||
|
}
|
||||||
|
|
||||||
int Segment::width() {
|
int Segment::width() {
|
||||||
return std::abs(u.x - v.x);
|
return std::abs(u.x - v.x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
class Segment {
|
class Segment {
|
||||||
private :
|
public :
|
||||||
Vertex u;
|
Vertex u;
|
||||||
Vertex v;
|
Vertex v;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ class Segment {
|
||||||
int length();
|
int length();
|
||||||
int width();
|
int width();
|
||||||
int height();
|
int height();
|
||||||
|
Segment reduce(int value);
|
||||||
Vertex randomPos(int seed, int n, int a, int b); // Renvoir un vertex sur le segment [u,v], à une position entre a% and b%.
|
Vertex randomPos(int seed, int n, int a, int b); // Renvoir un vertex sur le segment [u,v], à une position entre a% and b%.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user