Refactor : utilisation de c[] au lieu de corner, c[] au lieu de v1, v2, v3 pour les triangles, création d'un dossier geometry avec vertex, segment, ..., séparation de Triangle en GPUTriangle et geometry/Triangle.

This commit is contained in:
Georges Dupéron 2012-01-03 18:24:48 +01:00
parent e437287a68
commit 8aee27c488
46 changed files with 477 additions and 483 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@ city
all.cpp
all_includes.hh.gch
city-builder
.cproject
.project

View File

@ -5,8 +5,8 @@ CCWARN=-Wall -Wextra -Werror
# -g -rdynamic uniquement pour le debug.
CFLAGS=-O0 -I. $(CCWARN) -g -rdynamic
SOURCES = $(shell echo *.cpp rules/*.cpp rules/*/*.cpp)
HEADERS = $(shell echo *.hh rules/*.hh rules/*/*.hh)
SOURCES = $(shell echo *.cpp geometry/*.cpp rules/*.cpp rules/*/*.cpp)
HEADERS = $(shell echo *.hh geometry/*.hh rules/*.hh rules/*/*.hh)
LIBS = -lm -lGL -lGLU -lSDL -lGLEW
EXECUTABLE = city

View File

@ -19,13 +19,14 @@ class Chose;
#include <GL/glu.h>
#include <GL/gl.h>
#include "angle.hh"
#include "directions.hh"
#include "vertex.hh"
#include "segment.hh"
#include "triangle.hh"
#include "quad.hh"
#include "geometry/angle.hh"
#include "geometry/directions.hh"
#include "geometry/vertex.hh"
#include "geometry/segment.hh"
#include "geometry/triangle.hh"
#include "geometry/quad.hh"
#include "gputriangle.hh"
#include "hash.hh"
// heap.hh must be included before lod.hh
#include "heap.hh"

102
geometry/quad.cpp Normal file
View File

@ -0,0 +1,102 @@
#include "all_includes.hh"
Quad::Quad() {}
Quad::Quad(Vertex ne, Vertex se, Vertex sw, Vertex nw) {
c[NE] = ne;
c[SE] = se;
c[SW] = sw;
c[NW] = nw;
}
void Quad::offset(Cardinal side, int offset) {
Vertex voffset = (c[NE + side]-c[NW + side]).perpendicular().setNorm(offset);
c[NE + side] = c[NE + side] + voffset.projectOn(c[NE + side]-c[SE + side]);
c[NW + side] = c[NW + side] + voffset.projectOn(c[NW + side]-c[SW + side]);
}
void Quad::offsetNESW(int offsetN, int offsetE, int offsetS, int offsetW) {
this->offset(N,offsetN);
this->offset(E,offsetE);
this->offset(S,offsetS);
this->offset(W,offsetW);
}
Quad Quad::makeParallelogram() {
int l1, l2;
if(Segment(c[NW],c[NE]).length() < Segment(c[SE],c[SW]).length()) {
if((l1 = Segment(c[NE],c[SE]).length()) < (l2 = Segment(c[SW],c[NW]).length())) {
c[SW] = Segment(c[NW],c[SW]).reduce(l1).v;
c[SE] = c[SW] + (c[NE] - c[NW]);
}
else if((l1 = Segment(c[NE],c[SE]).length()) > (l2 = Segment(c[SW],c[NW]).length())) {
c[SE] = Segment(c[NE],c[SE]).reduce(l2).v;
c[SW] = c[SE] + (c[NW] - c[NE]);
}
}
else {
if((l1 = Segment(c[NE],c[SE]).length()) < (l2 = Segment(c[SW],c[NW]).length())) {
c[NW] = Segment(c[SW],c[NW]).reduce(l1).v;
c[NE] = c[NW] + (c[SE] - c[SW]);
}
else if((l1 = Segment(c[NE],c[SE]).length()) > (l2 = Segment(c[SW],c[NW]).length())) {
c[NE] = Segment(c[SE],c[NE]).reduce(l2).v;
c[NW] = c[NE] + (c[SW] - c[SE]);
}
}
return Quad(c[0],c[1],c[2],c[3]);
}
int Quad::minLengthNS() {
return std::min(
Segment(c[NW],c[NE]).length(),
Segment(c[SE],c[SW]).length()
);
}
int Quad::minLengthEW() {
return std::min(
Segment(c[NE],c[SE]).length(),
Segment(c[SW],c[NW]).length()
);
}
int Quad::maxLengthNS() {
return std::max(
Segment(c[NW],c[NE]).length(),
Segment(c[SE],c[SW]).length()
);
}
int Quad::maxLengthEW() {
return std::max(
Segment(c[NE],c[SE]).length(),
Segment(c[SW],c[NW]).length()
);
}
int Quad::minLength() {
return std::min(minLengthNS(), minLengthEW());
}
int Quad::maxLength() {
return std::max(maxLengthNS(), maxLengthEW());
}
float Quad::minAngle() {
float a = 370; // > 360.
for (int i = 0; i < 4; i++) {
a = std::min(a, Triangle(c[NE+i], c[SE+i], c[SW+i]).angle());
}
return a;
}
float Quad::maxAngle() {
float a = 0;
for (int i = 0; i < 4; i++) {
a = std::max(a, Triangle(c[NE+i], c[SE+i], c[SW+i]).angle());
}
return a;
}

View File

@ -6,7 +6,7 @@
// Quad est un quadrilatère
class Quad {
public :
Vertex corner[4];
Vertex c[4];
public :
Quad();

30
geometry/triangle.cpp Normal file
View File

@ -0,0 +1,30 @@
Triangle::Triangle() {
}
Triangle::Triangle(Vertex left, Vertex top, Vertex right) {
c[0] = left;
c[1] = top;
c[2] = right;
}
float Triangle::cosAngle() {
return (c[0]-c[1]).cosAngle(c[2]-c[1]);
}
float Triangle::angle() {
return std::acos(cosAngle());
}
float Triangle::minAngle() {
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);
}
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];
}

20
geometry/triangle.hh Normal file
View File

@ -0,0 +1,20 @@
#ifndef _GEOMETRY_TRIANGLE_HH_
#define _GEOMETRY_TRIANGLE_HH_
#include "all_includes.hh"
class Triangle {
public :
Vertex c[3];
public :
Triangle();
Triangle(Vertex left, Vertex top, Vertex right);
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]).
void offsetBase(int offset);
void display();
};
#endif

33
gputriangle.cpp Normal file
View File

@ -0,0 +1,33 @@
#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;
}
Vertex GPUTriangle::normal(Vertex left, Vertex top, Vertex right) {
Vertex normal = (left - top)*(top - right);
return normal / normal.norm();
}
void GPUTriangle::display() {
// glDisable(GL_LIGHTING);
// glDisable(GL_TEXTURE_2D);
// glBegin(GL_LINES);
// 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();
}

22
gputriangle.hh Normal file
View File

@ -0,0 +1,22 @@
#ifndef _GPU_TRIANGLE_HH_
#define _GPU_TRIANGLE_HH_
#include "all_includes.hh"
class GPUTriangle {
public :
Vertex c[3];
unsigned char r;
unsigned char g;
unsigned char b;
Vertex vnormal;
public :
GPUTriangle(Vertex left, Vertex top, Vertex right, unsigned char r, unsigned char g, unsigned char b);
void display();
private :
Vertex normal(Vertex left, Vertex top, Vertex right);
};
#endif

102
quad.cpp
View File

