On passe -ansi -pedantic -Wconversion.

This commit is contained in:
Georges Dupéron 2012-01-09 15:28:10 +01:00
parent 4740ce442d
commit 30251f62c0
42 changed files with 140 additions and 120 deletions

View File

@ -3,7 +3,7 @@ CXX=g++
CCWARN=-Wall -Wextra -Werror CCWARN=-Wall -Wextra -Werror
# TODO : -O3 -m32 ou -m64 # TODO : -O3 -m32 ou -m64
# -g -rdynamic uniquement pour le debug. # -g -rdynamic uniquement pour le debug.
CFLAGS=-O0 -g -rdynamic -m32 -I. $(CCWARN) CFLAGS=-O0 -g -rdynamic -I. $(CCWARN)
SOURCES = $(shell echo *.cpp geometry/*.cpp rules/*.cpp rules/*/*.cpp) SOURCES = $(shell echo *.cpp geometry/*.cpp rules/*.cpp rules/*/*.cpp)
HEADERS = $(shell echo *.hh geometry/*.hh rules/*.hh rules/*/*.hh) HEADERS = $(shell echo *.hh geometry/*.hh rules/*.hh rules/*/*.hh)

View File

@ -1,8 +1,6 @@
#ifndef _ALL_INCLUDES_HH_ #ifndef _ALL_INCLUDES_HH_
#define _ALL_INCLUDES_HH_ #define _ALL_INCLUDES_HH_
typedef long long int64;
class Chose; class Chose;
// DEBUG // DEBUG

View File

@ -2,10 +2,10 @@
#define _GEOMETRY_ANGLE_HH_ #define _GEOMETRY_ANGLE_HH_
namespace Angle { namespace Angle {
const float Pi = 3.141592653589793238462643383279;
const double dPi = 3.141592653589793238462643383279; const double dPi = 3.141592653589793238462643383279;
const float Pi = (float)(dPi);
float r2d(float rad) { return rad / Pi * 180; } float r2d(float rad) { return rad / Pi * 180; }
float d2r(float deg) { return deg / 180 * Pi; } float d2r(float deg) { return deg / 180 * Pi; }
}; }
#endif #endif

View File

