Merge branch 'master' of github.com:jsmaniac/2011-m2s3-city-builder
Conflicts: rules/chose.hh
This commit is contained in:
commit
ab8622338e
14
bugs/new/2011-18-12-1926-reperelocal.txt
Normal file
14
bugs/new/2011-18-12-1926-reperelocal.txt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
Il faut redéfinir la notion et implémentation du repère local dans
|
||||||
|
l'abre. pour ne pas avoir de problème de taille d'entier, et utiliser
|
||||||
|
correctement le repère local mis en place il faut que chaque élément
|
||||||
|
dépendent du repère local de l'élément qui lui est parent.
|
||||||
|
Par conséquent pour dessiner la ville il faudra effectuer un changement
|
||||||
|
de repère à chaque dscente dans l'abre pour décaller au fur et à mesure
|
||||||
|
le repère jusqu'a atteindre le repère de l'objet que l'on veut placer
|
||||||
|
sur la "carte".
|
||||||
|
|
||||||
|
Pour le moment les repères "locaux" ne le sont pas vraiment, je place un
|
||||||
|
point qui sert de repère local en fonction des autres points disponibles
|
||||||
|
(pas de soucis pour çaà sauf je passe les coordonnées absolue de cet
|
||||||
|
objet au sous objets que je crée au lieu de passer les coordonnées
|
||||||
|
locales.
|
4
main.cpp
4
main.cpp
|
@ -10,7 +10,7 @@
|
||||||
// -> bâtiment dans le "bout" le plus "étroit", et lignes dans une seule direction dans le reste.
|
// -> bâtiment dans le "bout" le plus "étroit", et lignes dans une seule direction dans le reste.
|
||||||
|
|
||||||
void recursiveSubdivide(Chose* c) {
|
void recursiveSubdivide(Chose* c) {
|
||||||
if (c->subdivide()) {
|
if (c->split()) {
|
||||||
std::vector<Chose*>::iterator it;
|
std::vector<Chose*>::iterator it;
|
||||||
for (it = c->children.begin(); it != c->children.end(); ++it) {
|
for (it = c->children.begin(); it != c->children.end(); ++it) {
|
||||||
recursiveSubdivide(*it);
|
recursiveSubdivide(*it);
|
||||||
|
@ -27,7 +27,7 @@ int main() {
|
||||||
Vertex sw(0, 0, 0);
|
Vertex sw(0, 0, 0);
|
||||||
Vertex nw(0, size, 0);
|
Vertex nw(0, size, 0);
|
||||||
Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw);
|
Chose* c = QuartierQuad::factory(Chose::initialSeed, 0, ne, se, sw, nw);
|
||||||
// c->subdivide();
|
// c->split();
|
||||||
recursiveSubdivide(c);
|
recursiveSubdivide(c);
|
||||||
|
|
||||||
Heap h(1);
|
Heap h(1);
|
||||||
|
|
|
@ -2,12 +2,20 @@
|
||||||
|
|
||||||
BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal entry) : Chose(), ne(ne) {
|
BatimentQuad::BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal entry) : Chose(), ne(ne) {
|
||||||
addEntropy(ne, se, sw, nw);
|
addEntropy(ne, se, sw, nw);
|
||||||
this->ne = ne;
|
|
||||||
this->se = se;
|
|
||||||
this-> sw = sw;
|
|
||||||
this->nw = nw;
|
|
||||||
this->entry = entry;
|
this->entry = entry;
|
||||||
triangulation();
|
lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f);
|
||||||
|
this->ne = ne-lctr;
|
||||||
|
this->se = se-lctr;
|
||||||
|
this-> sw = sw-lctr;
|
||||||
|
this->nw = nw-lctr;
|
||||||
|
triangulation();
|
||||||
|
}
|
||||||
|
|
||||||
|
BatimentQuad::~BatimentQuad() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BatimentQuad::width() { return this->ne.x - this->sw.x; }
|
int BatimentQuad::width() { return this->ne.x - this->sw.x; }
|
||||||
|
@ -18,7 +26,7 @@ std::vector<Vertex*> BatimentQuad::getBoundingBoxPoints() const {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BatimentQuad::subdivide() {
|
bool BatimentQuad::split() {
|
||||||
factory(1,1,ne,se,sw,nw);
|
factory(1,1,ne,se,sw,nw);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -33,21 +41,21 @@ Chose* BatimentQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, V
|
||||||
q.offset(S,-140);
|
q.offset(S,-140);
|
||||||
q.offset(W,-140);
|
q.offset(W,-140);
|
||||||
|
|
||||||
addChild(new TrottoirQuadNormal(ne,se,q.corner[1],q.corner[0],th,E));
|
addChild(new TrottoirQuadNormal(lctr+ne,lctr+se,lctr+q.corner[1],lctr+q.corner[0],th,E));
|
||||||
addChild(new TrottoirQuadNormal(se,sw,q.corner[2],q.corner[1],th,E));
|
addChild(new TrottoirQuadNormal(lctr+se,lctr+sw,lctr+q.corner[2],lctr+q.corner[1],th,E));
|
||||||
addChild(new TrottoirQuadNormal(sw,nw,q.corner[3],q.corner[2],th,E));
|
addChild(new TrottoirQuadNormal(lctr+sw,lctr+nw,lctr+q.corner[3],lctr+q.corner[2],th,E));
|
||||||
addChild(new TrottoirQuadNormal(nw,ne,q.corner[0],q.corner[3],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);
|
q.corner[0] = q.corner[0] + Vertex(0,0,th);
|
||||||
q.corner[1] = q.corner[1] + 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[2] = q.corner[2] + Vertex(0,0,th);
|
||||||
q.corner[3] = q.corner[3] + Vertex(0,0,th);
|
q.corner[3] = q.corner[3] + Vertex(0,0,th);
|
||||||
|
|
||||||
addChild(new BatimentQuadJardin(q.corner[0],q.corner[1],q.corner[2],q.corner[3]));
|
addChild(new BatimentQuadJardin(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3]));
|
||||||
|
|
||||||
q.offset(this->entry,-400);
|
q.offset(this->entry,-400);
|
||||||
|
|
||||||
addChild(new BatimentQuadMaison(q.corner[0],q.corner[1],q.corner[2],q.corner[3]));
|
addChild(new BatimentQuadMaison(lctr+q.corner[0],lctr+q.corner[1],lctr+q.corner[2],lctr+q.corner[3]));
|
||||||
return NULL; // pour compilation, à virer.
|
return NULL; // pour compilation, à virer.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,10 @@ class BatimentQuad : public Chose {
|
||||||
static const int maxHeight = 800;
|
static const int maxHeight = 800;
|
||||||
|
|
||||||
BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal door);
|
BatimentQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, Cardinal door);
|
||||||
|
virtual ~BatimentQuad();
|
||||||
int width();
|
int width();
|
||||||
int height();
|
int height();
|
||||||
virtual bool subdivide();
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
BatimentQuadJardin::BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) {
|
BatimentQuadJardin::BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
|
||||||
addEntropy(ne, se, sw, nw);
|
addEntropy(ne, se, sw, nw);
|
||||||
|
lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f);
|
||||||
|
this->ne = ne-lctr;
|
||||||
|
this->se = se-lctr;
|
||||||
|
this-> sw = sw-lctr;
|
||||||
|
this->nw = nw-lctr;
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BatimentQuadJardin::~BatimentQuadJardin() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
int BatimentQuadJardin::width() { return this->ne.x - this->sw.x; }
|
int BatimentQuadJardin::width() { return this->ne.x - this->sw.x; }
|
||||||
|
|
||||||
int BatimentQuadJardin::height() { return this->ne.y - this->sw.y; }
|
int BatimentQuadJardin::height() { return this->ne.y - this->sw.y; }
|
||||||
|
@ -14,7 +26,7 @@ std::vector<Vertex*> BatimentQuadJardin::getBoundingBoxPoints() const {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BatimentQuadJardin::subdivide() {
|
bool BatimentQuadJardin::split() {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +34,6 @@ bool BatimentQuadJardin::subdivide() {
|
||||||
void BatimentQuadJardin::triangulation() {
|
void BatimentQuadJardin::triangulation() {
|
||||||
triangles.reserve(2);
|
triangles.reserve(2);
|
||||||
|
|
||||||
addTriangle(new Triangle(ne,nw,sw,0x12,0x64,0x12));
|
addTriangle(new Triangle(lctr+ne,lctr+nw,lctr+sw,0x12,0x64,0x12));
|
||||||
addTriangle(new Triangle(sw,se,ne,0x10,0x60,0x10));
|
addTriangle(new Triangle(lctr+sw,lctr+se,lctr+ne,0x10,0x60,0x10));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,10 @@ class BatimentQuadJardin : public Chose {
|
||||||
static const int maxHeight = 800;
|
static const int maxHeight = 800;
|
||||||
|
|
||||||
BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
BatimentQuadJardin(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
|
virtual ~BatimentQuadJardin();
|
||||||
int width();
|
int width();
|
||||||
int height();
|
int height();
|
||||||
virtual bool subdivide();
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
BatimentQuadMaison::BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) {
|
BatimentQuadMaison::BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose() {
|
||||||
addEntropy(ne, se, sw, nw);
|
addEntropy(ne, se, sw, nw);
|
||||||
|
lctr = Vertex(ne.x-nw.x,se.y-ne.y,0.0f);
|
||||||
|
this->ne = ne-lctr;
|
||||||
|
this->se = se-lctr;
|
||||||
|
this-> sw = sw-lctr;
|
||||||
|
this->nw = nw-lctr;
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BatimentQuadMaison::~BatimentQuadMaison() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
int BatimentQuadMaison::width() { return this->ne.x - this->sw.x; }
|
int BatimentQuadMaison::width() { return this->ne.x - this->sw.x; }
|
||||||
|
|
||||||
int BatimentQuadMaison::height() { return this->ne.y - this->sw.y; }
|
int BatimentQuadMaison::height() { return this->ne.y - this->sw.y; }
|
||||||
|
@ -14,7 +26,7 @@ std::vector<Vertex*> BatimentQuadMaison::getBoundingBoxPoints() const {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BatimentQuadMaison::subdivide() {
|
bool BatimentQuadMaison::split() {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -31,14 +43,14 @@ void BatimentQuadMaison::triangulation() {
|
||||||
Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit);
|
Vertex toit = (neh + seh + nwh + swh) / 4 + Vertex(0,0,htoit);
|
||||||
|
|
||||||
// 4 Murs
|
// 4 Murs
|
||||||
addTriangle(new Triangle(neh,seh,ne,0xf1,0xe3,0xad)); addTriangle(new Triangle(seh,se,ne,0xf1,0xe3,0xad)); // ne-se-seh-neh
|
addTriangle(new Triangle(lctr+neh,lctr+seh,lctr+ne,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+seh,lctr+se,lctr+ne,0xf1,0xe3,0xad)); // ne-se-seh-neh
|
||||||
addTriangle(new Triangle(seh,swh,se,0xf1,0xe3,0xad)); addTriangle(new Triangle(swh,sw,se,0xf1,0xe3,0xad)); // se-sw-swh-seh
|
addTriangle(new Triangle(lctr+seh,lctr+swh,lctr+se,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+swh,lctr+sw,lctr+se,0xf1,0xe3,0xad)); // se-sw-swh-seh
|
||||||
addTriangle(new Triangle(swh,nwh,sw,0xf1,0xe3,0xad)); addTriangle(new Triangle(nwh,nw,sw,0xf1,0xe3,0xad)); // sw-nw-nwh-swh
|
addTriangle(new Triangle(lctr+swh,lctr+nwh,lctr+sw,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+nwh,lctr+nw,lctr+sw,0xf1,0xe3,0xad)); // sw-nw-nwh-swh
|
||||||
addTriangle(new Triangle(nwh,neh,nw,0xf1,0xe3,0xad)); addTriangle(new Triangle(neh,ne,nw,0xf1,0xe3,0xad)); // nw-ne-neh-nwh
|
addTriangle(new Triangle(lctr+nwh,lctr+neh,lctr+nw,0xf1,0xe3,0xad)); addTriangle(new Triangle(lctr+neh,lctr+ne,lctr+nw,0xf1,0xe3,0xad)); // nw-ne-neh-nwh
|
||||||
|
|
||||||
// 1 Toit
|
// 1 Toit
|
||||||
addTriangle(new Triangle(neh,toit,seh,0x9a,0x48,0x3c));
|
addTriangle(new Triangle(lctr+neh,lctr+toit,lctr+seh,0x9a,0x48,0x3c));
|
||||||
addTriangle(new Triangle(seh,toit,swh,0x9a,0x48,0x3c));
|
addTriangle(new Triangle(lctr+seh,lctr+toit,lctr+swh,0x9a,0x48,0x3c));
|
||||||
addTriangle(new Triangle(swh,toit,nwh,0x9a,0x48,0x3c));
|
addTriangle(new Triangle(lctr+swh,lctr+toit,lctr+nwh,0x9a,0x48,0x3c));
|
||||||
addTriangle(new Triangle(nwh,toit,neh,0x9a,0x48,0x3c));
|
addTriangle(new Triangle(lctr+nwh,lctr+toit,lctr+neh,0x9a,0x48,0x3c));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,10 @@ class BatimentQuadMaison : public Chose {
|
||||||
static const int maxHeight = 800;
|
static const int maxHeight = 800;
|
||||||
|
|
||||||
BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
BatimentQuadMaison(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
|
virtual ~BatimentQuadMaison();
|
||||||
int width();
|
int width();
|
||||||
int height();
|
int height();
|
||||||
virtual bool subdivide();
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
|
|
|
@ -10,8 +10,12 @@ void Chose::addTriangle(Triangle* t) {
|
||||||
triangles.push_back(t);
|
triangles.push_back(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chose::merge() {
|
bool Chose::merge() {
|
||||||
triangles.clear();
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
// triangles.clear();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chose::display() {
|
void Chose::display() {
|
||||||
|
|
|
@ -14,11 +14,12 @@ class Chose {
|
||||||
int inCounter;
|
int inCounter;
|
||||||
int splitCube[6];
|
int splitCube[6];
|
||||||
int mergeCube[6];
|
int mergeCube[6];
|
||||||
|
Vertex lctr; // Local center;
|
||||||
|
|
||||||
public :
|
public :
|
||||||
void display();
|
void display();
|
||||||
virtual bool subdivide() = 0;
|
virtual bool split() = 0;
|
||||||
virtual void merge();
|
virtual bool merge();
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
Chose();
|
Chose();
|
||||||
|
|
|
@ -8,6 +8,13 @@ QuartierQuad::QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose()
|
||||||
corner[NW] = nw;
|
corner[NW] = nw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QuartierQuad::~QuartierQuad() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> QuartierQuad::getBoundingBoxPoints() const {
|
std::vector<Vertex*> QuartierQuad::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
|
@ -38,7 +45,7 @@ Chose* QuartierQuad::factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, V
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuartierQuad::subdivide() {
|
bool QuartierQuad::split() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ public:
|
||||||
Vertex corner[4];
|
Vertex corner[4];
|
||||||
public:
|
public:
|
||||||
QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
QuartierQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual bool subdivide();
|
virtual ~QuartierQuad();
|
||||||
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
static Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
static Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
|
|
|
@ -4,12 +4,19 @@ QuartierQuadAngle::QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw)
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QuartierQuadAngle::~QuartierQuadAngle() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> QuartierQuadAngle::getBoundingBoxPoints() const {
|
std::vector<Vertex*> QuartierQuadAngle::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuartierQuadAngle::subdivide() {
|
bool QuartierQuadAngle::split() {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (Triangle(corner[NW+i], corner[NE+i], corner[SE+i]).angle() >= Angle::d2r(130)) {
|
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]);
|
Triangle t1(corner[NE+i], corner[SE+i], corner[SW+i]);
|
||||||
|
|
|
@ -10,7 +10,8 @@ class QuartierQuadAngle : public QuartierQuad {
|
||||||
|
|
||||||
public :
|
public :
|
||||||
QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
QuartierQuadAngle(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual bool subdivide();
|
virtual ~QuartierQuadAngle();
|
||||||
|
virtual bool split();
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
|
@ -3,12 +3,19 @@
|
||||||
QuartierQuadCarre::QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) {
|
QuartierQuadCarre::QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QuartierQuadCarre::~QuartierQuadCarre() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> QuartierQuadCarre::getBoundingBoxPoints() const {
|
std::vector<Vertex*> QuartierQuadCarre::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuartierQuadCarre::subdivide() {
|
bool QuartierQuadCarre::split() {
|
||||||
Vertex middle[4];
|
Vertex middle[4];
|
||||||
Quad q[4];
|
Quad q[4];
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ class QuartierQuadCarre : public QuartierQuad {
|
||||||
|
|
||||||
public :
|
public :
|
||||||
QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
QuartierQuadCarre(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual bool subdivide();
|
virtual ~QuartierQuadCarre();
|
||||||
|
virtual bool split();
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,19 @@
|
||||||
QuartierQuadRect::QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) {
|
QuartierQuadRect::QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw) : QuartierQuad(ne, se, sw, nw) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QuartierQuadRect::~QuartierQuadRect() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> QuartierQuadRect::getBoundingBoxPoints() const {
|
std::vector<Vertex*> QuartierQuadRect::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuartierQuadRect::subdivide() {
|
bool QuartierQuadRect::split() {
|
||||||
Vertex n = Segment(corner[NW], corner[NE]).randomPos(seed, 0, 33, 67);
|
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 s = Segment(corner[SE], corner[SW]).randomPos(seed, 1, 33, 67);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ class QuartierQuadRect : public QuartierQuad {
|
||||||
|
|
||||||
public :
|
public :
|
||||||
QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
QuartierQuadRect(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual bool subdivide();
|
virtual ~QuartierQuadRect();
|
||||||
|
virtual bool split();
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,13 @@ QuartierTri::QuartierTri(Vertex left, Vertex top, Vertex right) : Chose() {
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QuartierTri::~QuartierTri() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> QuartierTri::getBoundingBoxPoints() const {
|
std::vector<Vertex*> QuartierTri::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
|
@ -20,7 +27,7 @@ Chose* QuartierTri::factory(int seed, int n, Vertex left, Vertex top, Vertex rig
|
||||||
return new QuartierTri(left, top, right);
|
return new QuartierTri(left, top, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuartierTri::subdivide() {
|
bool QuartierTri::split() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ class QuartierTri : public Chose {
|
||||||
|
|
||||||
public :
|
public :
|
||||||
QuartierTri(Vertex left, Vertex top, Vertex right);
|
QuartierTri(Vertex left, Vertex top, Vertex right);
|
||||||
virtual bool subdivide();
|
virtual ~QuartierTri();
|
||||||
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
static Chose* factory(int seed, int n, Vertex left, Vertex top, Vertex right);
|
static Chose* factory(int seed, int n, Vertex left, Vertex top, Vertex right);
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
|
|
|
@ -5,12 +5,19 @@ RouteQuadCarrefour::RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex n
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RouteQuadCarrefour::~RouteQuadCarrefour() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> RouteQuadCarrefour::getBoundingBoxPoints() const {
|
std::vector<Vertex*> RouteQuadCarrefour::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RouteQuadCarrefour::subdivide() {
|
bool RouteQuadCarrefour::split() {
|
||||||
// TODO
|
// TODO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@ class RouteQuadCarrefour : public Chose {
|
||||||
|
|
||||||
public :
|
public :
|
||||||
RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
RouteQuadCarrefour(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual bool subdivide();
|
virtual ~RouteQuadCarrefour();
|
||||||
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,12 +4,19 @@ RouteQuadChaussee::RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw)
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RouteQuadChaussee::~RouteQuadChaussee() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> RouteQuadChaussee::getBoundingBoxPoints() const {
|
std::vector<Vertex*> RouteQuadChaussee::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RouteQuadChaussee::subdivide() {
|
bool RouteQuadChaussee::split() {
|
||||||
// TODO
|
// TODO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@ class RouteQuadChaussee : public Chose {
|
||||||
|
|
||||||
public :
|
public :
|
||||||
RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
RouteQuadChaussee(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
virtual bool subdivide();
|
virtual ~RouteQuadChaussee();
|
||||||
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,12 +10,19 @@ TrottoirQuadNormal::TrottoirQuadNormal(Vertex ne, Vertex se, Vertex sw, Vertex n
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TrottoirQuadNormal::~TrottoirQuadNormal() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> TrottoirQuadNormal::getBoundingBoxPoints() const {
|
std::vector<Vertex*> TrottoirQuadNormal::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrottoirQuadNormal::subdivide() {
|
bool TrottoirQuadNormal::split() {
|
||||||
// TODO
|
// TODO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ class TrottoirQuadNormal : public Chose {
|
||||||
|
|
||||||
public :
|
public :
|
||||||
TrottoirQuadNormal(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height, Cardinal border);
|
TrottoirQuadNormal(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height, Cardinal border);
|
||||||
virtual bool subdivide();
|
virtual ~TrottoirQuadNormal();
|
||||||
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,13 @@ TerrainQuadHerbe::TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw) :
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TerrainQuadHerbe::~TerrainQuadHerbe() {
|
||||||
|
for(unsigned int i = 0; i < children.size(); i++)
|
||||||
|
delete(children[i]);
|
||||||
|
children.clear();
|
||||||
|
triangles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vertex*> TerrainQuadHerbe::getBoundingBoxPoints() const {
|
std::vector<Vertex*> TerrainQuadHerbe::getBoundingBoxPoints() const {
|
||||||
std::vector<Vertex*> list;
|
std::vector<Vertex*> list;
|
||||||
return list;
|
return list;
|
||||||
|
@ -23,7 +30,7 @@ TerrainQuadHerbe::TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Ver
|
||||||
triangulation();
|
triangulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TerrainQuadHerbe::subdivide() {
|
bool TerrainQuadHerbe::split() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ class TerrainQuadHerbe : public Chose {
|
||||||
public :
|
public :
|
||||||
TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
TerrainQuadHerbe(Vertex ne, Vertex se, Vertex sw, Vertex nw);
|
||||||
TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Vertex nw); // DEBUG
|
TerrainQuadHerbe(int red, Vertex ne, Vertex se, Vertex sw, Vertex nw); // DEBUG
|
||||||
virtual bool subdivide();
|
virtual ~TerrainQuadHerbe();
|
||||||
|
virtual bool split();
|
||||||
virtual void triangulation();
|
virtual void triangulation();
|
||||||
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
virtual std::vector<Vertex*> getBoundingBoxPoints() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,8 +21,8 @@ std::ostream& operator<<(std::ostream& os, const Triangle& t) {
|
||||||
return os << "Triangle " << t.v1 << "--" << t.v2 << "--" << t.v3 << "-- cycle";
|
return os << "Triangle " << t.v1 << "--" << t.v2 << "--" << t.v3 << "-- cycle";
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertexf Triangle::normal(Vertex v1, Vertex v2, Vertex v3) {
|
Vertex Triangle::normal(Vertex v1, Vertex v2, Vertex v3) {
|
||||||
Vertexf normal = (v1 - v2)*(v2 - v3);
|
Vertex normal = (v1 - v2)*(v2 - v3);
|
||||||
return normal / normal.norm();
|
return normal / normal.norm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ void Triangle::display() {
|
||||||
// glVertex3d(v.x+vnormal.x*50,v.y+vnormal.y*50,v.z+vnormal.z*50);
|
// glVertex3d(v.x+vnormal.x*50,v.y+vnormal.y*50,v.z+vnormal.z*50);
|
||||||
// glEnd( );
|
// glEnd( );
|
||||||
// glEnable(GL_LIGHTING);
|
// glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
View::setColor(r,g,b);
|
View::setColor(r,g,b);
|
||||||
glNormal3d(vnormal.x,vnormal.y,vnormal.z);
|
glNormal3d(vnormal.x,vnormal.y,vnormal.z);
|
||||||
// glBegin(GL_TRIANGLES);
|
// glBegin(GL_TRIANGLES);
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Triangle {
|
||||||
unsigned char r;
|
unsigned char r;
|
||||||
unsigned char g;
|
unsigned char g;
|
||||||
unsigned char b;
|
unsigned char b;
|
||||||
Vertexf vnormal;
|
Vertex vnormal;
|
||||||
|
|
||||||
public :
|
public :
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Triangle* t);
|
friend std::ostream& operator<<(std::ostream& os, const Triangle* t);
|
||||||
|
@ -26,7 +26,7 @@ class Triangle {
|
||||||
void display();
|
void display();
|
||||||
|
|
||||||
private :
|
private :
|
||||||
Vertexf normal(Vertex v1, Vertex v2, Vertex v3);
|
Vertex normal(Vertex v1, Vertex v2, Vertex v3);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
134
vertex.cpp
134
vertex.cpp
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Vertex::Vertex() {}
|
Vertex::Vertex() {}
|
||||||
|
|
||||||
Vertex::Vertex(int x, int y, int z): x(x), y(y), z(z) {}
|
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() { return std::sqrt(x*x + y*y + z*z); }
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ Vertex Vertex::projectOn(Vertex v) {
|
||||||
return Vertex(((int64)v.x) * scalaire / normecarre, ((int64)v.y) * scalaire / normecarre, 0);
|
return Vertex(((int64)v.x) * scalaire / normecarre, ((int64)v.y) * scalaire / normecarre, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex Vertex::setNorm(int n) {
|
Vertex Vertex::setNorm(float n) {
|
||||||
int64 current = norm();
|
int64 current = norm();
|
||||||
return Vertex((int64)x * (int64)n / current, (int64)y * (int64)n / current, 0);
|
return Vertex((int64)x * (int64)n / current, (int64)y * (int64)n / current, 0);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,66 @@ float Vertex::cosAngle(Vertex v) {
|
||||||
return ((double)(this->x*v.x + this->y*v.y)) / (((double)norm())*((double)v.norm()));
|
return ((double)(this->x*v.x + this->y*v.y)) / (((double)norm())*((double)v.norm()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex::operator Vertexf() { return Vertexf(x,y,z); }
|
Vertex::operator Vertex() { return Vertex(x,y,z); }
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
|
||||||
|
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, u.z + v.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator-(const Vertex& u, const Vertex& v) {
|
||||||
|
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, -v.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator*(const Vertex& v, const float n) {
|
||||||
|
return Vertex(v.x * n, v.y * n, v.z * n);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator*(const Vertex& u, const Vertex& v) {
|
||||||
|
return Vertex(
|
||||||
|
(u.y * v.z) - (u.z * v.y),
|
||||||
|
(u.z * v.x) - (u.x * v.z),
|
||||||
|
(u.x * v.y) - (u.y * v.x)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator/(const Vertex& v, const int n) {
|
||||||
|
return Vertex(v.x / n, v.y / n, v.z / n);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex operator/(const Vertex& v, const float f) {
|
||||||
|
return Vertex(v.x / f, v.y / f, v.z / f);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) {
|
||||||
|
// http://electron9.phys.utk.edu/vectors/3dcoordinates.htm
|
||||||
|
return Vertex(
|
||||||
|
r * std::sin(xAngle / 180 * 3.14159) * std::cos(yAngle / 180 * 3.14159),
|
||||||
|
r * std::sin(xAngle / 180 * 3.14159) * std::sin(yAngle / 180 * 3.14159),
|
||||||
|
r * std::cos(xAngle / 180 * 3.14159)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
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); }
|
||||||
|
|
||||||
|
Vertex::operator Vertex() { return Vertex(x,y,z); }
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
|
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
|
||||||
return os << "(" << v.x << "," << v.y << "," << v.z << ")";
|
return os << "(" << v.x << "," << v.y << "," << v.z << ")";
|
||||||
|
@ -59,11 +118,11 @@ Vertex operator-(const Vertex& u, const Vertex& v) {
|
||||||
return Vertex(u.x - v.x, u.y - v.y, u.z - v.z);
|
return Vertex(u.x - v.x, u.y - v.y, u.z - v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex operator+(const Vertex& u, const Vertexf& v) {
|
Vertex operator+(const Vertex& u, const Vertex& v) {
|
||||||
return Vertex(u.x + v.x, u.y + v.y, u.z + v.z);
|
return Vertex(u.x + v.x, u.y + v.y, u.z + v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex operator-(const Vertex& u, const Vertexf& v) {
|
Vertex operator-(const Vertex& u, const Vertex& v) {
|
||||||
return Vertex(u.x - v.x, u.y - v.y, u.z - v.z);
|
return Vertex(u.x - v.x, u.y - v.y, u.z - v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,67 +158,4 @@ Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) {
|
||||||
r * std::cos(xAngle / 180 * 3.14159)
|
r * std::cos(xAngle / 180 * 3.14159)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Vertexf::Vertexf() {}
|
|
||||||
|
|
||||||
Vertexf::Vertexf(float x, float y, float z): x(x), y(y), z(z) {}
|
|
||||||
|
|
||||||
float Vertexf::norm() { return std::sqrt(x*x + y*y + z*z); }
|
|
||||||
|
|
||||||
Vertexf::operator Vertex() { return Vertex(x,y,z); }
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Vertexf& v) {
|
|
||||||
return os << "(" << v.x << "," << v.y << "," << v.z << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator+(const Vertexf& u, const Vertexf& v) {
|
|
||||||
return Vertexf(u.x + v.x, u.y + v.y, u.z + v.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator-(const Vertexf& u, const Vertex& v) {
|
|
||||||
return Vertexf(u.x - v.x, u.y - v.y, u.z - v.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator+(const Vertexf& u, const Vertex& v) {
|
|
||||||
return Vertexf(u.x + v.x, u.y + v.y, u.z + v.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator-(const Vertexf& u, const Vertexf& v) {
|
|
||||||
return Vertexf(u.x - v.x, u.y - v.y, u.z - v.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator-(const Vertexf& v) {
|
|
||||||
return Vertexf(-v.x, -v.y, -v.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator*(const Vertexf& v, const int n) {
|
|
||||||
return Vertexf(v.x * n, v.y * n, v.z * n);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator*(const Vertexf& u, const Vertexf& v) {
|
|
||||||
return Vertexf(
|
|
||||||
(u.y * v.z) - (u.z * v.y),
|
|
||||||
(u.z * v.x) - (u.x * v.z),
|
|
||||||
(u.x * v.y) - (u.y * v.x)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator/(const Vertexf& v, const int n) {
|
|
||||||
return Vertexf(v.x / n, v.y / n, v.z / n);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf operator/(const Vertexf& v, const float f) {
|
|
||||||
return Vertexf(v.x / f, v.y / f, v.z / f);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vertexf Vertexf::fromSpherical(float r, float xAngle, float yAngle) {
|
|
||||||
// http://electron9.phys.utk.edu/vectors/3dcoordinates.htm
|
|
||||||
return Vertexf(
|
|
||||||
r * std::sin(xAngle / 180 * 3.14159) * std::cos(yAngle / 180 * 3.14159),
|
|
||||||
r * std::sin(xAngle / 180 * 3.14159) * std::sin(yAngle / 180 * 3.14159),
|
|
||||||
r * std::cos(xAngle / 180 * 3.14159)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
70
vertex.hh
70
vertex.hh
|
@ -2,27 +2,51 @@
|
||||||
#define _VERTEX_HH_
|
#define _VERTEX_HH_
|
||||||
|
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
class Vertexf;
|
|
||||||
|
|
||||||
class Vertex {
|
class Vertex {
|
||||||
public :
|
public :
|
||||||
int x;
|
float x;
|
||||||
int y;
|
float y;
|
||||||
int z;
|
float z;
|
||||||
|
|
||||||
public :
|
public :
|
||||||
Vertex();
|
Vertex();
|
||||||
Vertex(int x, int y, int z);
|
Vertex(float x, float y, float z);
|
||||||
float norm();
|
float norm();
|
||||||
Vertex projectOn(Vertex v);
|
Vertex projectOn(Vertex v);
|
||||||
Vertex setNorm(int n);
|
Vertex setNorm(float n);
|
||||||
Vertex perpendicular(); // Perpendiculaire 2D dans le sens contraire des aiguilles d'une montre.
|
Vertex perpendicular(); // Perpendiculaire 2D dans le sens contraire des aiguilles d'une montre.
|
||||||
float cosAngle(Vertex v); // cosinus de l'angle entre this et v.
|
float cosAngle(Vertex v); // cosinus de l'angle entre this et v.
|
||||||
static Vertex fromSpherical(float r, float xAngle, float yAngle);
|
static Vertex fromSpherical(float r, float xAngle, float yAngle);
|
||||||
friend Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d); // Intersection entre (a,b) et (c,d).
|
friend Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d); // Intersection entre (a,b) et (c,d).
|
||||||
|
|
||||||
public :
|
public :
|
||||||
operator Vertexf();
|
operator Vertex();
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const Vertex& v);
|
||||||
|
friend Vertex operator+(const Vertex& u, const Vertex& v);
|
||||||
|
friend Vertex operator-(const Vertex& u, const Vertex& v);
|
||||||
|
friend Vertex operator-(const Vertex& v);
|
||||||
|
friend Vertex operator*(const Vertex& v, const float n);
|
||||||
|
friend Vertex operator*(const Vertex& u, const Vertex& v);
|
||||||
|
friend Vertex operator/(const Vertex& v, const int n);
|
||||||
|
friend Vertex operator/(const Vertex& v, const float f);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
class Vertex {
|
||||||
|
public :
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
|
||||||
|
public :
|
||||||
|
Vertex();
|
||||||
|
Vertex(float x, float y, float z);
|
||||||
|
float norm();
|
||||||
|
static Vertex fromSpherical(float r, float xAngle, float yAngle);
|
||||||
|
|
||||||
|
public :
|
||||||
|
operator Vertex();
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Vertex& v);
|
friend std::ostream& operator<<(std::ostream& os, const Vertex& v);
|
||||||
friend Vertex operator+(const Vertex& u, const Vertex& v);
|
friend Vertex operator+(const Vertex& u, const Vertex& v);
|
||||||
friend Vertex operator-(const Vertex& u, const Vertex& v);
|
friend Vertex operator-(const Vertex& u, const Vertex& v);
|
||||||
|
@ -31,34 +55,8 @@ class Vertex {
|
||||||
friend Vertex operator*(const Vertex& u, const Vertex& v);
|
friend Vertex operator*(const Vertex& u, const Vertex& v);
|
||||||
friend Vertex operator/(const Vertex& v, const int n);
|
friend Vertex operator/(const Vertex& v, const int n);
|
||||||
friend Vertex operator/(const Vertex& v, const float f);
|
friend Vertex operator/(const Vertex& v, const float f);
|
||||||
friend Vertex operator+(const Vertex& u, const Vertexf& v);
|
friend Vertex operator+(const Vertex& u, const Vertex& v);
|
||||||
friend Vertex operator-(const Vertex& u, const Vertexf& v);
|
friend Vertex operator-(const Vertex& u, const Vertex& v);
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
class Vertexf {
|
|
||||||
public :
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
|
|
||||||
public :
|
|
||||||
Vertexf();
|
|
||||||
Vertexf(float x, float y, float z);
|
|
||||||
float norm();
|
|
||||||
static Vertexf fromSpherical(float r, float xAngle, float yAngle);
|
|
||||||
|
|
||||||
public :
|
|
||||||
operator Vertex();
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Vertexf& v);
|
|
||||||
friend Vertexf operator+(const Vertexf& u, const Vertexf& v);
|
|
||||||
friend Vertexf operator-(const Vertexf& u, const Vertexf& v);
|
|
||||||
friend Vertexf operator-(const Vertexf& v);
|
|
||||||
friend Vertexf operator*(const Vertexf& v, const int n);
|
|
||||||
friend Vertexf operator*(const Vertexf& u, const Vertexf& v);
|
|
||||||
friend Vertexf operator/(const Vertexf& v, const int n);
|
|
||||||
friend Vertexf operator/(const Vertexf& v, const float f);
|
|
||||||
friend Vertexf operator+(const Vertexf& u, const Vertex& v);
|
|
||||||
friend Vertexf operator-(const Vertexf& u, const Vertex& v);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
44
view.cpp
44
view.cpp
|
@ -1,7 +1,7 @@
|
||||||
#include "all_includes.hh"
|
#include "all_includes.hh"
|
||||||
|
|
||||||
// camera(Camera(Vertexf(1000,1000,2000),45,100,1000,0.6)
|
// camera(Camera(Vertex(1000,1000,2000),45,100,1000,0.6)
|
||||||
View::View(Chose* root) : root(root), camera(Camera(Vertexf(9600,10000,15300),0,179,1000,0.6)) {
|
View::View(Chose* root) : root(root), camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6)) {
|
||||||
initWindow();
|
initWindow();
|
||||||
mainLoop();
|
mainLoop();
|
||||||
}
|
}
|
||||||
|
@ -25,17 +25,17 @@ void View::initWindow() {
|
||||||
gluPerspective(70,(double)windowWidth/windowHeight,1,100000); // back frustum : 1km
|
gluPerspective(70,(double)windowWidth/windowHeight,1,100000); // back frustum : 1km
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
float MatSpec[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
float MatSpec[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
float MatDif[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
float MatDif[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
||||||
float MatAmb[4] = {0.3f, 0.3f, 0.6f, 1.0f};
|
float MatAmb[4] = {0.3f, 0.3f, 0.6f, 1.0f};
|
||||||
float shininess = 128.0f;
|
float shininess = 128.0f;
|
||||||
|
|
||||||
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,MatSpec);
|
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,MatSpec);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MatDif);
|
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MatDif);
|
||||||
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,MatAmb);
|
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,MatAmb);
|
||||||
glMaterialfv(GL_FRONT,GL_SHININESS,&shininess);
|
glMaterialfv(GL_FRONT,GL_SHININESS,&shininess);
|
||||||
|
|
||||||
glEnable(GL_LIGHTING); // Active l'éclairage
|
glEnable(GL_LIGHTING); // Active l'éclairage
|
||||||
glEnable(GL_LIGHT0); // Active la lumière 0;
|
glEnable(GL_LIGHT0); // Active la lumière 0;
|
||||||
}
|
}
|
||||||
|
@ -62,13 +62,13 @@ void View::displayAxes() {
|
||||||
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
||||||
glVertex3f(2500.0f, 0.0f, 0.0f); // ending point of the line
|
glVertex3f(2500.0f, 0.0f, 0.0f); // ending point of the line
|
||||||
glEnd( );
|
glEnd( );
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glColor3ub(0,255,0);
|
glColor3ub(0,255,0);
|
||||||
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
||||||
glVertex3f(0.0f, 2500.0f, 0.0f); // ending point of the line
|
glVertex3f(0.0f, 2500.0f, 0.0f); // ending point of the line
|
||||||
glEnd( );
|
glEnd( );
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glColor3ub(0,0,255);
|
glColor3ub(0,0,255);
|
||||||
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
|
||||||
|
@ -81,18 +81,18 @@ void View::displayAxes() {
|
||||||
void View::renderScene(int lastTime, int currentTime) {
|
void View::renderScene(int lastTime, int currentTime) {
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
|
||||||
|
|
||||||
camera.animation(currentTime-lastTime);
|
camera.animation(currentTime-lastTime);
|
||||||
camera.setCamera();
|
camera.setCamera();
|
||||||
|
|
||||||
setLight();
|
setLight();
|
||||||
//displayAxes();
|
//displayAxes();
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
root->display();
|
root->display();
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ void View::mainLoop() {
|
||||||
|
|
||||||
int lastTime = SDL_GetTicks() - 30;
|
int lastTime = SDL_GetTicks() - 30;
|
||||||
int currentTime = 0;
|
int currentTime = 0;
|
||||||
|
|
||||||
while (continuer) {
|
while (continuer) {
|
||||||
lastTime = currentTime;
|
lastTime = currentTime;
|
||||||
currentTime = SDL_GetTicks();
|
currentTime = SDL_GetTicks();
|
||||||
|
@ -133,9 +133,9 @@ void View::mainLoop() {
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera::Camera(Vertexf pos, float xA, float yA, int moveSensitivity, float mouseSensitivity)
|
Camera::Camera(Vertex pos, float xA, float yA, int moveSensitivity, float mouseSensitivity)
|
||||||
: cameraCenter(pos),
|
: cameraCenter(pos),
|
||||||
cameraSight(cameraCenter + Vertexf::fromSpherical(100,yA,xA)),
|
cameraSight(cameraCenter + Vertex::fromSpherical(100,yA,xA)),
|
||||||
xAngle(xA),
|
xAngle(xA),
|
||||||
yAngle(yA),
|
yAngle(yA),
|
||||||
moveDist(moveSensitivity),
|
moveDist(moveSensitivity),
|
||||||
|
@ -151,7 +151,7 @@ std::ostream& Camera::print(std::ostream& os) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::setCamera() {
|
void Camera::setCamera() {
|
||||||
cameraSight = cameraCenter + Vertexf::fromSpherical(100, yAngle, xAngle);
|
cameraSight = cameraCenter + Vertex::fromSpherical(100, yAngle, xAngle);
|
||||||
gluLookAt(cameraCenter.x,cameraCenter.y,cameraCenter.z, cameraSight.x, cameraSight.y, cameraSight.z,0,0,1);
|
gluLookAt(cameraCenter.x,cameraCenter.y,cameraCenter.z, cameraSight.x, cameraSight.y, cameraSight.z,0,0,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,17 +214,17 @@ void Camera::keyboard(const SDL_KeyboardEvent &eventKey) {
|
||||||
|
|
||||||
void Camera::animation(int elapsedTime) {
|
void Camera::animation(int elapsedTime) {
|
||||||
float diff = ((float)(elapsedTime+1)/1000.)*(float)moveDist;
|
float diff = ((float)(elapsedTime+1)/1000.)*(float)moveDist;
|
||||||
|
|
||||||
if(up)
|
if(up)
|
||||||
cameraCenter = cameraCenter + Vertexf::fromSpherical(diff, yAngle, xAngle);
|
cameraCenter = cameraCenter + Vertex::fromSpherical(diff, yAngle, xAngle);
|
||||||
if(down)
|
if(down)
|
||||||
cameraCenter = cameraCenter - Vertexf::fromSpherical(diff, yAngle, xAngle);
|
cameraCenter = cameraCenter - Vertex::fromSpherical(diff, yAngle, xAngle);
|
||||||
if(left)
|
if(left)
|
||||||
cameraCenter = cameraCenter - Vertexf::fromSpherical(diff, 90, xAngle - 90);
|
cameraCenter = cameraCenter - Vertex::fromSpherical(diff, 90, xAngle - 90);
|
||||||
if(right)
|
if(right)
|
||||||
cameraCenter = cameraCenter + Vertexf::fromSpherical(diff, 90, xAngle - 90);
|
cameraCenter = cameraCenter + Vertex::fromSpherical(diff, 90, xAngle - 90);
|
||||||
if(pageUp)
|
if(pageUp)
|
||||||
cameraCenter = cameraCenter - Vertexf::fromSpherical(diff, yAngle + 90, xAngle);
|
cameraCenter = cameraCenter - Vertex::fromSpherical(diff, yAngle + 90, xAngle);
|
||||||
if(pageDown)
|
if(pageDown)
|
||||||
cameraCenter = cameraCenter + Vertexf::fromSpherical(diff, yAngle + 90, xAngle);
|
cameraCenter = cameraCenter + Vertex::fromSpherical(diff, yAngle + 90, xAngle);
|
||||||
}
|
}
|
||||||
|
|
6
view.hh
6
view.hh
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
public :
|
public :
|
||||||
Vertexf cameraCenter;
|
Vertex cameraCenter;
|
||||||
Vertexf cameraSight;
|
Vertex cameraSight;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
float xAngle;
|
float xAngle;
|
||||||
|
@ -27,7 +27,7 @@ class Camera {
|
||||||
bool pageDown;
|
bool pageDown;
|
||||||
|
|
||||||
public :
|
public :
|
||||||
Camera(Vertexf pos, float xA, float yA, int moveSensitivity, float mouseSensitivity);
|
Camera(Vertex pos, float xA, float yA, int moveSensitivity, float mouseSensitivity);
|
||||||
void setCamera();
|
void setCamera();
|
||||||
void mouseMotion(const SDL_MouseMotionEvent &event);
|
void mouseMotion(const SDL_MouseMotionEvent &event);
|
||||||
void keyboard(const SDL_KeyboardEvent &event);
|
void keyboard(const SDL_KeyboardEvent &event);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user