Ajout de Quad::offsetNormal .

This commit is contained in:
Georges Dupéron 2012-01-10 16:46:25 +01:00
parent 474ab3e706
commit f73c270ce3
11 changed files with 27 additions and 20 deletions

View File

@ -128,3 +128,7 @@ float Quad::surface() const {
Triangle sw(c[SE], c[SW], c[NW]);
return ne.surface() + sw.surface();
}
Quad Quad::offsetNormal(float offset) const {
return ((*this) + Triangle(c[NE], c[SE], c[SW]).normal().setNorm(offset));
}

View File

@ -41,6 +41,7 @@ class Quad {
float surface() const;
//void cutCornerCorner(Coin from) const;
Quad makeParallelogram() const;
Quad offsetNormal(float offset) const;
};

View File

@ -61,3 +61,12 @@ float Triangle::surface() const {
float base = Segment(c[LEFT], c[RIGHT]).length();
return (base * hauteur) / 2.f;
}
Vertex Triangle::normal() const {
return ((c[LEFT] - c[TOP]) * (c[RIGHT] - c[TOP]));
}
Vertex Triangle::normalizedNormal() const {
Vertex v = normal();
return v / v.norm();
}

View File

@ -33,7 +33,8 @@ class Triangle {
Triangle inset(CoteTriangle side, float offset) const;
Triangle insetLTR(float offset) const;
Vertex randomPoint(int seed, int n) const;
void display();
Vertex normal() const;
Vertex normalizedNormal() const;
};
#endif

View File

@ -1,19 +1,14 @@
#include "all_includes.hh"
GPUTriangle::GPUTriangle(Vertex left, Vertex top, Vertex right, unsigned char _r, unsigned char _g, unsigned char _b)
: c(left, top, right), r(_r), g(_g), b(_b), vnormal(normal(left,top,right)) {
: c(left, top, right), r(_r), g(_g), b(_b), vnormal(c.normalizedNormal()) {
}
GPUTriangle::GPUTriangle(Triangle _c, unsigned char _r, unsigned char _g, unsigned char _b)
: c(_c), r(_r), g(_g), b(_b), vnormal(normal(c[LEFT], c[TOP], c[RIGHT])) {
: c(_c), r(_r), g(_g), b(_b), vnormal(c.normalizedNormal()) {
}
Vertex GPUTriangle::normal(Vertex left, Vertex top, Vertex right) {
Vertex v = (left - top)*(right - top);
return v / v.norm();
}
void GPUTriangle::display() {
void GPUTriangle::display() const {
View::setColor(r,g,b);
glNormal3d(vnormal.x,vnormal.y,vnormal.z);
glVertex3d(c[LEFT].x,c[LEFT].y,c[LEFT].z);
@ -21,7 +16,7 @@ void GPUTriangle::display() {
glVertex3d(c[RIGHT].x,c[RIGHT].y,c[RIGHT].z);
}
void GPUTriangle::displayNormal() {
void GPUTriangle::displayNormal() const {
glColor3ub(255,255,0);
// Vertex v = (c[0] + c[1] + c[2]) / 3;
// glVertex3d(v.x,v.y,v.z);

View File

@ -14,11 +14,8 @@ class GPUTriangle {
public :
GPUTriangle(Vertex left, Vertex top, Vertex right, unsigned char r, unsigned char g, unsigned char b);
GPUTriangle(Triangle c, unsigned char r, unsigned char g, unsigned char b);
void display();
void displayNormal();
private :
Vertex normal(Vertex left, Vertex top, Vertex right);
void display() const;
void displayNormal() const;
};
#endif

View File

@ -25,7 +25,7 @@ Chose* QuartierTri::factory(int seed, int n, Triangle c) {
return new QuartierTriTrapeze(c);
}
} else {
return new TerrainTriHerbe(c);
return new BatimentTri(c);
}
}

View File

@ -8,7 +8,7 @@ class RouteQuadChaussee : public Chose {
Quad c;
public :
RouteQuadChaussee(Quad c);
RouteQuadChaussee(Quad _c);
virtual void triangulation();
virtual void getBoundingBoxPoints();
};

View File

@ -9,7 +9,7 @@ class TrottoirQuadNormal : public Chose {
float height;
public :
TrottoirQuadNormal(Quad c, float height);
TrottoirQuadNormal(Quad _c, float _height);
virtual void triangulation();
virtual void getBoundingBoxPoints();
};

View File

@ -9,7 +9,7 @@ class TerrainQuadHerbe : public Chose {
Quad c;
public :
TerrainQuadHerbe(Quad c);
TerrainQuadHerbe(Quad _c);
virtual void triangulation();
virtual void getBoundingBoxPoints();
};

View File

@ -9,7 +9,7 @@ class TerrainTriHerbe : public Chose {
Triangle c;
public :
TerrainTriHerbe(Triangle c);
TerrainTriHerbe(Triangle _c);
virtual void triangulation();
virtual void getBoundingBoxPoints();
};