@ -10,9 +10,12 @@ enum Cardinal {
inline Cardinal operator+(Cardinal c, int i) { inline Cardinal operator+(Cardinal c, int i) {
return Cardinal((int(c) + int(i)) & 3); return Cardinal((int(c) + int(i)) & 3);
//int result = int(c) << (i & 3);
//result = result | result >> 4;
//return Cardinal (c & 15);
} }
inline Cardinal operator-(Cardinal c, int i) { inline Cardinal operator-(Cardinal c, int i) {
return Cardinal((int(c) - int(i)) & 3); return c + (-i);
} }
enum Coin { enum Coin {
@ -26,7 +29,7 @@ inline Coin operator+(Coin c, int i) {
return Coin((int(c) + int(i)) & 3); return Coin((int(c) + int(i)) & 3);
} }
inline Coin operator-(Coin c, int i) { inline Coin operator-(Coin c, int i) {
return Coin((int(c) - int(i)) & 3); return c + (-i);
} }
enum SommetTriangle { enum SommetTriangle {

View File

@ -28,7 +28,7 @@ Quad Quad::insetNESW(float offset) const {
} }
Quad Quad::makeParallelogram() const { Quad Quad::makeParallelogram() const {
int l1, l2; float l1, l2;
Quad q(c[NE],c[SE],c[SW],c[NW]); Quad q(c[NE],c[SE],c[SW],c[NW]);
if(length(N) < length(S)) { if(length(N) < length(S)) {

View File

@ -11,15 +11,15 @@ Segment Segment::reduce(float value) {
return Segment(u,u+((v - u) / reduc)); return Segment(u,u+((v - u) / reduc));
} }
int Segment::width() { float Segment::width() {
return std::abs(u.x - v.x); return std::abs(u.x - v.x);
} }
int Segment::height() { float Segment::height() {
return std::abs(u.y - v.y); return std::abs(u.y - v.y);
} }
Vertex Segment::randomPos(int seed, int n, int a, int b) { Vertex Segment::randomPos(int seed, int n, float a, float b) {
int pos = hashInRange(seed, n, a, b); float pos = floatInRange(seed, n, a, b);
return (u * pos + v * (100-pos)) / 100; return (u * pos + v * (1-pos));
} }

View File

@ -11,10 +11,10 @@ class Segment {
public : public :
Segment(Vertex u, Vertex v); Segment(Vertex u, Vertex v);
float length(); float length();
int width(); float width();
int height(); float height();
Segment reduce(float value); Segment reduce(float value);
Vertex randomPos(int seed, int n, int a, int b); // Renvoir un vertex sur le segment [u,v], à une position entre a% and b%. Vertex randomPos(int seed, int n, float a, float b); // Renvoie un vertex sur le segment [u,v], à une position entre a et b.
}; };
#endif #endif

View File

@ -51,7 +51,7 @@ Triangle operator+(const Triangle& t, const Vertex& v) {
} }
Vertex Triangle::randomPoint(int seed, int n) const { Vertex Triangle::randomPoint(int seed, int n) const {
float rndl = hashInRange(seed, n, 0, 100); float rndl = floatInRange(seed, n, 0, 100);
float rndr = hashInRange(seed, hash2(n, 42), 0, 100 - rndl); float rndr = floatInRange(seed, hash2(n, 42), 0, 100 - rndl);
return c[TOP] + (c[LEFT] - c[TOP]) * (rndl/100.f) + (c[RIGHT] - c[TOP]) * (rndr/100.f); return c[TOP] + (c[LEFT] - c[TOP]) * (rndl/100.f) + (c[RIGHT] - c[TOP]) * (rndr/100.f);
} }

View File

@ -6,19 +6,15 @@ Vertex::Vertex(float x, float y, float z): x(x), y(y), z(z) {}
float Vertex::norm() const { return std::sqrt(x*x + y*y + z*z); } float Vertex::norm() const { return std::sqrt(x*x + y*y + z*z); }
// TODO : this is 2D only, use Vertex2d. // TODO : Ce code ne marche qu'en 2D !
Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d) { Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d) {
// Note : si les deux lignes sont parallèles, on risque fort // Note : si les deux lignes sont parallèles, on risque fort
// d'avoir une division par zéro. // d'avoir une division par zéro.
// http://en.wikipedia.org/wiki/Line-line_intersection // http://en.wikipedia.org/wiki/Line-line_intersection
int64 x1 = a.x; int64 y1 = a.y; float denominator = ((a.x-b.x)*(c.y-d.y) - (a.y-b.y)*(c.x-d.x));
int64 x2 = b.x; int64 y2 = b.y;
int64 x3 = c.x; int64 y3 = c.y;
int64 x4 = d.x; int64 y4 = d.y;
int64 denominator = ((x1-x2)*(y3-y4) - (y1-y2)*(x3-x4));
return Vertex( return Vertex(
((x1*y2-y1*x2)*(x3-x4) - (x1-x2)*(x3*y4-y3*x4)) / denominator, ((a.x*b.y-a.y*b.x)*(c.x-d.x) - (a.x-b.x)*(c.x*d.y-c.y*d.x)) / denominator,
((x1*y2-y1*x2)*(y3-y4) - (y1-y2)*(x3*y4-y3*x4)) / denominator, ((a.x*b.y-a.y*b.x)*(c.y-d.y) - (a.y-b.y)*(c.x*d.y-c.y*d.x)) / denominator,
0 0
); );
} }
@ -49,8 +45,6 @@ float Vertex::angle(Vertex v) const {
return std::acos(cosAngle(v)); return std::acos(cosAngle(v));
} }
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 << ")";
} }
@ -87,9 +81,9 @@ Vertex operator/(const Vertex& v, const float f) {
Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) { Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) {
// http://electron9.phys.utk.edu/vectors/3dcoordinates.htm // http://electron9.phys.utk.edu/vectors/3dcoordinates.htm
return Vertex( return Vertex(
r * std::sin(xAngle / 180 * 3.14159) * std::cos(yAngle / 180 * 3.14159), r * std::sin(xAngle / 180.f * Angle::Pi) * std::cos(yAngle / 180.f * Angle::Pi),
r * std::sin(xAngle / 180 * 3.14159) * std::sin(yAngle / 180 * 3.14159), r * std::sin(xAngle / 180.f * Angle::Pi) * std::sin(yAngle / 180.f * Angle::Pi),
r * std::cos(xAngle / 180 * 3.14159) r * std::cos(xAngle / 180.f * Angle::Pi)
); );
} }

View File

@ -22,7 +22,6 @@ class Vertex {
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 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);

View File

@ -24,10 +24,28 @@ unsigned int hash2(unsigned int a, unsigned int b) {
return h; return h;
} }
int hashInRange(int seed, int n, int a, int b) { float floatInRange(int seed, int n, float a, float b) {
return (hash2(seed, n) % (b - a)) + a; // 24 bits de précision, ça devrait suffire pour la plupart des utilisations.
return (float)(hash2(seed, n) & 0xffffff) / (float)(0x1000000) * (b-a) + a;
} }
bool proba(int seed, int n, unsigned int a, unsigned int b) { bool proba(int seed, int n, unsigned int a, unsigned int b) {
return ((hash2(seed, n) % b) < a); return ((hash2(seed, n) % b) < a);
} }
unsigned int float2uint(float f) {
// TODO : il y a plein de problèmes avec cette conversion :
// 1) Il y a plusieurs représentations possibles pour le même float,
// donc si on re-split un objet 10 minutes après et qu'on n'a pas
// la même représentation, on n'aura pas la même entropie pour les hash.
// 2) On ne peut pas faire juste fi.f = f; return fi.ui; car si
// sizeof(int) > sizeof(float), on lira des saletés.
// 3) De toute façon, tout ça est principalement du "undefined behaviour".
FloatUIntUnion fi;
for (unsigned int i = 0; i < sizeof(fi); i++) {
// effacer la structure.
reinterpret_cast<char*>(&fi)[i] = 0;
}
fi.f = f;
return fi.ui;
}

View File