@ -1,102 +0,0 @@
#include "all_includes.hh"
Quad::Quad() {}
Quad::Quad(Vertex ne, Vertex se, Vertex sw, Vertex nw) {
corner[NE] = ne;
corner[SE] = se;
corner[SW] = sw;
corner[NW] = nw;
}
void Quad::offset(Cardinal side, int offset) {
Vertex voffset = (corner[NE + side]-corner[NW + side]).perpendicular().setNorm(offset);
corner[NE + side] = corner[NE + side] + voffset.projectOn(corner[NE + side]-corner[SE + side]);
corner[NW + side] = corner[NW + side] + voffset.projectOn(corner[NW + side]-corner[SW + side]);
}
void Quad::offsetNESW(int offsetN, int offsetE, int offsetS, int offsetW) {
this->offset(N,offsetN);
this->offset(E,offsetE);
this->offset(S,offsetS);
this->offset(W,offsetW);
}
Quad 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]);
}
}
return Quad(corner[0],corner[1],corner[2],corner[3]);
}
int Quad::minLengthNS() {
return std::min(
Segment(corner[NW],corner[NE]).length(),
Segment(corner[SE],corner[SW]).length()
);
}
int Quad::minLengthEW() {
return std::min(
Segment(corner[NE],corner[SE]).length(),
Segment(corner[SW],corner[NW]).length()
);
}
int Quad::maxLengthNS() {
return std::max(
Segment(corner[NW],corner[NE]).length(),
Segment(corner[SE],corner[SW]).length()
);
}
int Quad::maxLengthEW() {
return std::max(
Segment(corner[NE],corner[SE]).length(),
Segment(corner[SW],corner[NW]).length()
);
}
int Quad::minLength() {
return std::min(minLengthNS(), minLengthEW());
}
int Quad::maxLength() {
return std::max(maxLengthNS(), maxLengthEW());
}
float Quad::minAngle() {
float a = 370; // > 360.
for (int i = 0; i < 4; i++) {
a = std::min(a, Triangle(corner[NE+i], corner[SE+i], corner[SW+i]).angle());
}
return a;
}
float Quad::maxAngle() {
float a = 0;
for (int i = 0; i < 4; i++) {
a = std::max(a, Triangle(corner[NE+i], corner[SE+i], corner[SW+i]).angle());
}
return a;
}

View File

@ -3,8 +3,7 @@
BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal entry) : Chose() {
addEntropy(ne, se, sw, nw);
this->entry = entry;
lctr = (ne + se + sw + nw) / 4;
c[NE] = ne;//-lctr;
c[NE] = ne;//-lctr;
c[SE] = se;//-lctr;
c[SW] = sw;//-lctr;
c[NW] = nw;//-lctr;
@ -33,7 +32,7 @@ bool BatimentQuad::split() {
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.corner[0],q.corner[1],q.corner[2],q.corner[3],800));
addChild(new BatimentQuadMaisonPont(q.c[0],q.c[1],q.c[2],q.c[3],800));
}
else {
int th = 20; // Terrain height.
@ -44,21 +43,21 @@ bool BatimentQuad::split() {
q.offset(S,-140);
q.offset(W,-140);
addChild(new TrottoirQuadNormal(c[NE],c[SE],q.corner[1],q.corner[0],th,E));
addChild(new TrottoirQuadNormal(c[SE],c[SW],q.corner[2],q.corner[1],th,E));
addChild(new TrottoirQuadNormal(c[SW],c[NW],q.corner[3],q.corner[2],th,E));
addChild(new TrottoirQuadNormal(c[NW],c[NE],q.corner[0],q.corner[3],th,E));
addChild(new TrottoirQuadNormal(c[NE],c[SE],q.c[1],q.c[0],th,E));
addChild(new TrottoirQuadNormal(c[SE],c[SW],q.c[2],q.c[1],th,E));
addChild(new TrottoirQuadNormal(c[SW],c[NW],q.c[3],q.c[2],th,E));
addChild(new TrottoirQuadNormal(c[NW],c[NE],q.c[0],q.c[3],th,E));
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.c[0] = q.c[0] + Vertex(0,0,th);
q.c[1] = q.c[1] + Vertex(0,0,th);
q.c[2] = q.c[2] + Vertex(0,0,th);
q.c[3] = q.c[3] + Vertex(0,0,th);
addChild(new BatimentQuadJardin(q.corner[0],q.corner[1],q.corner[2],q.corner[3]));
addChild(new BatimentQuadJardin(q.c[0],q.c[1],q.c[2],q.c[3]));
q.offset(this->entry,-400);
addChild(new BatimentQuadMaison(q.corner[0],q.corner[1],q.corner[2],q.corner[3]));
addChild(new BatimentQuadMaison(q.c[0],q.c[1],q.c[2],q.c[3]));
}
return true;
}

View File

