Quelques corrections sur bâtiment.

This commit is contained in:
Georges Dupéron 2011-11-29 12:06:50 +01:00
parent b7b2dccd73
commit 1851daa0aa
9 changed files with 40 additions and 48 deletions

View File

@ -16,12 +16,12 @@ void recursiveSubdivide(Chose* c) {
int main() { int main() {
// Générer une tile de base // Générer une tile de base
Vertex ne(1000, 1000, 0); Vertex ne(50, 50, 0);
Vertex sw(0, 0, 0); Vertex sw(0, 0, 0);
RectangleRoutes* r = new RectangleRoutes(ne, sw); Chose* c = new RectangleRoutes(ne, sw);
recursiveSubdivide(r); recursiveSubdivide(c);
new View(r); new View(c);
// tile.subdivide tant qu'on n'a pas le niveau de détail désiré. // tile.subdivide tant qu'on n'a pas le niveau de détail désiré.
return 0; return 0;
} }

View File

@ -20,8 +20,8 @@ void Batiment::triangulation() {
// abcd sont les quatre coins du bâtiment. // abcd sont les quatre coins du bâtiment.
Vertex a = this->ne; Vertex a = this->ne;
Vertex b = Vertex(this->ne.x, this->sw.y, 0); Vertex b = Vertex(this->ne.x, this->sw.y, 0);
Vertex c = this->sw; Vertex c = Vertex(this->sw.x, this->ne.y, 0);
Vertex d = Vertex(this->sw.x, this->ne.y, 0); Vertex d = this->sw;
int h = 6; int h = 6;
Vertex ah = a + Vertex(0,0,h); Vertex ah = a + Vertex(0,0,h);
@ -31,16 +31,16 @@ void Batiment::triangulation() {
Vertex toit = (ah + bh + ch + dh) / 4 + Vertex(0,0,h/5); Vertex toit = (ah + bh + ch + dh) / 4 + Vertex(0,0,h/5);
// 4 Murs // 4 Murs
addTriangle(new Triangle(a,bh,ah)); addTriangle(new Triangle(a,b,bh)); // a-b-bh-ah addTriangle(new Triangle(a,bh,ah,0xf1,0xe3,0xad)); addTriangle(new Triangle(a,b,bh,0xf1,0xe3,0xad)); // a-b-bh-ah
addTriangle(new Triangle(b,dh,bh)); addTriangle(new Triangle(b,d,dh)); // b-d-dh-bh addTriangle(new Triangle(b,dh,bh,0xf1,0xe3,0xad)); addTriangle(new Triangle(b,d,dh,0xf1,0xe3,0xad)); // b-d-dh-bh
addTriangle(new Triangle(d,ch,dh)); addTriangle(new Triangle(d,c,ch)); // d-c-ch-dh addTriangle(new Triangle(d,ch,dh,0xf1,0xe3,0xad)); addTriangle(new Triangle(d,c,ch,0xf1,0xe3,0xad)); // d-c-ch-dh
addTriangle(new Triangle(c,ah,ch)); addTriangle(new Triangle(c,a,ah)); // c-a-ah-ch addTriangle(new Triangle(c,ah,ch,0xf1,0xe3,0xad)); addTriangle(new Triangle(c,a,ah,0xf1,0xe3,0xad)); // c-a-ah-ch
// 1 Toit // 1 Toit
addTriangle(new Triangle(ah,toit,bh)); addTriangle(new Triangle(ah,toit,bh,0x8a,0x48,0x3c));
addTriangle(new Triangle(bh,toit,dh)); addTriangle(new Triangle(bh,toit,dh,0x8a,0x48,0x3c));
addTriangle(new Triangle(dh,toit,ch)); addTriangle(new Triangle(dh,toit,ch,0x8a,0x48,0x3c));
addTriangle(new Triangle(ch,toit,ah)); addTriangle(new Triangle(ch,toit,ah,0x8a,0x48,0x3c));
} }
std::ostream& operator<<(std::ostream& os, const Batiment* r) { std::ostream& operator<<(std::ostream& os, const Batiment* r) {

View File

@ -23,6 +23,6 @@ std::ostream& operator<<(std::ostream& os, const Carrefour& c) {
void Carrefour::triangulation() { void Carrefour::triangulation() {
triangles.reserve(2); triangles.reserve(2);
addTriangle(new Triangle(corners[SW], corners[NW], corners[NE])); addTriangle(new Triangle(corners[SW], corners[NW], corners[NE], 0x80, 0x80, 0x80));
addTriangle(new Triangle(corners[SW], corners[SE], corners[NE])); addTriangle(new Triangle(corners[SW], corners[SE], corners[NE], 0x80, 0x80, 0x80));
} }

View File

@ -45,12 +45,13 @@ void RectangleRoutes::triangulation() {
triangles.reserve(2); triangles.reserve(2);
Vertex nw(this->sw.x, this->ne.y, 0); Vertex nw(this->sw.x, this->ne.y, 0);
Vertex se(this->ne.x, this->sw.y, 0); Vertex se(this->ne.x, this->sw.y, 0);
addTriangle(new Triangle(this->sw, nw, this->ne)); addTriangle(new Triangle(this->sw, nw, this->ne, 0xc0, 0xc0, 0xc0));
addTriangle(new Triangle(this->sw, se, this->ne)); addTriangle(new Triangle(this->sw, se, this->ne, 0xc0, 0xc0, 0xc0));
} }
Chose* RectangleRoutes::sub(Vertex ne, Vertex sw) { Chose* RectangleRoutes::sub(Vertex ne, Vertex sw) {
Segment rect = Segment(ne,sw); Segment rect = Segment(ne,sw);
std::cout << this << " ne=" << ne << " sw=" << sw << std::endl;
if (rect.width() < 10 || rect.height() < 10) { if (rect.width() < 10 || rect.height() < 10) {
return new Batiment(ne, sw); return new Batiment(ne, sw);
} else { } else {

View File

@ -25,6 +25,6 @@ std::ostream& operator<<(std::ostream& os, const Route& r) {
void Route::triangulation() { void Route::triangulation() {
triangles.reserve(2); triangles.reserve(2);
addTriangle(new Triangle(corners[SW], corners[NW], corners[NE])); addTriangle(new Triangle(corners[SW], corners[NW], corners[NE], 0x6c, 0x6c, 0x6c));
addTriangle(new Triangle(corners[SW], corners[SE], corners[NE])); addTriangle(new Triangle(corners[SW], corners[SE], corners[NE], 0x6c, 0x6c, 0x6c));
} }

View File

@ -9,9 +9,9 @@ int Segment::length() {
} }
int Segment::width() { int Segment::width() {
return u.x - v.x; return std::abs(u.x - v.x);
} }
int Segment::height() { int Segment::height() {
return u.y - v.y; return std::abs(u.y - v.y);
} }

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
Triangle::Triangle(Vertex a, Vertex b, Vertex c): a(a), b(b), c(c) { 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) {
// TODO : calcul de la normale. // TODO : calcul de la normale.
normal = Vertex(0,0,1); normal = Vertex(0,0,1);
} }
@ -10,12 +10,16 @@ std::ostream& operator<<(std::ostream& os, const Triangle* t) {
} }
std::ostream& operator<<(std::ostream& os, const Triangle& t) { std::ostream& operator<<(std::ostream& os, const Triangle& t) {
return os << "Triangle " << t.a << "--" << t.b << "--" << t.c << "-- cycle"; return os << "Triangle " << t.v1 << "--" << t.v2 << "--" << t.v3 << "-- cycle";
} }
void Triangle::display() { void Triangle::display() {
glColor3ub(r, g, b);
//std::cout << (int)r << "," << (int)g << "," << (int)b << std::endl;
glNormal3d(normal.x,normal.y,normal.z); glNormal3d(normal.x,normal.y,normal.z);
glVertex3d(a.x,a.y,a.z); glBegin(GL_TRIANGLES);
glVertex3d(b.x,b.y,b.z); glVertex3d(v1.x,v1.y,v1.z);
glVertex3d(c.x,c.y,c.z); glVertex3d(v2.x,v2.y,v2.z);
glVertex3d(v3.x,v3.y,v3.z);
glEnd();
} }

View File

@ -5,12 +5,15 @@
class Triangle { class Triangle {
public: public:
Vertex a; Vertex v1;
Vertex b; Vertex v2;
Vertex c; Vertex v3;
unsigned char r;
unsigned char g;
unsigned char b;
Vertex normal; Vertex normal;
public: public:
Triangle(Vertex a, Vertex b, Vertex c); Triangle(Vertex v1, Vertex v2, Vertex v3, unsigned char r, unsigned char g, unsigned char b);
void display(); void display();
public: public:
friend std::ostream& operator<<(std::ostream& os, const Triangle* t); friend std::ostream& operator<<(std::ostream& os, const Triangle* t);

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
View::View(Chose* root) : root(root), cameraCenter(500,-500,100), xAngle(0), yAngle(0), moveDist(40) { View::View(Chose* root) : root(root), cameraCenter(500,-500,100), xAngle(135), yAngle(102), moveDist(40) {
cameraSight = cameraCenter + Vertex::fromSpherical(100, yAngle, xAngle); cameraSight = cameraCenter + Vertex::fromSpherical(100, yAngle, xAngle);
initWindow(); initWindow();
mainLoop(); mainLoop();
@ -64,20 +64,6 @@ void View::displayAxes() {
glVertex3f(0.0f, 0.0f, 2500.0f); // ending point of the line glVertex3f(0.0f, 0.0f, 2500.0f); // ending point of the line
glEnd( ); glEnd( );
Vertex dest = Vertex::fromSpherical(100, yAngle, xAngle);
glBegin(GL_LINES);
glColor3ub(255,0,255);
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
glVertex3d(dest.x, dest.y, dest.z); // ending point of the line
glEnd( );
dest = cameraCenter - dest;
glBegin(GL_LINES);
glColor3ub(255,255,0);
glVertex3d(cameraCenter.x, cameraCenter.y, cameraCenter.z); // origin of the line
glVertex3d(dest.x, dest.y, dest.z); // ending point of the line
glEnd( );
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
} }
@ -91,9 +77,7 @@ void View::renderScene() {
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);
displayAxes(); displayAxes();
glBegin(GL_TRIANGLES);
root->display(); root->display();
glEnd();
glFlush(); glFlush();
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();