@ -6,7 +6,12 @@
int random_seed(); int random_seed();
unsigned int hash2(unsigned int a, unsigned int b); unsigned int hash2(unsigned int a, unsigned int b);
int hashInRange(int seed, int n, int a, int b); // Renvoie le n-ième nombre aléatoire dérivé de seed entre a et b (a inclus, b non inclus). float floatInRange(int seed, int n, float a, float b); // Renvoie le n-ième nombre aléatoire dérivé de seed entre a et b (a inclus, b non inclus).
bool proba(int seed, int n, unsigned int a, unsigned int b); // Renvoie vrai avec `a` fois sur `b`. bool proba(int seed, int n, unsigned int a, unsigned int b); // Renvoie vrai avec `a` fois sur `b`.
typedef union FloatUIntUnion {
float f;
unsigned int ui;
} FloatUIntUnion;
unsigned int float2uint(float f);
#endif #endif

View File

@ -3,7 +3,7 @@ Heap::Heap()
bucketArraySize(1), lastNode(-1) { bucketArraySize(1), lastNode(-1) {
} }
void Heap::init(int id, int factor) { this->id = id; this->factor = factor; } void Heap::init(int id, int factor) { this->id = id; this->factor = (float)factor; }
void Heap::insert(float key, Chose* value) { void Heap::insert(float key, Chose* value) {
++lastNode; ++lastNode;

View File

@ -30,7 +30,7 @@ private:
inline int leftchild(int node) { return node * 2 + 1; } inline int leftchild(int node) { return node * 2 + 1; }
inline int rightchild(int node) { return node * 2 + 2; } inline int rightchild(int node) { return node * 2 + 2; }
public: public:
int factor; float factor; // -1.f ou +1.f
Heap(); Heap();
void insert(float key, Chose* value); void insert(float key, Chose* value);
void remove(Chose* value); void remove(Chose* value);

View File

@ -1,9 +1,12 @@
#include "all_includes.hh" #include "all_includes.hh"
// TODO : créer les routes dans les bâtiments
// TODO : faire des enum SetCoin, SetCardinal, SetSommetTriangle, SetCoteTriangle.
int main() { int main() {
// Générer une tile de base // Générer une tile de base
std::cout << "Initial seed = " << Chose::initialSeed << std::endl; std::cout << "Initial seed = " << Chose::initialSeed << std::endl;
int size = 20000; float size = 20000;
Vertex ne(size, size, 0); Vertex ne(size, size, 0);
Vertex se(size, 0, 0); Vertex se(size, 0, 0);
Vertex sw(0, 0, 0); Vertex sw(0, 0, 0);

View File

@ -17,7 +17,7 @@ bool BatimentQuad::split() {
//addQuad(c[SE],c[SW],c[NW],c[NE],0xDD,0xDD,0xDD); //addQuad(c[SE],c[SW],c[NW],c[NE],0xDD,0xDD,0xDD);
addChild(new BatimentQuadMaisonPont(q,800)); addChild(new BatimentQuadMaisonPont(q,800));
} else { } else {
int th = 20; // Terrain height. float th = 20; // Terrain height.
Quad q = Quad(c[NE],c[SE],c[SW],c[NW]).insetNESW(140); Quad q = Quad(c[NE],c[SE],c[SW],c[NW]).insetNESW(140);
addChild(new TrottoirQuadNormal(Quad(c[NE],c[SE],q[SE],q[NE]),th)); addChild(new TrottoirQuadNormal(Quad(c[NE],c[SE],q[SE],q[NE]),th));
@ -36,9 +36,8 @@ bool BatimentQuad::split() {
void BatimentQuad::triangulation() { void BatimentQuad::triangulation() {
triangles.reserve(12); triangles.reserve(12);
int h = hashInRange(seed,1,minHeight,maxHeight); float h = floatInRange(seed,1,minHeight,maxHeight);
int htoit = hashInRange(seed,2,minHeight/2,maxHeight/2); float htoit = floatInRange(seed,2,minHeight/2,maxHeight/2);
h += htoit;
addGPUOcto(c, c + Vertex(0,0,h), 0xFF, 0xFF, 0x00); addGPUOcto(c, c + Vertex(0,0,h + htoit), 0xFF, 0xFF, 0x00);
} }

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
BatimentQuadBlock::BatimentQuadBlock(Quad c, int height) : Chose(), c(c), height(height) { BatimentQuadBlock::BatimentQuadBlock(Quad c, float height) : Chose(), c(c), height(height) {
addEntropy(c); addEntropy(c);
} }

View File

@ -7,10 +7,10 @@
class BatimentQuadBlock : public Chose { class BatimentQuadBlock : public Chose {
private : private :
Quad c; Quad c;
int height; float height;
public : public :
BatimentQuadBlock(Quad c, int height); BatimentQuadBlock(Quad c, float height);
virtual bool split(); virtual bool split();
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
BatimentQuadFenetre::BatimentQuadFenetre(Quad c, int height) : Chose(), c(c), height(height) { BatimentQuadFenetre::BatimentQuadFenetre(Quad c, float height) : Chose(), c(c), height(height) {
addEntropy(c); addEntropy(c);
} }

View File

@ -6,11 +6,11 @@
class BatimentQuadFenetre: public Chose { class BatimentQuadFenetre: public Chose {
private : private :
Quad c; Quad c;
int height; float height;
public : public :
BatimentQuadFenetre(Quad c, int height); BatimentQuadFenetre(Quad c, float height);
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();
}; };

View File

@ -12,8 +12,8 @@ void BatimentQuadMaison::getBoundingBoxPoints() {
void BatimentQuadMaison::triangulation() { void BatimentQuadMaison::triangulation() {
triangles.reserve(12); triangles.reserve(12);
int h = hashInRange(seed,0,minHeight,maxHeight); float h = floatInRange(seed,0,minHeight,maxHeight);
int htoit = hashInRange(seed,0,minHeight/2,maxHeight/2); float htoit = floatInRange(seed,0,minHeight/2,maxHeight/2);
Quad ch = c + Vertex(0,0,h); Quad ch = c + Vertex(0,0,h);
Vertex toit = (ch[NE] + ch[SE] + ch[SW] + ch[NW]) / 4 + Vertex(0,0,htoit); Vertex toit = (ch[NE] + ch[SE] + ch[SW] + ch[NW]) / 4 + Vertex(0,0,htoit);

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
BatimentQuadMaisonPont::BatimentQuadMaisonPont(Quad c, int height) : Chose(), c(c), height(height) { BatimentQuadMaisonPont::BatimentQuadMaisonPont(Quad c, float height) : Chose(), c(c), height(height) {
addEntropy(c); addEntropy(c);
} }
@ -14,7 +14,7 @@ bool BatimentQuadMaisonPont::split() {
if(Segment(q[NE],q[NW]).length() < Segment(q[NE],q[SE]).length()) if(Segment(q[NE],q[NW]).length() < Segment(q[NE],q[SE]).length())
q = q << 1; q = q << 1;
float partLength = Segment(q[NE],q[NW]).length() / 3; float partLength = Segment(q[NE],q[NW]).length() / 3;
int partHeight = 2.5*height/3.; float partHeight = 2.5f * height / 3.f;
Quad qa = q.inset(E,2*partLength); Quad qa = q.inset(E,2*partLength);
Quad qb = q.inset(W,2*partLength); Quad qb = q.inset(W,2*partLength);
Quad qc = q.inset(E, partLength).inset(W, partLength); Quad qc = q.inset(E, partLength).inset(W, partLength);
@ -31,15 +31,15 @@ bool BatimentQuadMaisonPont::split() {
} }
void BatimentQuadMaisonPont::triangulation() { void BatimentQuadMaisonPont::triangulation() {
float h = 2.5*height/3.; float h = 2.5f * height / 3.f;
Quad q = c.makeParallelogram(); Quad q = c.makeParallelogram();
Quad qh = q + Vertex(0,0,h); Quad qh = q + Vertex(0,0,h);
addGPUQuad(c,0x80,0x80,0x80); addGPUQuad(c,0x80,0x80,0x80);
addGPUOcto(q,qh,0xF1,0xE0,0xE0); addGPUOcto(q,qh,0xF1,0xE0,0xE0);
Vertex ce = qh[SE] + (qh[NE] - qh[SE])/2 + Vertex(0,0,0.5*height/3.f); Vertex ce = qh[SE] + (qh[NE] - qh[SE])/2 + Vertex(0,0,0.5f * height / 3.f);
Vertex cw = qh[SW] + (qh[NW] - qh[SW])/2 + Vertex(0,0,0.5*height/3.f); Vertex cw = qh[SW] + (qh[NW] - qh[SW])/2 + Vertex(0,0,0.5f * height / 3.f);
addGPUTriangle(qh[NW],cw,qh[SW],0xF1,0xE0,0xE0); addGPUTriangle(qh[NW],cw,qh[SW],0xF1,0xE0,0xE0);
addGPUTriangle(qh[SE],ce,qh[NE],0xF1,0xE0,0xE0); addGPUTriangle(qh[SE],ce,qh[NE],0xF1,0xE0,0xE0);

View File

@ -7,11 +7,11 @@
class BatimentQuadMaisonPont: public Chose { class BatimentQuadMaisonPont: public Chose {
private : private :
Quad c; Quad c;
int height; float height;
public : public :
BatimentQuadMaisonPont(Quad c, int height); BatimentQuadMaisonPont(Quad c, float height);
virtual bool split(); virtual bool split();
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
BatimentQuadMur::BatimentQuadMur(Quad c, int height) : Chose(), c(c), height(height) { BatimentQuadMur::BatimentQuadMur(Quad c, float height) : Chose(), c(c), height(height) {
addEntropy(c); addEntropy(c);
} }

View File

@ -6,11 +6,11 @@
class BatimentQuadMur: public Chose { class BatimentQuadMur: public Chose {
private : private :
Quad c; Quad c;
int height; float height;
public : public :
BatimentQuadMur(Quad c, int height); BatimentQuadMur(Quad c, float height);
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();
}; };

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
BatimentQuadPont::BatimentQuadPont(Quad c, int height) : Chose(), c(c), height(height) { BatimentQuadPont::BatimentQuadPont(Quad c, float height) : Chose(), c(c), height(height) {
addEntropy(c); addEntropy(c);
} }
@ -10,11 +10,11 @@ void BatimentQuadPont::getBoundingBoxPoints() {
} }
float ct(float x) { float ct(float x) {
return -(1.*cosh(x/1.))+1; return (float)(1 - cosh(x / 1.f));
} }
float nt(double x, int height) { float nt(float x, float height) {
return (ct(x) + -ct(-1.7))/(ct(0)+ -ct(-1.7)) * height; return (ct(x) + -ct(-1.7f))/(ct(0)+ -ct(-1.7f)) * height;
} }
void BatimentQuadPont::triangulation() { void BatimentQuadPont::triangulation() {
@ -29,9 +29,9 @@ void BatimentQuadPont::triangulation() {
Vertex l1 = c[NE] - c[NW]; Vertex l1 = c[NE] - c[NW];
Vertex l2 = c[SW] - c[SE]; Vertex l2 = c[SW] - c[SE];
float pas = 0.1; float pas = 0.1f;
int steps = (3.14/pas); int steps = (int)(Angle::Pi / pas);
float n2 = l2.norm()/(3.14/pas); float n2 = l2.norm()/(Angle::Pi / pas);
n2=n2; n2=n2;
int middle = steps/2; int middle = steps/2;
int n; int n;
@ -39,7 +39,7 @@ void BatimentQuadPont::triangulation() {
addGPUTriangle(c[SW],pb,ch[SW],0xD0,0xD0,0xD0); addGPUTriangle(c[SW],pb,ch[SW],0xD0,0xD0,0xD0);
addGPUTriangle(pa,c[NW],ch[NW],0xD0,0xD0,0xD0); addGPUTriangle(pa,c[NW],ch[NW],0xD0,0xD0,0xD0);
for(var=-1.7,n=0; var <= 1.7; var+=pas,n++) { for(var=-1.7f, n=0; var <= 1.7f; var+=pas, n++) {
q = q.inset(W,n2); q = q.inset(W,n2);
a = q[NW] + Vertex(0,0,nt(var,height)); a = q[NW] + Vertex(0,0,nt(var,height));
b = q[SW] + Vertex(0,0,nt(var,height)); b = q[SW] + Vertex(0,0,nt(var,height));

View File

@ -7,10 +7,10 @@
class BatimentQuadPont: public Chose { class BatimentQuadPont: public Chose {
private : private :
Quad c; Quad c;
int height; float height;
public : public :
BatimentQuadPont(Quad c, int height); BatimentQuadPont(Quad c, float height);
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();
}; };

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
BatimentQuadToit::BatimentQuadToit(Quad c, int height) : Chose(), c(c), height(height) { BatimentQuadToit::BatimentQuadToit(Quad c, float height) : Chose(), c(c), height(height) {
addEntropy(c); addEntropy(c);
} }
@ -10,8 +10,8 @@ void BatimentQuadToit::getBoundingBoxPoints() {
} }
void BatimentQuadToit::triangulation() { void BatimentQuadToit::triangulation() {
Vertex ce = c[SE] + (c[NE] - c[SE])/2 + Vertex(0,0,height/3.); Vertex ce = c[SE] + (c[NE] - c[SE])/2 + Vertex(0,0,height / 3.f);
Vertex cw = c[SW] + (c[NW] - c[SW])/2 + Vertex(0,0,height/3.); Vertex cw = c[SW] + (c[NW] - c[SW])/2 + Vertex(0,0,height / 3.f);
addGPUTriangle(c[NW],cw,c[SW],0xF1,0xE0,0xE0); addGPUTriangle(c[NW],cw,c[SW],0xF1,0xE0,0xE0);
addGPUTriangle(c[SE],ce,c[NE],0xF1,0xE0,0xE0); addGPUTriangle(c[SE],ce,c[NE],0xF1,0xE0,0xE0);

View File

@ -7,11 +7,11 @@
class BatimentQuadToit: public Chose { class BatimentQuadToit: public Chose {
private : private :
Quad c; Quad c;
int height; float height;
public : public :
BatimentQuadToit(Quad c, int height); BatimentQuadToit(Quad c, float height);
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();
}; };

View File

@ -39,11 +39,10 @@ bool BatimentTri::split() {
} }
void BatimentTri::triangulation() { void BatimentTri::triangulation() {
int h = hashInRange(seed,1,minHeight,maxHeight); float h = floatInRange(seed,1,minHeight,maxHeight);
// int htoit = hashInRange(seed,2,minHeight/2,maxHeight/2); // float htoit = hashInRange(seed,2,minHeight/2,maxHeight/2);
// h += htoit;
// addGPUOcto(c, c + Vertex(0,0,h), 0xFF, 0xFF, 0x00); // addGPUOcto(c, c + Vertex(0,0,h + htoit), 0xFF, 0xFF, 0x00);
Triangle ch = c + Vertex(0,0,h); Triangle ch = c + Vertex(0,0,h);
addGPUTriangle(c[LEFT], c[TOP], c[RIGHT], 0xFF, 0xFF, 0x00); addGPUTriangle(c[LEFT], c[TOP], c[RIGHT], 0xFF, 0xFF, 0x00);
addGPUTriangle(ch[LEFT], ch[TOP], ch[RIGHT], 0xFF, 0xFF, 0x00); addGPUTriangle(ch[LEFT], ch[TOP], ch[RIGHT], 0xFF, 0xFF, 0x00);

View File

@ -20,29 +20,29 @@ bool Chose::merge() {
return true; return true;
} }
void Chose::addGPUTriangle(Vertex left, Vertex top, Vertex right, char r, char g, char b) { void Chose::addGPUTriangle(Vertex left, Vertex top, Vertex right, unsigned char r, unsigned char g, unsigned char b) {
triangles.push_back(new GPUTriangle(left, top, right, r, g, b)); triangles.push_back(new GPUTriangle(left, top, right, r, g, b));
} }
void Chose::addGPUTriangle(Triangle t, char r, char g, char b) { void Chose::addGPUTriangle(Triangle t, unsigned char r, unsigned char g, unsigned char b) {
addGPUTriangle(t[LEFT], t[TOP], t[RIGHT], r, g, b); addGPUTriangle(t[LEFT], t[TOP], t[RIGHT], r, g, b);
} }
void Chose::addGPUQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, char r, char g, char b) { void Chose::addGPUQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, unsigned char r, unsigned char g, unsigned char b) {
this->addGPUTriangle(nw,ne,se,r,g,b); this->addGPUTriangle(nw,ne,se,r,g,b);
this->addGPUTriangle(se,sw,nw,r,g,b); this->addGPUTriangle(se,sw,nw,r,g,b);
} }
void Chose::addGPUQuad(Quad q, char r, char g, char b) { void Chose::addGPUQuad(Quad q, unsigned char r, unsigned char g, unsigned char b) {
addGPUQuad(q[NE], q[SE], q[SW], q[NW], r, g, b); addGPUQuad(q[NE], q[SE], q[SW], q[NW], r, g, b);
} }
void Chose::addGPUOcto(Vertex ne, Vertex se, Vertex sw, Vertex nw, void Chose::addGPUOcto(Vertex ne, Vertex se, Vertex sw, Vertex nw,
Vertex neh, Vertex seh, Vertex swh, Vertex nwh, char r, char g, char b) { Vertex neh, Vertex seh, Vertex swh, Vertex nwh, unsigned char r, unsigned char g, unsigned char b) {
addGPUOcto(Quad(ne,se,sw,nw), Quad(neh,seh,swh,nwh), r, g, b); addGPUOcto(Quad(ne,se,sw,nw), Quad(neh,seh,swh,nwh), r, g, b);
} }
void Chose::addGPUOcto(Quad q, Quad qh, char r, char g, char b) { void Chose::addGPUOcto(Quad q, Quad qh, unsigned char r, unsigned char g, unsigned char b) {
this->addGPUQuad(q[NE], q[SE], q[SW], q[NW], r, g, b); this->addGPUQuad(q[NE], q[SE], q[SW], q[NW], r, g, b);
this->addGPUQuad(qh[NE], qh[SE], qh[SW], qh[NW], r, g, b); this->addGPUQuad(qh[NE], qh[SE], qh[SW], qh[NW], r, g, b);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -139,9 +139,9 @@ void Chose::drawAABB() {
Vertex(lod.splitBox[1], lod.splitBox[2], lod.splitBox[5]), Vertex(lod.splitBox[1], lod.splitBox[2], lod.splitBox[5]),
Vertex(lod.splitBox[1], lod.splitBox[3], lod.splitBox[5]), Vertex(lod.splitBox[1], lod.splitBox[3], lod.splitBox[5]),
Vertex(lod.splitBox[0], lod.splitBox[3], lod.splitBox[5]), Vertex(lod.splitBox[0], lod.splitBox[3], lod.splitBox[5]),
hashInRange(seed, 42, 0, 256), hash2(seed, 42) & 255,
hashInRange(seed, 43, 0, 256), hash2(seed, 43) & 255,
hashInRange(seed, 44, 0, 256) hash2(seed, 44) & 255
); );
} }

View File

@ -41,7 +41,7 @@ class Chose {
addEntropy(x1, x2); addEntropy(x3, x4); addEntropy(x1, x2); addEntropy(x3, x4);
} }
inline void addEntropy(Vertex v1) { inline void addEntropy(Vertex v1) {
addEntropy(v1.x, v1.y); addEntropy(float2uint(v1.x), float2uint(v1.y));
} }
inline void addEntropy(Vertex v1, Vertex v2) { inline void addEntropy(Vertex v1, Vertex v2) {
addEntropy(v1); addEntropy(v2); addEntropy(v1); addEntropy(v2);
@ -59,13 +59,15 @@ class Chose {
addEntropy(t[LEFT], t[TOP], t[RIGHT]); addEntropy(t[LEFT], t[TOP], t[RIGHT]);
} }
void addChild(Chose* c); void addChild(Chose* c);
void addGPUTriangle(GPUTriangle* t);
void addGPUTriangle(Vertex left, Vertex top, Vertex right, char r, char g, char b); void addGPUTriangle(Vertex left, Vertex top, Vertex right, unsigned char r, unsigned char g, unsigned char b);
void addGPUTriangle(Triangle t, char r, char g, char b); void addGPUTriangle(Triangle t, unsigned char r, unsigned char g, unsigned char b);
void addGPUQuad(Vertex u, Vertex v, Vertex w, Vertex x, char r, char g, char b); void addGPUQuad(Vertex ne, Vertex se, Vertex sw, Vertex nw, unsigned char r, unsigned char g, unsigned char b);
void addGPUQuad(Quad q, char r, char g, char b); void addGPUQuad(Quad q, unsigned char r, unsigned char g, unsigned char b);
void addGPUOcto(Vertex a,Vertex b,Vertex c,Vertex d,Vertex e,Vertex f,Vertex g,Vertex h,char red,char green,char blue); void addGPUOcto(Vertex ne, Vertex se, Vertex sw, Vertex nw,
void addGPUOcto(Quad q1, Quad q2, char red, char green, char blue); Vertex neh, Vertex seh, Vertex swh, Vertex nwh,
unsigned char r, unsigned char g, unsigned char b);
void addGPUOcto(Quad q, Quad qh, unsigned char r, unsigned char g, unsigned char b);
}; };
#endif #endif

View File

@ -21,8 +21,8 @@ bool QuartierQuadAngle::split() {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (Triangle(c[NW+i], c[NE+i], c[SE+i]).angle() <= Angle::d2r(50)) { if (Triangle(c[NW+i], c[NE+i], c[SE+i]).angle() <= Angle::d2r(50)) {
// "couper ce coin". // "couper ce coin".
Vertex n = Segment(c[NW+i], c[NE+i]).randomPos(seed, 0, 40, 60); Vertex n = Segment(c[NW+i], c[NE+i]).randomPos(seed, 0, 0.4f, 0.6f);
Vertex e = Segment(c[NE+i], c[SE+i]).randomPos(seed, 1, 40, 60); Vertex e = Segment(c[NE+i], c[SE+i]).randomPos(seed, 1, 0.4f, 0.6f);
Triangle tn = Triangle(n, c[NE+i], c[SE+i]); Triangle tn = Triangle(n, c[NE+i], c[SE+i]);
Triangle te = Triangle(c[NW+i], c[NE+i], e); Triangle te = Triangle(c[NW+i], c[NE+i], e);
Quad q; Quad q;

View File

@ -7,12 +7,12 @@ bool QuartierQuadCarre::split() {
Vertex middle[4]; Vertex middle[4];
Quad q[4]; Quad q[4];
Vertex centerN = Segment(c[NW], c[NE]).randomPos(seed, -1, 25, 75); Vertex centerN = Segment(c[NW], c[NE]).randomPos(seed, -1, 0.25, 0.75);
Vertex centerS = Segment(c[SE], c[SW]).randomPos(seed, -2, 25, 75); Vertex centerS = Segment(c[SE], c[SW]).randomPos(seed, -2, 0.25, 0.75);
Vertex center = Segment(centerN, centerS).randomPos(seed, -3, 25, 75); Vertex center = Segment(centerN, centerS).randomPos(seed, -3, 0.25, 0.75);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
middle[N+i] = Segment(c[NW+i], c[NE+i]).randomPos(seed, i, 25, 75); middle[N+i] = Segment(c[NW+i], c[NE+i]).randomPos(seed, i, 0.25, 0.75);
} }
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
q[i] = Quad(c[NE+i], middle[E+i], center, middle[N+i]); q[i] = Quad(c[NE+i], middle[E+i], center, middle[N+i]);

View File

@ -4,8 +4,8 @@ QuartierQuadRect::QuartierQuadRect(Quad c) : QuartierQuad(c) {
} }
bool QuartierQuadRect::split() { bool QuartierQuadRect::split() {
Vertex n = Segment(c[NW], c[NE]).randomPos(seed, 0, 33, 67); Vertex n = Segment(c[NW], c[NE]).randomPos(seed, 0, 1/3.f, 2/3.f);
Vertex s = Segment(c[SE], c[SW]).randomPos(seed, 1, 33, 67); Vertex s = Segment(c[SE], c[SW]).randomPos(seed, 1, 1/3.f, 2/3.f);
Quad qe = Quad(c[NE], c[SE], s, n).inset(W,hrw); Quad qe = Quad(c[NE], c[SE], s, n).inset(W,hrw);
Quad qw = Quad(c[SW], c[NW], n, s).inset(W,hrw); Quad qw = Quad(c[SW], c[NW], n, s).inset(W,hrw);

View File

@ -15,7 +15,7 @@ Chose* QuartierTri::factory(int seed, int n, Triangle c) {
if (small && !big) { if (small && !big) {
return new BatimentTri(c); return new BatimentTri(c);
} else if (big) { } else if (big) {
int choice = hashInRange(seed, n, 0, 3); int choice = hash2(seed, n) % 3;
if (choice == 0) { if (choice == 0) {
// TODO : condition : générer seulement si les 3 angles sont proches de 60° // TODO : condition : générer seulement si les 3 angles sont proches de 60°
return new QuartierTriCentre(c); return new QuartierTriCentre(c);

View File

@ -8,7 +8,7 @@ bool QuartierTriCentre::split() {
Vertex center = c.insetLTR(1000).randomPoint(seed, 0); Vertex center = c.insetLTR(1000).randomPoint(seed, 0);
Vertex edgePoint[3]; Vertex edgePoint[3];
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
edgePoint[LEFTSIDE+i] = Segment(c[LEFT+i], c[TOP+i]).randomPos(seed, i+1, 33, 67); edgePoint[LEFTSIDE+i] = Segment(c[LEFT+i], c[TOP+i]).randomPos(seed, i+1, 1/3.f, 2/3.f);
Quad q[3]; Quad q[3];
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {

View File

@ -10,7 +10,7 @@ bool QuartierTriHauteur::split() {
// addChild(new RouteTriChaussee(r.cutFrom)); // addChild(new RouteTriChaussee(r.cutFrom));
// addChild(QuartierTri::factory(seed, 1, r.left); // addChild(QuartierTri::factory(seed, 1, r.left);
// addChild(QuartierTri::factory(seed, 1, r.right); // addChild(QuartierTri::factory(seed, 1, r.right);
Vertex baseCenter = Segment(c[LEFT], c[RIGHT]).randomPos(seed, 0, 33, 67); Vertex baseCenter = Segment(c[LEFT], c[RIGHT]).randomPos(seed, 0, 1/3.f, 2/3.f);
Triangle tl(c[TOP], baseCenter, c[LEFT]); Triangle tl(c[TOP], baseCenter, c[LEFT]);
Triangle tr(c[RIGHT], baseCenter, c[TOP]); Triangle tr(c[RIGHT], baseCenter, c[TOP]);

View File

@ -5,8 +5,8 @@ QuartierTriTrapeze::QuartierTriTrapeze(Triangle c) : QuartierTri(c) {
bool QuartierTriTrapeze::split() { bool QuartierTriTrapeze::split() {
// TODO : sélectionner le sommet avec l'angle le plus petit. // TODO : sélectionner le sommet avec l'angle le plus petit.
Vertex left = Segment(c[LEFT], c[TOP]).randomPos(seed, 0, 33, 67); Vertex left = Segment(c[LEFT], c[TOP]).randomPos(seed, 0, 1/3.f, 2/3.f);
Vertex right = Segment(c[RIGHT], c[TOP]).randomPos(seed, 0, 33, 67); Vertex right = Segment(c[RIGHT], c[TOP]).randomPos(seed, 0, 1/3.f, 2/3.f);
Triangle ttop(left, c[TOP], right); Triangle ttop(left, c[TOP], right);
Quad trapeze(right, c[RIGHT], c[LEFT], left); Quad trapeze(right, c[RIGHT], c[LEFT], left);

View File

@ -1,6 +1,6 @@
#include "all_includes.hh" #include "all_includes.hh"
TrottoirQuadNormal::TrottoirQuadNormal(Quad c, int height) : Chose(), c(c), height(height) { TrottoirQuadNormal::TrottoirQuadNormal(Quad c, float height) : Chose(), c(c), height(height) {
} }
void TrottoirQuadNormal::getBoundingBoxPoints() { void TrottoirQuadNormal::getBoundingBoxPoints() {

View File

@ -6,13 +6,13 @@
class TrottoirQuadNormal : public Chose { class TrottoirQuadNormal : public Chose {
private : private :
Quad c; Quad c;
int height; float height;
// TODO : pas besoin de ce champ : il suffit d'orienter // TODO : pas besoin de ce champ : il suffit d'orienter
// correctement le trottoir lorsqu'on le crée. // correctement le trottoir lorsqu'on le crée.
Cardinal border; Cardinal border;
public : public :
TrottoirQuadNormal(Quad c, int height); TrottoirQuadNormal(Quad c, float height);
virtual void triangulation(); virtual void triangulation();
virtual void getBoundingBoxPoints(); virtual void getBoundingBoxPoints();
}; };

View File

@ -2,16 +2,16 @@
View::View(Chose* root) View::View(Chose* root)
: root(root), : root(root),
camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6)), camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6f)),
lod(camera.cameraCenter, root) { lod(camera.cameraCenter, root) {
initWindow(); initWindow();
mainLoop(); mainLoop();
} }
void View::setColor(unsigned char r, unsigned char g, unsigned char b) { void View::setColor(unsigned char r, unsigned char g, unsigned char b) {
float red = r/255.f; float red = (float)r / 255.f;
float green = g/255.f; float green = (float)g / 255.f;
float blue = b/255.f; float blue = (float)b / 255.f;
float MatDif[4] = {red, green, blue, 1.0f}; float MatDif[4] = {red, green, blue, 1.0f};
float MatAmb[4] = {red, green, blue, 1.0f}; float MatAmb[4] = {red, green, blue, 1.0f};
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MatDif); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MatDif);
@ -168,8 +168,8 @@ void Camera::setCamera() {
} }
void Camera::mouseMotion(const SDL_MouseMotionEvent &event) { void Camera::mouseMotion(const SDL_MouseMotionEvent &event) {
xAngle -= event.xrel*mouseSensitivity; xAngle -= (float)(event.xrel) * mouseSensitivity;
yAngle += event.yrel*mouseSensitivity; yAngle += (float)(event.yrel) * mouseSensitivity;
xAngle = std::fmod(xAngle + 360, 360); xAngle = std::fmod(xAngle + 360, 360);
if(yAngle > 179) if(yAngle > 179)
yAngle = 179; yAngle = 179;
@ -225,7 +225,7 @@ 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.f)*(float)moveDist;
if(up) if(up)
cameraCenter = cameraCenter + Vertex::fromSpherical(diff, yAngle, xAngle); cameraCenter = cameraCenter + Vertex::fromSpherical(diff, yAngle, xAngle);