@ -2,8 +2,7 @@
BatimentQuadBlock::BatimentQuadBlock(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() {
addEntropy(ne, se, sw, nw);
lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f);
c[NE] = ne;
c[NE] = ne;
c[SE] = se;
c[SW] = sw;
c[NW] = nw;

View File

@ -2,11 +2,10 @@
BatimentQuadJardin::BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
addEntropy(ne, se, sw, nw);
lctr = (ne + se + sw + nw) / 4;
corner[NE] = ne;//-lctr;
corner[SE] = se;//-lctr;
corner[SW] = sw;//-lctr;
corner[NW] = nw;//-lctr;
c[NE] = ne;
c[SE] = se;
c[SW] = sw;
c[NW] = nw;
}
BatimentQuadJardin::~BatimentQuadJardin() {
@ -15,14 +14,14 @@ BatimentQuadJardin::~BatimentQuadJardin() {
}
void BatimentQuadJardin::getBoundingBoxPoints() {
addBBPoint(corner[NE]);
addBBPoint(corner[SE]);
addBBPoint(corner[SW]);
addBBPoint(corner[NW]);
addBBPoint(corner[NE] + Vertex(0,0,200)); // TODO
addBBPoint(corner[SE] + Vertex(0,0,200));
addBBPoint(corner[SW] + Vertex(0,0,200));
addBBPoint(corner[NW] + Vertex(0,0,200));
addBBPoint(c[NE]);
addBBPoint(c[SE]);
addBBPoint(c[SW]);
addBBPoint(c[NW]);
addBBPoint(c[NE] + Vertex(0,0,200)); // TODO
addBBPoint(c[SE] + Vertex(0,0,200));
addBBPoint(c[SW] + Vertex(0,0,200));
addBBPoint(c[NW] + Vertex(0,0,200));
}
bool BatimentQuadJardin::split() {
@ -32,6 +31,6 @@ bool BatimentQuadJardin::split() {
void BatimentQuadJardin::triangulation() {
triangles.reserve(2);
addTriangle(new Triangle(/*lctr+*/corner[NE],/*lctr+*/corner[NW],/*lctr+*/corner[SW],0x12,0x64,0x12));
addTriangle(new Triangle(/*lctr+*/corner[SW],/*lctr+*/corner[SE],/*lctr+*/corner[NE],0x12,0x64,0x12));
addTriangle(new GPUTriangle(/*lctr+*/c[NE],/*lctr+*/c[NW],/*lctr+*/c[SW],0x12,0x64,0x12));
addTriangle(new GPUTriangle(/*lctr+*/c[SW],/*lctr+*/c[SE],/*lctr+*/c[NE],0x12,0x64,0x12));
}

View File

@ -6,7 +6,7 @@
class BatimentQuadJardin : public Chose {
private :
Vertex corner[4];
Vertex c[4];
public :
static const int minHeight = 400;

View File

@ -2,11 +2,10 @@
BatimentQuadMaison::BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
addEntropy(ne, se, sw, nw);
lctr = (ne + se + sw + nw) / 4;
corner[NE] = ne;//-lctr;
corner[SE] = se;//-lctr;
corner[SW] = sw;//-lctr;
corner[NW] = nw;//-lctr;
c[NE] = ne;
c[SE] = se;
c[SW] = sw;
c[NW] = nw;
}
BatimentQuadMaison::~BatimentQuadMaison() {
@ -15,14 +14,14 @@ BatimentQuadMaison::~BatimentQuadMaison() {
}
void BatimentQuadMaison::getBoundingBoxPoints() {
addBBPoint(corner[NE]);
addBBPoint(corner[SE]);
addBBPoint(corner[SW]);
addBBPoint(corner[NW]);
addBBPoint(corner[NE] + Vertex(0,0,maxHeight + maxHeight/2)); // TODO
addBBPoint(corner[SE] + Vertex(0,0,maxHeight + maxHeight/2));
addBBPoint(corner[SW] + Vertex(0,0,maxHeight + maxHeight/2));
addBBPoint(corner[NW] + Vertex(0,0,maxHeight + maxHeight/2));
addBBPoint(c[NE]);
addBBPoint(c[SE]);
addBBPoint(c[SW]);
addBBPoint(c[NW]);
addBBPoint(c[NE] + Vertex(0,0,maxHeight + maxHeight/2)); // TODO
addBBPoint(c[SE] + Vertex(0,0,maxHeight + maxHeight/2));
addBBPoint(c[SW] + Vertex(0,0,maxHeight + maxHeight/2));
addBBPoint(c[NW] + Vertex(0,0,maxHeight + maxHeight/2));
}
bool BatimentQuadMaison::split() {
@ -34,21 +33,21 @@ void BatimentQuadMaison::triangulation() {
int h = hashInRange(seed,0,minHeight,maxHeight);
int htoit = hashInRange(seed,0,minHeight/2,maxHeight/2);
Vertex neh = corner[NE] + Vertex(0,0,h);
Vertex seh = corner[SE] + Vertex(0,0,h);
Vertex nwh = corner[NW] + Vertex(0,0,h);
Vertex swh = corner[SW] + Vertex(0,0,h);
Vertex neh = c[NE] + Vertex(0,0,h);
Vertex seh = c[SE] + Vertex(0,0,h);
Vertex nwh = c[NW] + Vertex(0,0,h);
Vertex swh = c[SW] + Vertex(0,0,h);
Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit);
// 4 Murs
addQuad(/*lctr+*/neh,/*lctr+*/seh,/*lctr+*/corner[SE],/*lctr+*/corner[NE],0xf1,0xe3,0xad);
addQuad(/*lctr+*/seh,/*lctr+*/swh,/*lctr+*/corner[SW],/*lctr+*/corner[SE],0xf1,0xe3,0xad);
addQuad(/*lctr+*/swh,/*lctr+*/nwh,/*lctr+*/corner[NW],/*lctr+*/corner[SW],0xf1,0xe3,0xad);
addQuad(/*lctr+*/nwh,/*lctr+*/neh,/*lctr+*/corner[NE],/*lctr+*/corner[NW],0xf1,0xe3,0xad);
addQuad(/*lctr+*/neh,/*lctr+*/seh,/*lctr+*/c[SE],/*lctr+*/c[NE],0xf1,0xe3,0xad);
addQuad(/*lctr+*/seh,/*lctr+*/swh,/*lctr+*/c[SW],/*lctr+*/c[SE],0xf1,0xe3,0xad);
addQuad(/*lctr+*/swh,/*lctr+*/nwh,/*lctr+*/c[NW],/*lctr+*/c[SW],0xf1,0xe3,0xad);
addQuad(/*lctr+*/nwh,/*lctr+*/neh,/*lctr+*/c[NE],/*lctr+*/c[NW],0xf1,0xe3,0xad);
// 1 Toit
addTriangle(new Triangle(/*lctr+*/neh,/*lctr+*/toit,/*lctr+*/seh,0x96,0x16,0x18));
addTriangle(new Triangle(/*lctr+*/seh,/*lctr+*/toit,/*lctr+*/swh,0x96,0x16,0x18));
addTriangle(new Triangle(/*lctr+*/swh,/*lctr+*/toit,/*lctr+*/nwh,0x96,0x16,0x18));
addTriangle(new Triangle(/*lctr+*/nwh,/*lctr+*/toit,/*lctr+*/neh,0x96,0x16,0x18));
addTriangle(new GPUTriangle(/*lctr+*/neh,/*lctr+*/toit,/*lctr+*/seh,0x96,0x16,0x18));
addTriangle(new GPUTriangle(/*lctr+*/seh,/*lctr+*/toit,/*lctr+*/swh,0x96,0x16,0x18));
addTriangle(new GPUTriangle(/*lctr+*/swh,/*lctr+*/toit,/*lctr+*/nwh,0x96,0x16,0x18));
addTriangle(new GPUTriangle(/*lctr+*/nwh,/*lctr+*/toit,/*lctr+*/neh,0x96,0x16,0x18));
}

View File

@ -6,7 +6,7 @@
class BatimentQuadMaison : public Chose {
private :
Vertex corner[4];
Vertex c[4];
public :
static const int minHeight = 400;

View File

@ -28,9 +28,9 @@ void BatimentQuadMaisonPont::getBoundingBoxPoints() {
bool BatimentQuadMaisonPont::split() {
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]);
q.makeParallelogram();
if(Segment(q.corner[0],q.corner[3]).length() < Segment(q.corner[0],q.corner[1]).length())
q = Quad(q.corner[1],q.corner[2],q.corner[3],q.corner[0]);
float partLength = Segment(q.corner[0],q.corner[3]).length() / 3;
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;
int partHeight = 2.5*height/3.;
Quad qa = q;
Quad qb = q;
@ -41,39 +41,39 @@ bool BatimentQuadMaisonPont::split() {
qc.offset(E, -partLength);
qc.offset(W, -partLength);
Vertex se = qa.corner[0];
Vertex sw = qa.corner[1];
Vertex nw = qa.corner[2];
Vertex ne = qa.corner[3];
Vertex se = qa.c[0];
Vertex sw = qa.c[1];
Vertex nw = qa.c[2];
Vertex ne = qa.c[3];
addChild(new BatimentQuadJardin(c[SE],c[SW],c[NW],c[NE]));
addChild(new BatimentQuadBlock(ne,se,sw,nw,partHeight));
se = qb.corner[0];
sw = qb.corner[1];
nw = qb.corner[2];
ne = qb.corner[3];
se = qb.c[0];
sw = qb.c[1];
nw = qb.c[2];
ne = qb.c[3];
addChild(new BatimentQuadBlock(ne,se,sw,nw,partHeight));
se = qh.corner[0] + Vertex(0,0,partHeight);
sw = qh.corner[1] + Vertex(0,0,partHeight);
nw = qh.corner[2] + Vertex(0,0,partHeight);
ne = qh.corner[3] + Vertex(0,0,partHeight);
se = qh.c[0] + Vertex(0,0,partHeight);
sw = qh.c[1] + Vertex(0,0,partHeight);
nw = qh.c[2] + Vertex(0,0,partHeight);
ne = qh.c[3] + Vertex(0,0,partHeight);
addChild(new BatimentQuadBlock(ne,se,sw,nw,partHeight));
se = qc.corner[0];
sw = qc.corner[1];
nw = qc.corner[2];
ne = qc.corner[3];
se = qc.c[0];
sw = qc.c[1];
nw = qc.c[2];
ne = qc.c[3];
addChild(new BatimentQuadPont(se,sw,nw,ne,partHeight));
Vertex seh = qh.corner[0] + Vertex(0,0,2*partHeight);
Vertex swh = qh.corner[1] + Vertex(0,0,2*partHeight);
Vertex nwh = qh.corner[2] + Vertex(0,0,2*partHeight);
Vertex neh = qh.corner[3] + Vertex(0,0,2*partHeight);
Vertex seh = qh.c[0] + Vertex(0,0,2*partHeight);
Vertex swh = qh.c[1] + Vertex(0,0,2*partHeight);
Vertex nwh = qh.c[2] + Vertex(0,0,2*partHeight);
Vertex neh = qh.c[3] + Vertex(0,0,2*partHeight);
addChild(new BatimentQuadToit(seh,swh,nwh,neh,150));
@ -84,19 +84,19 @@ void BatimentQuadMaisonPont::triangulation() {
//triangles.reserve(2);
float h = 2.5*height/3.;
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]).makeParallelogram();
Vertex seh = q.corner[SE] + Vertex(0,0,h);
Vertex swh = q.corner[SW] + Vertex(0,0,h);
Vertex nwh = q.corner[NW] + Vertex(0,0,h);
Vertex neh = q.corner[NE] + Vertex(0,0,h);
Vertex seh = q.c[SE] + Vertex(0,0,h);
Vertex swh = q.c[SW] + Vertex(0,0,h);
Vertex nwh = q.c[NW] + Vertex(0,0,h);
Vertex neh = q.c[NE] + Vertex(0,0,h);
addQuad(c[SE],c[SW],c[NW],c[NE],0x80,0x80,0x80);
addOcto(q.corner[NE],q.corner[SE],q.corner[SW],q.corner[NW],neh,seh,swh,nwh,0xF1,0xE0,0xE0);
addOcto(q.c[NE],q.c[SE],q.c[SW],q.c[NW],neh,seh,swh,nwh,0xF1,0xE0,0xE0);
Vertex ce = seh + (neh - seh)/2 + Vertex(0,0,0.5*height/3.);
Vertex cw = swh + (nwh - swh)/2 + Vertex(0,0,0.5*height/3.);
addTriangle(new Triangle(swh,nwh,cw,0xF1,0xE0,0xE0));
addTriangle(new Triangle(neh,seh,ce,0xF1,0xE0,0xE0));
addTriangle(new GPUTriangle(swh,nwh,cw,0xF1,0xE0,0xE0));
addTriangle(new GPUTriangle(neh,seh,ce,0xF1,0xE0,0xE0));
addQuad(neh,nwh,cw,ce,0xE0,0x20,0x00);
addQuad(swh,seh,ce,cw,0xE0,0x20,0x00);

View File

@ -59,35 +59,35 @@ void BatimentQuadPont::triangulation() {
int middle = steps/2;
int n;
addTriangle(new Triangle(c[SW],pb,swh,0xD0,0xD0,0xD0));
addTriangle(new Triangle(pa,c[NW],nwh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(c[SW],pb,swh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(pa,c[NW],nwh,0xD0,0xD0,0xD0));
for(var=-1.7,n=0; var <= 1.7; var+=pas,n++) {
q.offset(W,-n2);
a = q.corner[3] + Vertex(0,0,nt(var,height));
b = q.corner[2] + Vertex(0,0,nt(var,height));
a = q.c[3] + Vertex(0,0,nt(var,height));
b = q.c[2] + Vertex(0,0,nt(var,height));
addQuad(a,b,pb,pa,0xD0,0xD0,0xD0);
if( n < middle) {
addTriangle(new Triangle(pa,a,nwh,0xD0,0xD0,0xD0));
addTriangle(new Triangle(b,pb,swh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(pa,a,nwh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(b,pb,swh,0xD0,0xD0,0xD0));
}
else if(n == middle) {
addTriangle(new Triangle(pa,a,nwh,0xD0,0xD0,0xD0));
addTriangle(new Triangle(b,pb,swh,0xD0,0xD0,0xD0));
addTriangle(new Triangle(a,neh,nwh,0xD0,0xD0,0xD0));
addTriangle(new Triangle(b,swh,seh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(pa,a,nwh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(b,pb,swh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(a,neh,nwh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(b,swh,seh,0xD0,0xD0,0xD0));
}
else {
addTriangle(new Triangle(pa,a,neh,0xD0,0xD0,0xD0));
addTriangle(new Triangle(b,pb,seh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(pa,a,neh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(b,pb,seh,0xD0,0xD0,0xD0));
}
pa = a;
pb = b;
}
addTriangle(new Triangle(c[SE],pb,seh,0xD0,0xD0,0xD0));
addTriangle(new Triangle(c[NE],pa,neh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(c[SE],pb,seh,0xD0,0xD0,0xD0));
addTriangle(new GPUTriangle(c[NE],pa,neh,0xD0,0xD0,0xD0));
}

View File

@ -34,8 +34,8 @@ void BatimentQuadToit::triangulation() {
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.);
addTriangle(new Triangle(c[SW],c[NW],cw,0xF1,0xE0,0xE0));
addTriangle(new Triangle(c[NE],c[SE],ce,0xF1,0xE0,0xE0));
addTriangle(new GPUTriangle(c[SW],c[NW],cw,0xF1,0xE0,0xE0));
addTriangle(new GPUTriangle(c[NE],c[SE],ce,0xF1,0xE0,0xE0));
addQuad(c[NE],c[NW],cw,ce,0xE0,0x20,0x00);
addQuad(c[SW],c[SE],ce,cw,0xE0,0x20,0x00);

View File

@ -7,7 +7,7 @@ void Chose::addChild(Chose* c) {
children.push_back(c);
}
void Chose::addTriangle(Triangle* t) {
void Chose::addTriangle(GPUTriangle* t) {
triangles.push_back(t);
}
@ -18,8 +18,8 @@ bool Chose::merge() {
}
void Chose::addQuad(Vertex u, Vertex v, Vertex w, Vertex x, char r, char g, char b) {
this->addTriangle(new Triangle(u,x,w,r,g,b));
this->addTriangle(new Triangle(w,v,u,r,g,b));
this->addTriangle(new GPUTriangle(u,x,w,r,g,b));
this->addTriangle(new GPUTriangle(w,v,u,r,g,b));
}
void Chose::addOcto(Vertex a, Vertex b, Vertex c, Vertex d,
@ -39,7 +39,7 @@ void Chose::display() {
(*it)->display();
}
} else {
std::vector<Triangle*>::iterator it;
std::vector<GPUTriangle*>::iterator it;
for (it = triangles.begin(); it != triangles.end(); ++it) {
(*it)->display();
}

View File

@ -9,9 +9,8 @@ class Chose {
static unsigned int initialSeed;
unsigned int seed;
std::vector<Chose*> children;
std::vector<Triangle*> triangles;
std::vector<GPUTriangle*> triangles;
LodNode lod;
Vertex lctr; // Local center;
public :
void display();
@ -50,7 +49,7 @@ class Chose {
addEntropy(v1, v2); addEntropy(v3, v4);
}
void addChild(Chose* c);
void addTriangle(Triangle* t);
void addTriangle(GPUTriangle* t);
void addQuad(Vertex u, Vertex v, Vertex w, Vertex x, char r, char g, char b);
void addOcto(Vertex a,Vertex b,Vertex c,Vertex d,Vertex e,Vertex f,Vertex g,Vertex h,char red,char green,char blue);
};

View File

@ -2,10 +2,10 @@
QuartierQuad::QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
addEntropy(ne, se, sw, nw);
corner[NE] = ne;
corner[SE] = se;
corner[SW] = sw;
corner[NW] = nw;
c[NE] = ne;
c[SE] = se;
c[SW] = sw;
c[NW] = nw;
}
QuartierQuad::~QuartierQuad() {
@ -14,14 +14,14 @@ QuartierQuad::~QuartierQuad() {
}
void QuartierQuad::getBoundingBoxPoints() {
addBBPoint(corner[NE]);
addBBPoint(corner[SE]);
addBBPoint(corner[SW]);
addBBPoint(corner[NW]);
addBBPoint(corner[NE] + Vertex(0,0,1000)); // TODO
addBBPoint(corner[SE] + Vertex(0,0,1000));
addBBPoint(corner[SW] + Vertex(0,0,1000));
addBBPoint(corner[NW] + Vertex(0,0,1000));
addBBPoint(c[NE]);
addBBPoint(c[SE]);
addBBPoint(c[SW]);
addBBPoint(c[NW]);
addBBPoint(c[NE] + Vertex(0,0,1000)); // TODO
addBBPoint(c[SE] + Vertex(0,0,1000));
addBBPoint(c[SW] + Vertex(0,0,1000));
addBBPoint(c[NW] + Vertex(0,0,1000));
}
Chose* QuartierQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw) {
@ -56,6 +56,6 @@ bool QuartierQuad::split() {
void QuartierQuad::triangulation() {
triangles.reserve(2);
addTriangle(new Triangle(corner[NE], corner[NW], corner[SW], 0xc0, 0xc0, 0xc0));
addTriangle(new Triangle(corner[SW], corner[SE], corner[NE], 0xc0, 0xc0, 0xc0));
addTriangle(new GPUTriangle(c[NE], c[NW], c[SW], 0xc0, 0xc0, 0xc0));
addTriangle(new GPUTriangle(c[SW], c[SE], c[NE], 0xc0, 0xc0, 0xc0));
}

View File

@ -6,7 +6,7 @@
class QuartierQuad : public Chose {
public:
Vertex corner[4];
Vertex c[4];
public:
QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw);
virtual ~QuartierQuad();

View File

@ -10,51 +10,51 @@ QuartierQuadAngle::~QuartierQuadAngle() {
bool QuartierQuadAngle::split() {
for (int i = 0; i < 4; i++) {
if (Triangle(corner[NW+i], corner[NE+i], corner[SE+i]).angle() >= Angle::d2r(130)) {
Triangle t1(corner[NE+i], corner[SE+i], corner[SW+i]);
if (Triangle(c[NW+i], c[NE+i], c[SE+i]).angle() >= Angle::d2r(130)) {
Triangle t1(c[NE+i], c[SE+i], c[SW+i]);
t1.offsetBase(-hrw);
Triangle t2(corner[SW+i], corner[NW+i], corner[NE+i]);
Triangle t2(c[SW+i], c[NW+i], c[NE+i]);
t2.offsetBase(-hrw);
addChild(QuartierTri::factory(seed, 0, t1.v1, t1.v2, t1.v3));
addChild(QuartierTri::factory(seed, 1, t2.v1, t2.v2, t2.v3));
addChild(new RouteQuadChaussee(t1.v1, t1.v3, t2.v1, t2.v3));
addChild(new RouteTriChaussee(t1.v1, corner[NE+i], t2.v3));
addChild(new RouteTriChaussee(t2.v1, corner[SW+i], t1.v3));
addChild(QuartierTri::factory(seed, 0, t1.c[0], t1.c[1], t1.c[2]));
addChild(QuartierTri::factory(seed, 1, t2.c[0], t2.c[1], t2.c[2]));
addChild(new RouteQuadChaussee(t1.c[0], t1.c[2], t2.c[0], t2.c[2]));
addChild(new RouteTriChaussee(t1.c[0], c[NE+i], t2.c[2]));
addChild(new RouteTriChaussee(t2.c[0], c[SW+i], t1.c[2]));
return true;
}
}
for (int i = 0; i < 4; i++) {
if (Triangle(corner[NW+i], corner[NE+i], corner[SE+i]).angle() <= Angle::d2r(50)) {
if (Triangle(c[NW+i], c[NE+i], c[SE+i]).angle() <= Angle::d2r(50)) {
// "couper ce coin".
Vertex n = Segment(corner[NW+i], corner[NE+i]).randomPos(seed, 0, 40, 60);
Vertex e = Segment(corner[NE+i], corner[SE+i]).randomPos(seed, 1, 40, 60);
Triangle tn = Triangle(n, corner[NE+i], corner[SE+i]);
Triangle te = Triangle(corner[NW+i], corner[NE+i], e);
Vertex n = Segment(c[NW+i], c[NE+i]).randomPos(seed, 0, 40, 60);
Vertex e = Segment(c[NE+i], c[SE+i]).randomPos(seed, 1, 40, 60);
Triangle tn = Triangle(n, c[NE+i], c[SE+i]);
Triangle te = Triangle(c[NW+i], c[NE+i], e);
Quad q;
if (tn.minAngle() > te.minAngle()) {
q = Quad(n, corner[SE+i], corner[SW+i], corner[NW+i]);
Vertex oldv3 = tn.v3;
q = Quad(n, c[SE+i], c[SW+i], c[NW+i]);
Vertex oldtnc2 = tn.c[2];
tn.offsetBase(-hrw);
q.offset(E, -hrw);
addChild(QuartierTri::factory(seed, 0, tn.v1, tn.v2, tn.v3));
addChild(QuartierQuad::factory(seed, 1, q.corner[0], q.corner[1], q.corner[2], q.corner[3]));
addChild(new RouteQuadChaussee(tn.v1, tn.v3, q.corner[1], q.corner[0]));
addChild(new RouteTriChaussee(q.corner[1], oldv3, tn.v3));
addChild(QuartierTri::factory(seed, 0, tn.c[0], tn.c[1], tn.c[2]));
addChild(QuartierQuad::factory(seed, 1, q.c[0], q.c[1], q.c[2], q.c[3]));
addChild(new RouteQuadChaussee(tn.c[0], tn.c[2], q.c[1], q.c[0]));
addChild(new RouteTriChaussee(q.c[1], oldtnc2, tn.c[2]));
} else {
q = Quad(corner[NW+i], e, corner[SE+i], corner[SW+i]);
Vertex oldv1 = te.v1;
q = Quad(c[NW+i], e, c[SE+i], c[SW+i]);
Vertex oldtec0 = te.c[0];
te.offsetBase(-hrw);
q.offset(E, -hrw);
addChild(QuartierTri::factory(seed, 0, te.v1, te.v2, te.v3));
addChild(QuartierQuad::factory(seed, 1, q.corner[0], q.corner[1], q.corner[2], q.corner[3]));
addChild(new RouteQuadChaussee(te.v1, te.v3, q.corner[1], q.corner[0]));
addChild(new RouteTriChaussee(te.v1, oldv1, q.corner[0]));
addChild(QuartierTri::factory(seed, 0, te.c[0], te.c[1], te.c[2]));
addChild(QuartierQuad::factory(seed, 1, q.c[0], q.c[1], q.c[2], q.c[3]));
addChild(new RouteQuadChaussee(te.c[0], te.c[2], q.c[1], q.c[0]));
addChild(new RouteTriChaussee(te.c[0], oldtec0, q.c[0]));
}
return true;
}
}
// Ne devait jamais arriver ici !
addChild(new TerrainQuadHerbe(corner[NE], corner[SE], corner[SW], corner[NW]));
addChild(new TerrainQuadHerbe(c[NE], c[SE], c[SW], c[NW]));
return true;
}

View File

@ -12,21 +12,21 @@ bool QuartierQuadCarre::split() {
Vertex middle[4];
Quad q[4];
Vertex cn = Segment(corner[NW], corner[NE]).randomPos(seed, -1, 25, 75);
Vertex cs = Segment(corner[SE], corner[SW]).randomPos(seed, -2, 25, 75);
Vertex c = Segment(cn, cs).randomPos(seed, -3, 25, 75);
Vertex centerN = Segment(c[NW], c[NE]).randomPos(seed, -1, 25, 75);
Vertex centerS = Segment(c[SE], c[SW]).randomPos(seed, -2, 25, 75);
Vertex center = Segment(centerN, centerS).randomPos(seed, -3, 25, 75);
for (int i = 0; i < 4; i++) {
middle[N+i] = Segment(corner[NW+i], corner[NE+i]).randomPos(seed, i, 25, 75);
middle[N+i] = Segment(c[NW+i], c[NE+i]).randomPos(seed, i, 25, 75);
}
for (int i = 0; i < 4; i++) {
q[i] = Quad(corner[NE+i], middle[E+i], c, middle[N+i]);
q[i] = Quad(c[NE+i], middle[E+i], center, middle[N+i]);
q[i].offset(W,-hrw); q[i].offset(S,-hrw);
}
addChild(new RouteQuadCarrefour(q[0].corner[SW], q[1].corner[SW], q[2].corner[SW], q[3].corner[SW]));
addChild(new RouteQuadCarrefour(q[0].c[SW], q[1].c[SW], q[2].c[SW], q[3].c[SW]));
for (int i = 0; i < 4; i++) {
addChild(new RouteQuadChaussee(q[NE+i].corner[NW], q[NE+i].corner[SW], q[NW+i].corner[SW], q[NW+i].corner[SE]));
addChild(QuartierQuad::factory(seed, 4+i, q[i].corner[0], q[i].corner[1], q[i].corner[2], q[i].corner[3]));
addChild(new RouteQuadChaussee(q[NE+i].c[NW], q[NE+i].c[SW], q[NW+i].c[SW], q[NW+i].c[SE]));
addChild(QuartierQuad::factory(seed, 4+i, q[i].c[0], q[i].c[1], q[i].c[2], q[i].c[3]));
}
return true;
}

View File

@ -9,16 +9,16 @@ QuartierQuadRect::~QuartierQuadRect() {
}
bool QuartierQuadRect::split() {
Vertex n = Segment(corner[NW], corner[NE]).randomPos(seed, 0, 33, 67);
Vertex s = Segment(corner[SE], corner[SW]).randomPos(seed, 1, 33, 67);
Vertex n = Segment(c[NW], c[NE]).randomPos(seed, 0, 33, 67);
Vertex s = Segment(c[SE], c[SW]).randomPos(seed, 1, 33, 67);
Quad qe = Quad(corner[NE], corner[SE], s, n);
Quad qw = Quad(corner[SW], corner[NW], n, s);
Quad qe = Quad(c[NE], c[SE], s, n);
Quad qw = Quad(c[SW], c[NW], n, s);
qe.offset(W,-hrw);
qw.offset(W,-hrw);
addChild(new RouteQuadChaussee(qe.corner[NW], qe.corner[SW], qw.corner[NW], qw.corner[SW]));
addChild(QuartierQuad::factory(seed, 2, qe.corner[0], qe.corner[1], qe.corner[2], qe.corner[3]));
addChild(QuartierQuad::factory(seed, 3, qw.corner[0], qw.corner[1], qw.corner[2], qw.corner[3]));
addChild(new RouteQuadChaussee(qe.c[NW], qe.c[SW], qw.c[NW], qw.c[SW]));
addChild(QuartierQuad::factory(seed, 2, qe.c[0], qe.c[1], qe.c[2], qe.c[3]));
addChild(QuartierQuad::factory(seed, 3, qw.c[0], qw.c[1], qw.c[2], qw.c[3]));
return true;
}

View File

@ -2,9 +2,9 @@
QuartierTri::QuartierTri(Vertex left, Vertex top, Vertex right) : Chose() {
addEntropy(left, top, right);
corner[0] = left;
corner[1] = top;
corner[2] = right;
c[0] = left;
c[1] = top;
c[2] = right;
}
QuartierTri::~QuartierTri() {
@ -13,12 +13,12 @@ QuartierTri::~QuartierTri() {
}
void QuartierTri::getBoundingBoxPoints() {
addBBPoint(corner[0]);
addBBPoint(corner[1]);
addBBPoint(corner[2]);
addBBPoint(corner[0] + Vertex(0,0,1000)); // TODO
addBBPoint(corner[1] + Vertex(0,0,1000));
addBBPoint(corner[2] + Vertex(0,0,1000));
addBBPoint(c[0]);
addBBPoint(c[1]);
addBBPoint(c[2]);
addBBPoint(c[0] + Vertex(0,0,1000)); // TODO
addBBPoint(c[1] + Vertex(0,0,1000));
addBBPoint(c[2] + Vertex(0,0,1000));
}
Chose* QuartierTri::factory(int seed, int n, Vertex left, Vertex top, Vertex right) {
@ -34,5 +34,5 @@ bool QuartierTri::split() {
void QuartierTri::triangulation() {
triangles.reserve(1);
addTriangle(new Triangle(corner[0], corner[1], corner[2], 0xf0, 0xc0, 0xc0));
addTriangle(new GPUTriangle(c[0], c[1], c[2], 0xf0, 0xc0, 0xc0));
}

View File

@ -6,7 +6,7 @@
class QuartierTri : public Chose {
public :
Vertex corner[3];
Vertex c[3];
public :
QuartierTri(Vertex left, Vertex top, Vertex right);

View File

@ -4,16 +4,16 @@ QuartierTriHauteur::QuartierTriHauteur(Vertex left, Vertex top, Vertex right) :
}
bool QuartierTriHauteur::split() {
Vertex baseCenter = Segment(corner[0], corner[2]).randomPos(seed, 0, 33, 67);
Vertex baseCenter = Segment(c[0], c[2]).randomPos(seed, 0, 33, 67);
Triangle tl = Triangle(baseCenter, corner[0], corner[1]);
Triangle tr = Triangle(corner[1], corner[2], baseCenter);
Triangle tl = Triangle(baseCenter, c[0], c[1]);
Triangle tr = Triangle(c[1], c[2], baseCenter);
tl.offsetBase(-hrw);
tr.offsetBase(-hrw);
addChild(new RouteQuadChaussee(tr.v1, tr.v3, tl.v1, tl.v3));
addChild(new RouteTriChaussee(tl.v3, corner[1], tr.v1));
addChild(QuartierTri::factory(seed, 1, tl.v3, tl.v1, tl.v2));
addChild(QuartierTri::factory(seed, 2, tr.v2, tr.v3, tr.v1));
addChild(new RouteQuadChaussee(tr.c[0], tr.c[2], tl.c[0], tl.c[2]));
addChild(new RouteTriChaussee(tl.c[2], c[1], tr.c[0]));
addChild(QuartierTri::factory(seed, 1, tl.c[2], tl.c[0], tl.c[1]));
addChild(QuartierTri::factory(seed, 2, tr.c[1], tr.c[2], tr.c[0]));
return true;
}

View File

@ -2,10 +2,10 @@
RouteQuadCarrefour::RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
addEntropy(ne,se,sw,nw);
corner[NE] = ne;
corner[SE] = se;
corner[SW] = sw;
corner[NW] = nw;
c[NE] = ne;
c[SE] = se;
c[SW] = sw;
c[NW] = nw;
}
RouteQuadCarrefour::~RouteQuadCarrefour() {
@ -14,14 +14,14 @@ RouteQuadCarrefour::~RouteQuadCarrefour() {
}
void RouteQuadCarrefour::getBoundingBoxPoints() {
addBBPoint(corner[NE]);
addBBPoint(corner[SE]);
addBBPoint(corner[SW]);
addBBPoint(corner[NW]);
addBBPoint(corner[NE] + Vertex(0,0,1000)); // TODO
addBBPoint(corner[SE] + Vertex(0,0,1000));
addBBPoint(corner[SW] + Vertex(0,0,1000));
addBBPoint(corner[NW] + Vertex(0,0,1000));
addBBPoint(c[NE]);
addBBPoint(c[SE]);
addBBPoint(c[SW]);
addBBPoint(c[NW]);
addBBPoint(c[NE] + Vertex(0,0,1000)); // TODO
addBBPoint(c[SE] + Vertex(0,0,1000));
addBBPoint(c[SW] + Vertex(0,0,1000));
addBBPoint(c[NW] + Vertex(0,0,1000));
}
bool RouteQuadCarrefour::split() {
@ -30,6 +30,6 @@ bool RouteQuadCarrefour::split() {
void RouteQuadCarrefour::triangulation() {
triangles.reserve(2);
addTriangle(new Triangle(corner[NE], corner[NW], corner[SW], 0x36, 0x36, 0x36));
addTriangle(new Triangle(corner[SW], corner[SE], corner[NE], 0x36, 0x36, 0x36));
addTriangle(new GPUTriangle(c[NE], c[NW], c[SW], 0x36, 0x36, 0x36));
addTriangle(new GPUTriangle(c[SW], c[SE], c[NE], 0x36, 0x36, 0x36));
}

View File

@ -5,7 +5,7 @@
class RouteQuadCarrefour : public Chose {
private :
Vertex corner[4];
Vertex c[4];
public :
RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw);

View File

@ -2,10 +2,10 @@
RouteQuadChaussee::RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
addEntropy(ne,se,sw,nw);
corner[NE] = ne;
corner[SE] = se;
corner[SW] = sw;
corner[NW] = nw;
c[NE] = ne;
c[SE] = se;
c[SW] = sw;
c[NW] = nw;
}
RouteQuadChaussee::~RouteQuadChaussee() {
@ -14,14 +14,14 @@ RouteQuadChaussee::~RouteQuadChaussee() {
}
void RouteQuadChaussee::getBoundingBoxPoints() {
addBBPoint(corner[NE]);
addBBPoint(corner[SE]);
addBBPoint(corner[SW]);
addBBPoint(corner[NW]);
addBBPoint(corner[NE] + Vertex(0,0,1000)); // TODO
addBBPoint(corner[SE] + Vertex(0,0,1000));
addBBPoint(corner[SW] + Vertex(0,0,1000));
addBBPoint(corner[NW] + Vertex(0,0,1000));
addBBPoint(c[NE]);
addBBPoint(c[SE]);
addBBPoint(c[SW]);
addBBPoint(c[NW]);
addBBPoint(c[NE] + Vertex(0,0,1000)); // TODO
addBBPoint(c[SE] + Vertex(0,0,1000));
addBBPoint(c[SW] + Vertex(0,0,1000));
addBBPoint(c[NW] + Vertex(0,0,1000));
}
bool RouteQuadChaussee::split() {
@ -30,6 +30,6 @@ bool RouteQuadChaussee::split() {
void RouteQuadChaussee::triangulation() {
triangles.reserve(2);
addTriangle(new Triangle(corner[NE], corner[NW], corner[SW], 0x36, 0x36, 0x36));
addTriangle(new Triangle(corner[SW], corner[SE], corner[NE], 0x36, 0x36, 0x36));
addTriangle(new GPUTriangle(c[NE], c[NW], c[SW], 0x36, 0x36, 0x36));
addTriangle(new GPUTriangle(c[SW], c[SE], c[NE], 0x36, 0x36, 0x36));
}

View File

@ -5,7 +5,7 @@
class RouteQuadChaussee : public Chose {
private :
Vertex corner[4];
Vertex c[4];
public :
RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw);

View File

@ -2,18 +2,18 @@
RouteTriChaussee::RouteTriChaussee(Vertex left, Vertex top, Vertex right) : Chose() {
addEntropy(left, top, right);
corner[0] = left;
corner[1] = top;
corner[2] = right;
c[0] = left;
c[1] = top;
c[2] = right;
}
void RouteTriChaussee::getBoundingBoxPoints() {
addBBPoint(corner[0]);
addBBPoint(corner[1]);
addBBPoint(corner[2]);
addBBPoint(corner[0] + Vertex(0,0,1000)); // TODO
addBBPoint(corner[1] + Vertex(0,0,1000));
addBBPoint(corner[2] + Vertex(0,0,1000));
addBBPoint(c[0]);
addBBPoint(c[1]);
addBBPoint(c[2]);
addBBPoint(c[0] + Vertex(0,0,1000)); // TODO
addBBPoint(c[1] + Vertex(0,0,1000));
addBBPoint(c[2] + Vertex(0,0,1000));
}
bool RouteTriChaussee::split() {
@ -22,5 +22,5 @@ bool RouteTriChaussee::split() {
void RouteTriChaussee::triangulation() {
triangles.reserve(1);
addTriangle(new Triangle(corner[0], corner[1], corner[2], 0x36, 0x36, 0x36));
addTriangle(new GPUTriangle(c[0], c[1], c[2], 0x36, 0x36, 0x36));
}

View File

@ -5,7 +5,7 @@
class RouteTriChaussee : public Chose {
private :
Vertex corner[3];
Vertex c[3];
public :
RouteTriChaussee(Vertex left, Vertex top, Vertex right);

View File

@ -37,33 +37,33 @@ void TrottoirQuadNormal::triangulation() {
if(border == E) {
q.offset(E,-15);
addTriangle(new Triangle(q.corner[0] + h, q.corner[3] + h, q.corner[2] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(q.corner[2] + h, q.corner[1] + h, q.corner[0] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[NE] + h,q.corner[0] + h, q.corner[1] + h, 0xAA, 0xAA, 0xAA));
addTriangle(new Triangle(q.corner[1] + h, c[SE] + h, c[NE] + h, 0xAA, 0xAA, 0xAA));
addTriangle(new GPUTriangle(q.c[0] + h, q.c[3] + h, q.c[2] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(q.c[2] + h, q.c[1] + h, q.c[0] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[NE] + h,q.c[0] + h, q.c[1] + h, 0xAA, 0xAA, 0xAA));
addTriangle(new GPUTriangle(q.c[1] + h, c[SE] + h, c[NE] + h, 0xAA, 0xAA, 0xAA));
addTriangle(new Triangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[SW], c[SW] + h, c[NW] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[NE], c[NE] + h, c[SE] + h, 0xAA, 0xAA, 0xAA));
addTriangle(new Triangle(c[SE] + h, c[SE], c[NE], 0xAA, 0xAA, 0xAA));
addTriangle(new GPUTriangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[SW], c[SW] + h, c[NW] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[NE], c[NE] + h, c[SE] + h, 0xAA, 0xAA, 0xAA));
addTriangle(new GPUTriangle(c[SE] + h, c[SE], c[NE], 0xAA, 0xAA, 0xAA));
addTriangle(new Triangle(c[NE] + h, c[NE], c[NW], 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[NE] + h, c[NE], c[NW], 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66));
}
else {
addTriangle(new Triangle(q.corner[0] + h, q.corner[3] + h, q.corner[2] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(q.corner[2] + h, q.corner[1] + h, q.corner[0] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(q.c[0] + h, q.c[3] + h, q.c[2] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(q.c[2] + h, q.c[1] + h, q.c[0] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[SW], c[SW] + h, c[NW] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[NE], c[NE] + h, c[SE] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[SE] + h, c[SE], c[NE], 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[NW] + h, c[NW], c[SW], 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[SW], c[SW] + h, c[NW] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[NE], c[NE] + h, c[SE] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[SE] + h, c[SE], c[NE], 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[NE] + h, c[NE], c[NW], 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66));
addTriangle(new Triangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[NE] + h, c[NE], c[NW], 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[NW], c[NW] + h, c[NE] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[SW], c[SW] + h, c[SE] + h, 0x66, 0x66, 0x66));
addTriangle(new GPUTriangle(c[SE] + h, c[SE], c[SW], 0x66, 0x66, 0x66));
}
}

View File

@ -1,36 +1,22 @@
#include "all_includes.hh"
TerrainQuadHerbe::TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), red(0x11) {
TerrainQuadHerbe::TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
addEntropy(ne, se, sw, nw);
corner[NE] = ne;
corner[SE] = se;
corner[SW] = sw;
corner[NW] = nw;
}
TerrainQuadHerbe::~TerrainQuadHerbe() {
children.clear();
triangles.clear();
c[NE] = ne;
c[SE] = se;
c[SW] = sw;
c[NW] = nw;
}
void TerrainQuadHerbe::getBoundingBoxPoints() {
addBBPoint(corner[NE]);
addBBPoint(corner[SE]);
addBBPoint(corner[SW]);
addBBPoint(corner[NW]);
addBBPoint(corner[NE] + Vertex(0,0,1000)); // TODO
addBBPoint(corner[SE] + Vertex(0,0,1000));
addBBPoint(corner[SW] + Vertex(0,0,1000));
addBBPoint(corner[NW] + Vertex(0,0,1000));
}
TerrainQuadHerbe::TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Vertex nw)
: Chose(), red(red) {
addEntropy(ne, se, sw, nw);
corner[NE] = ne;
corner[SE] = se;
corner[SW] = sw;
corner[NW] = nw;
addBBPoint(c[NE]);
addBBPoint(c[SE]);
addBBPoint(c[SW]);
addBBPoint(c[NW]);
addBBPoint(c[NE] + Vertex(0,0,1000)); // TODO
addBBPoint(c[SE] + Vertex(0,0,1000));
addBBPoint(c[SW] + Vertex(0,0,1000));
addBBPoint(c[NW] + Vertex(0,0,1000));
}
bool TerrainQuadHerbe::split() {
@ -39,6 +25,6 @@ bool TerrainQuadHerbe::split() {
void TerrainQuadHerbe::triangulation() {
triangles.reserve(2);
addTriangle(new Triangle(corner[NE], corner[NW], corner[SW], red, 0xaa, 0x22));
addTriangle(new Triangle(corner[SW], corner[SE], corner[NE], red, 0xaa, 0x22));
addTriangle(new GPUTriangle(c[NE], c[NW], c[SW], 0x11, 0xaa, 0x22));
addTriangle(new GPUTriangle(c[SW], c[SE], c[NE], 0x11, 0xaa, 0x22));
}

View File

@ -6,13 +6,10 @@
class TerrainQuadHerbe : public Chose {
private :
Vertex corner[4];
int red; // DEBUG
Vertex c[4];
public :
TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw);
TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Vertex nw); // DEBUG
virtual ~TerrainQuadHerbe();
virtual bool split();
virtual void triangulation();
virtual void getBoundingBoxPoints();

View File

@ -1,62 +0,0 @@
#include "all_includes.hh"
// Triangle "rapide", sert juste aux calculs de coordonnées. Devrait
// être une superclasse de "triangle". Pour calculer le cosinus
// d'angles, on crée un objet triangle assez gros. C'est du
// gaspillage.
Triangle::Triangle() {
}
Triangle::Triangle(Vertex v1, Vertex v2, Vertex v3): v1(v1), v2(v2), v3(v3) {
}
Triangle::Triangle(Vertex v1, Vertex v2, Vertex v3, unsigned char r, unsigned char g, unsigned char b)
: v1(v1), v2(v2), v3(v3), r(r), g(g), b(b), vnormal(normal(v1,v2,v3)) {
}
Vertex Triangle::normal(Vertex v1, Vertex v2, Vertex v3) {
Vertex normal = (v1 - v2)*(v2 - v3);
return normal / normal.norm();
}
float Triangle::cosAngle() {
return (v1-v2).cosAngle(v3-v2);
}
float Triangle::angle() {
return std::acos(cosAngle());
}
float Triangle::minAngle() {
float a2 = angle();
float a3 = Triangle(v2,v3,v1).angle();
float a1 = Angle::Pi - a2 - a3;
return std::min(std::min(a1, a2), a3);
}
void Triangle::offsetBase(int offset) {
Quad q = Quad(v2, v1, v3, v2);
q.offset(S, -offset);
v1 = q.corner[1];
v2 = q.corner[0];
v3 = q.corner[2];
}
void Triangle::display() {
// glDisable(GL_LIGHTING);
// glDisable(GL_TEXTURE_2D);
// glBegin(GL_LINES);
// glColor3ub(255,255,0);
// Vertex v = (v1 + v2 + v3) / 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(v1.x,v1.y,v1.z);
glVertex3d(v2.x,v2.y,v2.z);
glVertex3d(v3.x,v3.y,v3.z);
// glEnd();
}

View File

@ -1,30 +0,0 @@
#ifndef _TRIANGLE_HH_
#define _TRIANGLE_HH_
#include "all_includes.hh"
class Triangle {
public :
Vertex v1;
Vertex v2;
Vertex v3;
unsigned char r;
unsigned char g;
unsigned char b;
Vertex vnormal;
public :
Triangle();
Triangle(Vertex v1, Vertex v2, Vertex v3);
Triangle(Vertex v1, Vertex v2, Vertex v3, unsigned char r, unsigned char g, unsigned char b);
float cosAngle(); // cosinus de l'angle en v2.
float angle(); // angle en v2, en degrés. TODO : le calcul ne donne que des angles entre 0 et 180 !
float minAngle(); // angle minimum du triangle (en v1, v2 ou v3).
void offsetBase(int offset);
void display();
private :
Vertex normal(Vertex v1, Vertex v2, Vertex v3);
};
#endif