Refactor, nettoyage, correction du calcul des normales, …
This commit is contained in:
parent
800338bfaa
commit
c361c48433
|
@ -43,6 +43,7 @@ class Chose;
|
|||
#include "rules/batiment/batimentquadmaisonpont.hh"
|
||||
#include "rules/batiment/batimentquadblock.hh"
|
||||
#include "rules/batiment/batimentquadtoit.hh"
|
||||
#include "rules/batiment/batimenttri.hh"
|
||||
|
||||
#include "rules/quartier/quartierquad.hh"
|
||||
#include "rules/quartier/quartierquadangle.hh"
|
||||
|
@ -58,5 +59,6 @@ class Chose;
|
|||
#include "rules/route/trottoirquadnormal.hh"
|
||||
|
||||
#include "rules/terrain/terrainquadherbe.hh"
|
||||
#include "rules/terrain/terraintriherbe.hh"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,9 @@ enum Cardinal {
|
|||
inline Cardinal operator+(Cardinal c, int i) {
|
||||
return Cardinal((int(c) + int(i)) & 3);
|
||||
}
|
||||
inline Cardinal operator-(Cardinal c, int i) {
|
||||
return Cardinal((int(c) - int(i)) & 3);
|
||||
}
|
||||
|
||||
enum Coin {
|
||||
NE = 0,
|
||||
|
@ -22,6 +25,9 @@ enum Coin {
|
|||
inline Coin operator+(Coin c, int i) {
|
||||
return Coin((int(c) + int(i)) & 3);
|
||||
}
|
||||
inline Coin operator-(Coin c, int i) {
|
||||
return Coin((int(c) - int(i)) & 3);
|
||||
}
|
||||
|
||||
enum SommetTriangle {
|
||||
LEFT = 0,
|
||||
|
@ -33,4 +39,8 @@ inline SommetTriangle operator+(SommetTriangle c, int i) {
|
|||
return SommetTriangle((((int(c) + int(i)) % 3 ) + 3) % 3);
|
||||
}
|
||||
|
||||
inline SommetTriangle operator-(SommetTriangle c, int i) {
|
||||
return SommetTriangle((((int(c) - int(i)) % 3 ) + 3) % 3);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -49,39 +49,39 @@ Quad Quad::makeParallelogram() {
|
|||
return Quad(c[0],c[1],c[2],c[3]);
|
||||
}
|
||||
|
||||
int Quad::minLengthNS() {
|
||||
float Quad::minLengthNS() {
|
||||
return std::min(
|
||||
Segment(c[NW],c[NE]).length(),
|
||||
Segment(c[SE],c[SW]).length()
|
||||
);
|
||||
}
|
||||
|
||||
int Quad::minLengthEW() {
|
||||
float Quad::minLengthEW() {
|
||||
return std::min(
|
||||
Segment(c[NE],c[SE]).length(),
|
||||
Segment(c[SW],c[NW]).length()
|
||||
);
|
||||
}
|
||||
|
||||
int Quad::maxLengthNS() {
|
||||
float Quad::maxLengthNS() {
|
||||
return std::max(
|
||||
Segment(c[NW],c[NE]).length(),
|
||||
Segment(c[SE],c[SW]).length()
|
||||
);
|
||||
}
|
||||
|
||||
int Quad::maxLengthEW() {
|
||||
float Quad::maxLengthEW() {
|
||||
return std::max(
|
||||
Segment(c[NE],c[SE]).length(),
|
||||
Segment(c[SW],c[NW]).length()
|
||||
);
|
||||
}
|
||||
|
||||
int Quad::minLength() {
|
||||
float Quad::minLength() {
|
||||
return std::min(minLengthNS(), minLengthEW());
|
||||
}
|
||||
|
||||
int Quad::maxLength() {
|
||||
float Quad::maxLength() {
|
||||
return std::max(maxLengthNS(), maxLengthEW());
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
// Quad est un quadrilatère
|
||||
class Quad {
|
||||
public :
|
||||
private:
|
||||
Vertex c[4];
|
||||
|
||||
public :
|
||||
|
@ -17,21 +17,21 @@ class Quad {
|
|||
inline const Vertex& operator[] (Coin x) const {
|
||||
return c[x];
|
||||
}
|
||||
inline Quad operator>> (int rot) {
|
||||
inline Quad operator>> (int rot) const {
|
||||
return Quad(c[NE - rot], c[SE - rot], c[SW - rot], c[NW - rot]);
|
||||
}
|
||||
inline Quad operator<< (int rot) {
|
||||
inline Quad operator<< (int rot) const {
|
||||
return Quad(c[NE + rot], c[SE + rot], c[SW + rot], c[NW + rot]);
|
||||
}
|
||||
friend Quad operator+(const Quad& t, const Vertex& v);
|
||||
void offset(Cardinal side, int offset);
|
||||
void offsetNESW(int offsetN, int offsetE, int offsetS, int offsetW);
|
||||
int minLengthNS();
|
||||
int minLengthEW();
|
||||
int maxLengthNS();
|
||||
int maxLengthEW();
|
||||
int minLength();
|
||||
int maxLength();
|
||||
float minLengthNS();
|
||||
float minLengthEW();
|
||||
float maxLengthNS();
|
||||
float maxLengthEW();
|
||||
float minLength();
|
||||
float maxLength();
|
||||
float minAngle();
|
||||
float maxAngle();
|
||||
Quad makeParallelogram();
|
||||
|
|
|
@ -6,27 +6,35 @@ Triangle::Triangle(Vertex left, Vertex top, Vertex right) {
|
|||
c[2] = right;
|
||||
}
|
||||
|
||||
float Triangle::cosAngle() {
|
||||
float Triangle::cosAngle() const {
|
||||
return (c[0]-c[1]).cosAngle(c[2]-c[1]);
|
||||
}
|
||||
|
||||
float Triangle::angle() {
|
||||
float Triangle::angle() const {
|
||||
return std::acos(cosAngle());
|
||||
}
|
||||
|
||||
float Triangle::minAngle() {
|
||||
float Triangle::minAngle() const {
|
||||
float a2 = angle();
|
||||
float a3 = Triangle(c[1],c[2],c[0]).angle();
|
||||
float a1 = Angle::Pi - a2 - a3;
|
||||
return std::min(std::min(a1, a2), a3);
|
||||
}
|
||||
|
||||
float Triangle::minLength() const {
|
||||
return std::min(std::min((c[0] - c[1]).norm(), (c[1] - c[2]).norm()), (c[2] - c[0]).norm());
|
||||
}
|
||||
|
||||
float Triangle::maxLength() const {
|
||||
return std::max(std::max((c[0] - c[1]).norm(), (c[1] - c[2]).norm()), (c[2] - c[0]).norm());
|
||||
}
|
||||
|
||||
void Triangle::offsetBase(int offset) {
|
||||
Quad q = Quad(c[1], c[0], c[2], c[1]);
|
||||
q.offset(S, -offset);
|
||||
c[0] = q.c[1];
|
||||
c[1] = q.c[0];
|
||||
c[2] = q.c[2];
|
||||
c[0] = q[SE];
|
||||
c[1] = q[NE];
|
||||
c[2] = q[SW];
|
||||
}
|
||||
|
||||
Triangle operator+(const Triangle& t, const Vertex& v) {
|
||||
|
|
|
@ -4,28 +4,30 @@
|
|||
#include "all_includes.hh"
|
||||
|
||||
class Triangle {
|
||||
public :
|
||||
private :
|
||||
Vertex c[3];
|
||||
|
||||
public :
|
||||
Triangle();
|
||||
Triangle(Vertex left, Vertex top, Vertex right);
|
||||
inline Vertex& operator[] (SommetTriangle x) {
|
||||
return c[x];
|
||||
return c[x];
|
||||
}
|
||||
inline const Vertex& operator[] (SommetTriangle x) const {
|
||||
return c[x];
|
||||
return c[x];
|
||||
}
|
||||
inline Triangle operator>> (int rot) {
|
||||
return Triangle(c[LEFT - rot], c[TOP - rot], c[RIGHT - rot]);
|
||||
inline Triangle operator>> (int rot) const {
|
||||
return Triangle(c[LEFT - rot], c[TOP - rot], c[RIGHT - rot]);
|
||||
}
|
||||
inline Triangle operator<< (int rot) {
|
||||
return Triangle(c[LEFT + rot], c[TOP + rot], c[RIGHT + rot]);
|
||||
inline Triangle operator<< (int rot) const {
|
||||
return Triangle(c[LEFT + rot], c[TOP + rot], c[RIGHT + rot]);
|
||||
}
|
||||
friend Triangle operator+(const Triangle& t, const Vertex& v);
|
||||
float cosAngle(); // cosinus de l'angle en c[1].
|
||||
float angle(); // angle en c[1], en degrés. TODO : le calcul ne donne que des angles entre 0 et 180 !
|
||||
float minAngle(); // angle minimum du triangle (en c[0], c[1] ou c[2]).
|
||||
float cosAngle() const; // cosinus de l'angle en c[1].
|
||||
float angle() const; // angle en c[1], en degrés. TODO : le calcul ne donne que des angles entre 0 et 180 !
|
||||
float minAngle() const; // angle minimum du triangle (en c[0], c[1] ou c[2]).
|
||||
float minLength() const;
|
||||
float maxLength() const;
|
||||
void offsetBase(int offset);
|
||||
void display();
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ Vertex::Vertex() {}
|
|||
|
||||
Vertex::Vertex(float x, float y, float z): x(x), y(y), z(z) {}
|
||||
|
||||
float Vertex::norm() { return std::sqrt(x*x + y*y + z*z); }
|
||||
float Vertex::norm() const { return std::sqrt(x*x + y*y + z*z); }
|
||||
|
||||
// TODO : this is 2D only, use Vertex2d.
|
||||
Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d) {
|
||||
|
|
|
@ -12,7 +12,7 @@ class Vertex {
|
|||
public :
|
||||
Vertex();
|
||||
Vertex(float x, float y, float z);
|
||||
float norm();
|
||||
float norm() const;
|
||||
Vertex projectOn(Vertex v);
|
||||
Vertex setNorm(float n);
|
||||
Vertex perpendicular(); // Perpendiculaire 2D dans le sens contraire des aiguilles d'une montre.
|
||||
|
|
|
@ -1,33 +1,44 @@
|
|||
#include "all_includes.hh"
|
||||
|
||||
GPUTriangle::GPUTriangle(Vertex left, Vertex top, Vertex right, unsigned char r, unsigned char g, unsigned char b)
|
||||
: r(r), g(g), b(b), vnormal(normal(left,top,right)) {
|
||||
c[0] = left;
|
||||
c[1] = top;
|
||||
c[2] = right;
|
||||
: c(left, top, right), r(r), g(g), b(b), vnormal(normal(left,top,right)) {
|
||||
}
|
||||
|
||||
GPUTriangle::GPUTriangle(Triangle c, unsigned char r, unsigned char g, unsigned char b)
|
||||
: c(c), r(r), g(g), b(b), vnormal(normal(c[LEFT], c[TOP], c[RIGHT])) {
|
||||
}
|
||||
|
||||
Vertex GPUTriangle::normal(Vertex left, Vertex top, Vertex right) {
|
||||
Vertex normal = (left - top)*(top - right);
|
||||
Vertex normal = (left - top)*(right - top);
|
||||
return normal / normal.norm();
|
||||
}
|
||||
|
||||
void GPUTriangle::display() {
|
||||
// glDisable(GL_LIGHTING);
|
||||
// glDisable(GL_TEXTURE_2D);
|
||||
// glBegin(GL_LINES);
|
||||
// glColor3ub(255,255,0);
|
||||
View::setColor(r,g,b);
|
||||
glNormal3d(vnormal.x,vnormal.y,vnormal.z);
|
||||
glVertex3d(c[LEFT].x,c[LEFT].y,c[LEFT].z);
|
||||
glVertex3d(c[TOP].x,c[TOP].y,c[TOP].z);
|
||||
glVertex3d(c[RIGHT].x,c[RIGHT].y,c[RIGHT].z);
|
||||
}
|
||||
|
||||
void GPUTriangle::displayNormal() {
|
||||
glColor3ub(255,255,0);
|
||||
// Vertex v = (c[0] + c[1] + c[2]) / 3;
|
||||
// glVertex3d(v.x,v.y,v.z);
|
||||
// glVertex3d(v.x+vnormal.x*50,v.y+vnormal.y*50,v.z+vnormal.z*50);
|
||||
// glEnd( );
|
||||
// glEnable(GL_LIGHTING);
|
||||
|
||||
View::setColor(r,g,b);
|
||||
glNormal3d(vnormal.x,vnormal.y,vnormal.z);
|
||||
// glBegin(GL_TRIANGLES);
|
||||
glVertex3d(c[0].x,c[0].y,c[0].z);
|
||||
glVertex3d(c[1].x,c[1].y,c[1].z);
|
||||
glVertex3d(c[2].x,c[2].y,c[2].z);
|
||||
// glEnd();
|
||||
glColor3ub(255,0,0);
|
||||
Vertex v = (c[LEFT]*8 + c[TOP] + c[RIGHT]) / 10;//(c[0] + c[1] + c[2]) / 3;
|
||||
glVertex3d(v.x,v.y,v.z);
|
||||
glVertex3d(v.x+vnormal.x*50,v.y+vnormal.y*50,v.z+vnormal.z*50);
|
||||
|
||||
glColor3ub(0,255,0);
|
||||
v = (c[LEFT] + c[TOP]*8 + c[RIGHT]) / 10;
|
||||
glVertex3d(v.x,v.y,v.z);
|
||||
glVertex3d(v.x+vnormal.x*50,v.y+vnormal.y*50,v.z+vnormal.z*50);
|
||||
|
||||
glColor3ub(0,0,255);
|
||||
v = (c[LEFT] + c[TOP] + c[RIGHT]*8) / 10;
|
||||
glVertex3d(v.x,v.y,v.z);
|
||||
glVertex3d(v.x+vnormal.x*50,v.y+vnormal.y*50,v.z+vnormal.z*50);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class GPUTriangle {
|
||||
public :
|
||||
Vertex c[3];
|
||||
Triangle c;
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
|
@ -13,7 +13,9 @@ class GPUTriangle {
|
|||
|
||||
public :
|
||||
GPUTriangle(Vertex left, Vertex top, Vertex right, unsigned char r, unsigned char g, unsigned char b);
|
||||
GPUTriangle(Triangle c, unsigned char r, unsigned char g, unsigned char b);
|
||||
void display();
|
||||
void displayNormal();
|
||||
|
||||
private :
|
||||
Vertex normal(Vertex left, Vertex top, Vertex right);
|
||||
|
|
|
@ -11,9 +11,7 @@ void BatimentQuad::getBoundingBoxPoints() {
|
|||
}
|
||||
|
||||
bool BatimentQuad::split() {
|
||||
int rand = this->seed % 20; // TODO : utiliser les fonctions random in range & co.
|
||||
|
||||
if(rand <= 1) {
|
||||
if(proba(seed, 0, 1, 10)) {
|
||||
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]);
|
||||
// TODO ajouter une classe surface.
|
||||
//addQuad(c[SE],c[SW],c[NW],c[NE],0xDD,0xDD,0xDD);
|
||||
|
@ -21,16 +19,15 @@ bool BatimentQuad::split() {
|
|||
} else {
|
||||
int th = 20; // Terrain height.
|
||||
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]);
|
||||
th = th;
|
||||
q.offset(N,-140);
|
||||
q.offset(E,-140);
|
||||
q.offset(S,-140);
|
||||
q.offset(W,-140);
|
||||
|
||||
addChild(new TrottoirQuadNormal(Quad(c[NE],c[SE],q[SE],q[NE]),th,E));
|
||||
addChild(new TrottoirQuadNormal(Quad(c[SE],c[SW],q[SW],q[SE]),th,E));
|
||||
addChild(new TrottoirQuadNormal(Quad(c[SW],c[NW],q[NW],q[SW]),th,E));
|
||||
addChild(new TrottoirQuadNormal(Quad(c[NW],c[NE],q[NE],q[NW]),th,E));
|
||||
addChild(new TrottoirQuadNormal(Quad(c[NE],c[SE],q[SE],q[NE]),th));
|
||||
addChild(new TrottoirQuadNormal(Quad(c[SE],c[SW],q[SW],q[SE]),th));
|
||||
addChild(new TrottoirQuadNormal(Quad(c[SW],c[NW],q[NW],q[SW]),th));
|
||||
addChild(new TrottoirQuadNormal(Quad(c[NW],c[NE],q[NE],q[NW]),th));
|
||||
|
||||
Quad qh = q + Vertex(0,0,th);
|
||||
addChild(new BatimentQuadJardin(qh));
|
||||
|
@ -44,8 +41,8 @@ bool BatimentQuad::split() {
|
|||
void BatimentQuad::triangulation() {
|
||||
triangles.reserve(12);
|
||||
|
||||
int h = hashInRange(seed,0,minHeight,maxHeight);
|
||||
int htoit = hashInRange(seed,0,minHeight/2,maxHeight/2);
|
||||
int h = hashInRange(seed,1,minHeight,maxHeight);
|
||||
int htoit = hashInRange(seed,2,minHeight/2,maxHeight/2);
|
||||
h += htoit;
|
||||
|
||||
addGPUOcto(c, c + Vertex(0,0,h), 0xFF, 0xFF, 0x00);
|
||||
|
|
|
@ -12,6 +12,5 @@ void BatimentQuadJardin::getBoundingBoxPoints() {
|
|||
void BatimentQuadJardin::triangulation() {
|
||||
triangles.reserve(2);
|
||||
|
||||
addGPUTriangle(new GPUTriangle(c[NE],c[NW],c[SW],0x12,0x64,0x12));
|
||||
addGPUTriangle(new GPUTriangle(c[SW],c[SE],c[NE],0x12,0x64,0x12));
|
||||
addGPUQuad(c, 0x12, 0x64, 0x12);
|
||||
}
|
||||
|
|
|
@ -17,15 +17,10 @@ void BatimentQuadMaison::triangulation() {
|
|||
Quad ch = c + Vertex(0,0,h);
|
||||
Vertex toit = (ch[NE] + ch[SE] + ch[SW] + ch[NW]) / 4 + Vertex(0,0,htoit);
|
||||
|
||||
// 4 Murs
|
||||
addGPUQuad(ch[NE],ch[SE],c[SE],c[NE],0xf1,0xe3,0xad);
|
||||
addGPUQuad(ch[SE],ch[SW],c[SW],c[SE],0xf1,0xe3,0xad);
|
||||
addGPUQuad(ch[SW],ch[NW],c[NW],c[SW],0xf1,0xe3,0xad);
|
||||
addGPUQuad(ch[NW],ch[NE],c[NE],c[NW],0xf1,0xe3,0xad);
|
||||
|
||||
// 1 Toit
|
||||
addGPUTriangle(new GPUTriangle(ch[NE],toit,ch[SE],0x96,0x16,0x18));
|
||||
addGPUTriangle(new GPUTriangle(ch[SE],toit,ch[SW],0x96,0x16,0x18));
|
||||
addGPUTriangle(new GPUTriangle(ch[SW],toit,ch[NW],0x96,0x16,0x18));
|
||||
addGPUTriangle(new GPUTriangle(ch[NW],toit,ch[NE],0x96,0x16,0x18));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// Mur
|
||||
addGPUQuad(c[NE+i],c[SE+i],ch[SE+i],ch[NE+i],0xf1,0xe3,0xad);
|
||||
// Pan du toit
|
||||
addGPUTriangle(ch[SE+i],toit,ch[NE+i],0x96,0x16,0x18);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ void BatimentQuadMaisonPont::getBoundingBoxPoints() {
|
|||
bool BatimentQuadMaisonPont::split() {
|
||||
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]);
|
||||
q.makeParallelogram();
|
||||
if(Segment(q.c[0],q.c[3]).length() < Segment(q.c[0],q.c[1]).length())
|
||||
q = Quad(q.c[1],q.c[2],q.c[3],q.c[0]);
|
||||
float partLength = Segment(q.c[0],q.c[3]).length() / 3;
|
||||
if(Segment(q[NE],q[NW]).length() < Segment(q[NE],q[SE]).length())
|
||||
q = q << 1;
|
||||
float partLength = Segment(q[NE],q[NW]).length() / 3;
|
||||
int partHeight = 2.5*height/3.;
|
||||
Quad qa = q;
|
||||
Quad qb = q;
|
||||
|
@ -36,7 +36,6 @@ bool BatimentQuadMaisonPont::split() {
|
|||
}
|
||||
|
||||
void BatimentQuadMaisonPont::triangulation() {
|
||||
//triangles.reserve(2);
|
||||
float h = 2.5*height/3.;
|
||||
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]).makeParallelogram();
|
||||
Quad qh = q + Vertex(0,0,h);
|
||||
|
@ -47,8 +46,8 @@ void BatimentQuadMaisonPont::triangulation() {
|
|||
Vertex ce = qh[SE] + (qh[NE] - qh[SE])/2 + Vertex(0,0,0.5*height/3.f);
|
||||
Vertex cw = qh[SW] + (qh[NW] - qh[SW])/2 + Vertex(0,0,0.5*height/3.f);
|
||||
|
||||
addGPUTriangle(new GPUTriangle(qh[SW],qh[NW],cw,0xF1,0xE0,0xE0));
|
||||
addGPUTriangle(new GPUTriangle(qh[NE],qh[SE],ce,0xF1,0xE0,0xE0));
|
||||
addGPUTriangle(qh[NW],cw,qh[SW],0xF1,0xE0,0xE0);
|
||||
addGPUTriangle(qh[SE],ce,qh[NE],0xF1,0xE0,0xE0);
|
||||
|
||||
addGPUQuad(qh[NE],qh[NW],cw,ce,0xE0,0x20,0x00);
|
||||
addGPUQuad(qh[SW],qh[SE],ce,cw,0xE0,0x20,0x00);
|
||||
|
|
|
@ -20,7 +20,7 @@ float nt(double x, int height) {
|
|||
void BatimentQuadPont::triangulation() {
|
||||
//triangles.reserve(2);
|
||||
float var;
|
||||
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]);
|
||||
Quad q = c;
|
||||
Vertex a,b;
|
||||
height -= 20;
|
||||
Vertex pa = c[NW];
|
||||
|
@ -36,35 +36,35 @@ void BatimentQuadPont::triangulation() {
|
|||
int middle = steps/2;
|
||||
int n;
|
||||
|
||||
addGPUTriangle(new GPUTriangle(c[SW],pb,ch[SW],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(new GPUTriangle(pa,c[NW],ch[NW],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(c[SW],pb,ch[SW],0xD0,0xD0,0xD0);
|
||||
addGPUTriangle(pa,c[NW],ch[NW],0xD0,0xD0,0xD0);
|
||||
|
||||
for(var=-1.7,n=0; var <= 1.7; var+=pas,n++) {
|
||||
q.offset(W,-n2);
|
||||
a = q.c[3] + Vertex(0,0,nt(var,height));
|
||||
b = q.c[2] + Vertex(0,0,nt(var,height));
|
||||
a = q[NW] + Vertex(0,0,nt(var,height));
|
||||
b = q[SW] + Vertex(0,0,nt(var,height));
|
||||
|
||||
addGPUQuad(a,b,pb,pa,0xD0,0xD0,0xD0);
|
||||
|
||||
if( n < middle) {
|
||||
addGPUTriangle(new GPUTriangle(pa,a,ch[NW],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(new GPUTriangle(b,pb,ch[SW],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(pa,a,ch[NW],0xD0,0xD0,0xD0);
|
||||
addGPUTriangle(b,pb,ch[SW],0xD0,0xD0,0xD0);
|
||||
}
|
||||
else if(n == middle) {
|
||||
addGPUTriangle(new GPUTriangle(pa,a,ch[NW],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(new GPUTriangle(b,pb,ch[SW],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(new GPUTriangle(a,ch[NE],ch[NW],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(new GPUTriangle(b,ch[SW],ch[SE],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(pa,a,ch[NW],0xD0,0xD0,0xD0);
|
||||
addGPUTriangle(b,pb,ch[SW],0xD0,0xD0,0xD0);
|
||||
addGPUTriangle(a,ch[NE],ch[NW],0xD0,0xD0,0xD0);
|
||||
addGPUTriangle(b,ch[SW],ch[SE],0xD0,0xD0,0xD0);
|
||||
}
|
||||
else {
|
||||
addGPUTriangle(new GPUTriangle(pa,a,ch[NE],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(new GPUTriangle(b,pb,ch[SE],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(pa,a,ch[NE],0xD0,0xD0,0xD0);
|
||||
addGPUTriangle(b,pb,ch[SE],0xD0,0xD0,0xD0);
|
||||
}
|
||||
|
||||
pa = a;
|
||||
pb = b;
|
||||
}
|
||||
|
||||
addGPUTriangle(new GPUTriangle(c[SE],pb,ch[SE],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(new GPUTriangle(c[NE],pa,ch[NE],0xD0,0xD0,0xD0));
|
||||
addGPUTriangle(c[SE],pb,ch[SE],0xD0,0xD0,0xD0);
|
||||
addGPUTriangle(c[NE],pa,ch[NE],0xD0,0xD0,0xD0);
|
||||
}
|
||||
|
|
|
@ -10,12 +10,11 @@ void BatimentQuadToit::getBoundingBoxPoints() {
|
|||
}
|
||||
|
||||
void BatimentQuadToit::triangulation() {
|
||||
//triangles.reserve(2);
|
||||
Vertex ce = c[SE] + (c[NE] - c[SE])/2 + Vertex(0,0,height/3.);
|
||||
Vertex cw = c[SW] + (c[NW] - c[SW])/2 + Vertex(0,0,height/3.);
|
||||
|
||||
addGPUTriangle(new GPUTriangle(c[SW],c[NW],cw,0xF1,0xE0,0xE0));
|
||||
addGPUTriangle(new GPUTriangle(c[NE],c[SE],ce,0xF1,0xE0,0xE0));
|
||||
addGPUTriangle(c[NW],cw,c[SW],0xF1,0xE0,0xE0);
|
||||
addGPUTriangle(c[SE],ce,c[NE],0xF1,0xE0,0xE0);
|
||||
|
||||
addGPUQuad(c[NE],c[NW],cw,ce,0xE0,0x20,0x00);
|
||||
addGPUQuad(c[SW],c[SE],ce,cw,0xE0,0x20,0x00);
|
||||
|
|
52
rules/batiment/batimenttri.cpp
Normal file
52
rules/batiment/batimenttri.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "all_includes.hh"
|
||||
|
||||
BatimentTri::BatimentTri(Triangle c) : Chose(), c(c) {
|
||||
addEntropy(c);
|
||||
}
|
||||
|
||||
void BatimentTri::getBoundingBoxPoints() {
|
||||
addBBPoints(c);
|
||||
addBBPoints(c + Vertex(0,0,maxHeight + maxHeight/2)); // TODO
|
||||
}
|
||||
|
||||
bool BatimentTri::split() {
|
||||
return false;
|
||||
// if(proba(seed, 0, 1, 10)) {
|
||||
// Quad q = Quad(c[NE],c[SE],c[SW],c[NW]);
|
||||
// // TODO ajouter une classe surface.
|
||||
// //addQuad(c[SE],c[SW],c[NW],c[NE],0xDD,0xDD,0xDD);
|
||||
// addChild(new BatimentQuadMaisonPont(q,800));
|
||||
// } else {
|
||||
// int th = 20; // Terrain height.
|
||||
// Quad q = Quad(c[NE],c[SE],c[SW],c[NW]);
|
||||
// q.offset(N,-140);
|
||||
// q.offset(E,-140);
|
||||
// q.offset(S,-140);
|
||||
// q.offset(W,-140);
|
||||
|
||||
// addChild(new TrottoirQuadNormal(Quad(c[NE],c[SE],q[SE],q[NE]),th,E));
|
||||
// addChild(new TrottoirQuadNormal(Quad(c[SE],c[SW],q[SW],q[SE]),th,E));
|
||||
// addChild(new TrottoirQuadNormal(Quad(c[SW],c[NW],q[NW],q[SW]),th,E));
|
||||
// addChild(new TrottoirQuadNormal(Quad(c[NW],c[NE],q[NE],q[NW]),th,E));
|
||||
|
||||
// Quad qh = q + Vertex(0,0,th);
|
||||
// addChild(new BatimentQuadJardin(qh));
|
||||
|
||||
// qh.offset(this->entry,-400);
|
||||
// addChild(new BatimentQuadMaison(qh));
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
|
||||
void BatimentTri::triangulation() {
|
||||
int h = hashInRange(seed,1,minHeight,maxHeight);
|
||||
// int htoit = hashInRange(seed,2,minHeight/2,maxHeight/2);
|
||||
// h += htoit;
|
||||
|
||||
// addGPUOcto(c, c + Vertex(0,0,h), 0xFF, 0xFF, 0x00);
|
||||
Triangle ch = c + Vertex(0,0,h);
|
||||
addGPUTriangle(c[LEFT], c[TOP], c[RIGHT], 0xFF, 0xFF, 0x00);
|
||||
addGPUTriangle(ch[LEFT], ch[TOP], ch[RIGHT], 0xFF, 0xFF, 0x00);
|
||||
for (int i = 0; i < 3; i++)
|
||||
addGPUQuad(c[LEFT+i], c[TOP+i], ch[TOP+i], ch[LEFT+i], 0xFF, 0xFF, 0x00);
|
||||
}
|
21
rules/batiment/batimenttri.hh
Normal file
21
rules/batiment/batimenttri.hh
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef _RULES_BATIMENT_BATIMENTTRI_HH_
|
||||
#define _RULES_BATIMENT_BATIMENTTRI_HH_
|
||||
|
||||
#include "all_includes.hh"
|
||||
|
||||
|
||||
class BatimentTri : public Chose {
|
||||
private :
|
||||
Triangle c;
|
||||
|
||||
public :
|
||||
static const int minHeight = 400;
|
||||
static const int maxHeight = 800;
|
||||
|
||||
BatimentTri(Triangle c);
|
||||
virtual bool split();
|
||||
virtual void triangulation();
|
||||
virtual void getBoundingBoxPoints();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -13,37 +13,39 @@ void Chose::addChild(Chose* c) {
|
|||
children.push_back(c);
|
||||
}
|
||||
|
||||
void Chose::addGPUTriangle(GPUTriangle* t) {
|
||||
triangles.push_back(t);
|
||||
}
|
||||
|
||||
bool Chose::merge() {
|
||||
children.clear();
|
||||
// triangles.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Chose::addGPUQuad(Vertex u, Vertex v, Vertex w, Vertex x, char r, char g, char b) {
|
||||
this->addGPUTriangle(new GPUTriangle(u,x,w,r,g,b));
|
||||
this->addGPUTriangle(new GPUTriangle(w,v,u,r,g,b));
|
||||
void Chose::addGPUTriangle(Vertex left, Vertex top, Vertex right, char r, char g, char b) {
|
||||
triangles.push_back(new GPUTriangle(left, top, right, r, g, b));
|
||||
}
|
||||
|
||||
void Chose::addGPUTriangle(Triangle t, char r, char g, char b) {
|
||||
addGPUTriangle(t[LEFT], t[TOP], t[RIGHT], r, g, b);
|
||||
}
|
||||
|
||||
void Chose::addGPUQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, char r, char g, char b) {
|
||||
this->addGPUTriangle(nw,ne,se,r,g,b);
|
||||
this->addGPUTriangle(se,sw,nw,r,g,b);
|
||||
}
|
||||
|
||||
void Chose::addGPUQuad(Quad q, char r, char g, char b) {
|
||||
addGPUQuad(q[NE], q[SE], q[SW], q[NW], r, g, b);
|
||||
}
|
||||
|
||||
void Chose::addGPUOcto(Vertex a, Vertex b, Vertex c, Vertex d,
|
||||
Vertex e, Vertex f, Vertex g, Vertex h, char red, char green, char blue) {
|
||||
this->addGPUQuad(a,b,c,d,red,green,blue);
|
||||
this->addGPUQuad(e,f,g,h,red,green,blue);
|
||||
this->addGPUQuad(b,a,e,f,red,green,blue);
|
||||
this->addGPUQuad(c,b,f,g,red,green,blue);
|
||||
this->addGPUQuad(d,c,g,h,red,green,blue);
|
||||
this->addGPUQuad(a,d,h,e,red,green,blue);
|
||||
void Chose::addGPUOcto(Vertex ne, Vertex se, Vertex sw, Vertex nw,
|
||||
Vertex neh, Vertex seh, Vertex swh, Vertex nwh, char r, char g, char b) {
|
||||
addGPUOcto(Quad(ne,se,sw,nw), Quad(neh,seh,swh,nwh), r, g, b);
|
||||
}
|
||||
|
||||
void Chose::addGPUOcto(Quad q1, Quad q2, char red, char green, char blue) {
|
||||
addGPUOcto(q1[NE], q1[SE], q1[SW], q1[NW], q2[NE], q2[SE], q2[SW], q2[NW], red, green, blue);
|
||||
void Chose::addGPUOcto(Quad q, Quad qh, char r, char g, char b) {
|
||||
this->addGPUQuad(q[NE], q[SE], q[SW], q[NW], r, g, b);
|
||||
this->addGPUQuad(qh[NE], qh[SE], qh[SW], qh[NW], r, g, b);
|
||||
for (int i = 0; i < 4; i++)
|
||||
this->addGPUQuad(q[NE+i], q[SE+i], qh[SE+i], qh[NE+i], r, g, b);
|
||||
}
|
||||
|
||||
void Chose::display() {
|
||||
|
@ -60,6 +62,20 @@ void Chose::display() {
|
|||
}
|
||||
}
|
||||
|
||||
void Chose::displayNormals() {
|
||||
if (children.size() > 0) {
|
||||
std::vector<Chose*>::iterator it;
|
||||
for (it = children.begin(); it != children.end(); ++it) {
|
||||
(*it)->displayNormals();
|
||||
}
|
||||
} else {
|
||||
std::vector<GPUTriangle*>::iterator it;
|
||||
for (it = triangles.begin(); it != triangles.end(); ++it) {
|
||||
(*it)->displayNormal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Chose::addBBPoint(const Vertex v) {
|
||||
if (lod.firstBBPoint) {
|
||||
lod.firstBBPoint = false;
|
||||
|
@ -128,4 +144,4 @@ void Chose::drawAABB() {
|
|||
);
|
||||
}
|
||||
|
||||
unsigned int Chose::initialSeed = random_seed();
|
||||
unsigned int Chose::initialSeed = 1417359759;//random_seed();
|
||||
|
|
|
@ -14,6 +14,7 @@ class Chose {
|
|||
|
||||
public :
|
||||
void display();
|
||||
void displayNormals();
|
||||
void drawAABB(); // DEBUG
|
||||
virtual bool split() { return false; };
|
||||
virtual bool merge();
|
||||
|
@ -59,6 +60,8 @@ class Chose {
|
|||
}
|
||||
void addChild(Chose* c);
|
||||
void addGPUTriangle(GPUTriangle* t);
|
||||
void addGPUTriangle(Vertex left, Vertex top, Vertex right, char r, char g, char b);
|
||||
void addGPUTriangle(Triangle t, char r, char g, char b);
|
||||
void addGPUQuad(Vertex u, Vertex v, Vertex w, Vertex x, char r, char g, char b);
|
||||
void addGPUQuad(Quad q, char r, char g, char b);
|
||||
void addGPUOcto(Vertex a,Vertex b,Vertex c,Vertex d,Vertex e,Vertex f,Vertex g,Vertex h,char red,char green,char blue);
|
||||
|
|
|
@ -39,7 +39,5 @@ bool QuartierQuad::split() {
|
|||
}
|
||||
|
||||
void QuartierQuad::triangulation() {
|
||||
triangles.reserve(2);
|
||||
addGPUTriangle(new GPUTriangle(c[NE], c[NW], c[SW], 0xc0, 0xc0, 0xc0));
|
||||
addGPUTriangle(new GPUTriangle(c[SW], c[SE], c[NE], 0xc0, 0xc0, 0xc0));
|
||||
addGPUQuad(c, 0xc0, 0xc0, 0xc0);
|
||||
}
|
||||
|
|
|
@ -12,8 +12,15 @@ void QuartierTri::getBoundingBoxPoints() {
|
|||
Chose* QuartierTri::factory(int seed, int n, Triangle c) {
|
||||
(void)seed;
|
||||
(void)n;
|
||||
// TODO
|
||||
return new QuartierTri(c);
|
||||
bool small = c.minLength() < 2500;
|
||||
bool big = c.maxLength() >= 5000;
|
||||
if (small && !big) {
|
||||
return new BatimentTri(c);
|
||||
} else if (!small) {
|
||||
return new QuartierTriHauteur(c);
|
||||
} else {
|
||||
return new TerrainTriHerbe(c);
|
||||
}
|
||||
}
|
||||
|
||||
bool QuartierTri::split() {
|
||||
|
@ -22,5 +29,5 @@ bool QuartierTri::split() {
|
|||
|
||||
void QuartierTri::triangulation() {
|
||||
triangles.reserve(1);
|
||||
addGPUTriangle(new GPUTriangle(c[LEFT], c[TOP], c[RIGHT], 0xf0, 0xc0, 0xc0));
|
||||
addGPUTriangle(c, 0xf0, 0xc0, 0xc0);
|
||||
}
|
||||
|
|
|
@ -10,5 +10,5 @@ void RouteTriChaussee::getBoundingBoxPoints() {
|
|||
}
|
||||
|
||||
void RouteTriChaussee::triangulation() {
|
||||
addGPUTriangle(new GPUTriangle(c[LEFT], c[TOP], c[RIGHT], 0x36, 0x36, 0x36));
|
||||
addGPUTriangle(c, 0x36, 0x36, 0x36);
|
||||
}
|
||||
|
|
|
@ -1,45 +1,19 @@
|
|||
#include "all_includes.hh"
|
||||
|
||||
TrottoirQuadNormal::TrottoirQuadNormal(Quad c, int height, Cardinal border) : Chose(), c(c), height(height), border(border) {
|
||||
TrottoirQuadNormal::TrottoirQuadNormal(Quad c, int height) : Chose(), c(c), height(height) {
|
||||
}
|
||||
|
||||
void TrottoirQuadNormal::getBoundingBoxPoints() {
|
||||
addBBPoints(c);
|
||||
addBBPoints(c + Vertex(0,0,height)); // TODO
|
||||
addBBPoints(c + Vertex(0,0,height));
|
||||
}
|
||||
|
||||
void TrottoirQuadNormal::triangulation() {
|
||||
Vertex h = Vertex(0,0,height);
|
||||
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]);
|
||||
Quad ch = c + Vertex(0,0,height);
|
||||
Quad bordureh = ch;
|
||||
bordureh.offset(E,-15);
|
||||
|
||||
if(border == E) {
|
||||
q.offset(E,-15);
|
||||
addGPUTriangle(new GPUTriangle(q.c[0] + h, q.c[3] + h, q.c[2] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(q.c[2] + h, q.c[1] + h, q.c[0] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[NE] + h, q.c[0] + h, q.c[1] + h, 0xAA, 0xAA, 0xAA));
|
||||
addGPUTriangle(new GPUTriangle(q.c[1] + h, c[SE] + h, c[NE] + h, 0xAA, 0xAA, 0xAA));
|
||||
|
||||
addGPUTriangle(new GPUTriangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[SW], c[SW] + h, c[NW] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[NE], c[NE] + h, c[SE] + h, 0xAA, 0xAA, 0xAA));
|
||||
addGPUTriangle(new GPUTriangle(c[SE] + h, c[SE], c[NE], 0xAA, 0xAA, 0xAA));
|
||||
|
||||
addGPUTriangle(new GPUTriangle(c[NE] + h, c[NE], c[NW], 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66));
|
||||
} else {
|
||||
addGPUTriangle(new GPUTriangle(q.c[0] + h, q.c[3] + h, q.c[2] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(q.c[2] + h, q.c[1] + h, q.c[0] + h, 0x66, 0x66, 0x66));
|
||||
|
||||
addGPUTriangle(new GPUTriangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[SW], c[SW] + h, c[NW] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[NE], c[NE] + h, c[SE] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[SE] + h, c[SE], c[NE], 0x66, 0x66, 0x66));
|
||||
|
||||
addGPUTriangle(new GPUTriangle(c[NE] + h, c[NE], c[NW], 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66));
|
||||
addGPUTriangle(new GPUTriangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66));
|
||||
}
|
||||
addGPUQuad(c[NE], c[SE], ch[SE], ch[NE], 0xAA, 0xAA, 0xAA);
|
||||
addGPUQuad(ch[NE], ch[SE], bordureh[SE], bordureh[NE], 0xAA, 0xAA, 0xAA);
|
||||
addGPUQuad(bordureh, 0x66, 0x66, 0x66);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class TrottoirQuadNormal : public Chose {
|
|||
Cardinal border;
|
||||
|
||||
public :
|
||||
TrottoirQuadNormal(Quad c, int height, Cardinal border);
|
||||
TrottoirQuadNormal(Quad c, int height);
|
||||
virtual void triangulation();
|
||||
virtual void getBoundingBoxPoints();
|
||||
};
|
||||
|
|
|
@ -11,6 +11,5 @@ void TerrainQuadHerbe::getBoundingBoxPoints() {
|
|||
|
||||
void TerrainQuadHerbe::triangulation() {
|
||||
triangles.reserve(2);
|
||||
addGPUTriangle(new GPUTriangle(c[NE], c[NW], c[SW], 0x11, 0xaa, 0x22));
|
||||
addGPUTriangle(new GPUTriangle(c[SW], c[SE], c[NE], 0x11, 0xaa, 0x22));
|
||||
addGPUQuad(c, 0x11, 0xaa, 0x22);
|
||||
}
|
||||
|
|
14
rules/terrain/terraintriherbe.cpp
Normal file
14
rules/terrain/terraintriherbe.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "all_includes.hh"
|
||||
|
||||
TerrainTriHerbe::TerrainTriHerbe(Triangle c) : Chose(), c(c) {
|
||||
addEntropy(c);
|
||||
}
|
||||
|
||||
void TerrainTriHerbe::getBoundingBoxPoints() {
|
||||
addBBPoints(c);
|
||||
addBBPoints(c + Vertex(0,0,1000)); // TODO
|
||||
}
|
||||
|
||||
void TerrainTriHerbe::triangulation() {
|
||||
addGPUTriangle(c, 0x11, 0xaa, 0x22);
|
||||
}
|
18
rules/terrain/terraintriherbe.hh
Normal file
18
rules/terrain/terraintriherbe.hh
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef _RULES_TERRAIN_TERRAINTRIHERBE_HH_
|
||||
#define _RULES_TERRAIN_TERRAINTRIHERBE_HH_
|
||||
|
||||
#include "all_includes.hh"
|
||||
|
||||
|
||||
class TerrainTriHerbe : public Chose {
|
||||
private :
|
||||
Triangle c;
|
||||
|
||||
public :
|
||||
TerrainTriHerbe(Triangle c);
|
||||
virtual void triangulation();
|
||||
virtual void getBoundingBoxPoints();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
9
view.cpp
9
view.cpp
|
@ -96,6 +96,15 @@ void View::renderScene(int lastTime, int currentTime) {
|
|||
glBegin(GL_TRIANGLES);
|
||||
root->display();
|
||||
glEnd();
|
||||
if (false) { // displayNormals ?
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glBegin(GL_LINES);
|
||||
root->displayNormals();
|
||||
glEnd();
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glFlush();
|
||||
SDL_GL_SwapBuffers();
|
||||
|
|
Loading…
Reference in New Issue
Block a user