www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

arche.cpp (1893B)


      1 #include "all_includes.hh"
      2 
      3 ArcheQuad::ArcheQuad(Quad _c, float _height, float _start, float _end, Type _type) : Chose(), c(_c), height(_height), start(_start), end(_end), type(_type) {
      4 	if (type == RANDOM) {
      5 		addEntropy(c);
      6 		addEntropyf(height);
      7 		switch (hash2(seed, 0) % 3) {
      8 		case 0: type = OGIVE; break;
      9 		case 1: type = BERCEAU; break;
     10 		case 2:
     11 		default: type = PLAT; break;
     12 		}
     13 	}
     14 }
     15 
     16 void ArcheQuad::split() {
     17 	if (type == PLAT)
     18 		return;
     19 	if (std::abs(end - start) < 0.1 && std::abs(f(end) - f(start)) < 0.05)
     20 		return;
     21 	float mid = (start + end) / 2;
     22 	Vertex n = (c[NW] + c[NE]) / 2.f;
     23 	Vertex s = (c[SE] + c[SW]) / 2.f;
     24 	addChild(new ArcheQuad(Quad(n, s, c[SW], c[NW]), height, start, mid, type));
     25 	addChild(new ArcheQuad(Quad(c[NE], c[SE], s, n), height, mid, end, type));
     26 }
     27 
     28 void ArcheQuad::triangulation() {
     29 	if (type == PLAT) {
     30 		Quad chh = c.offsetNormal(height);
     31 		Quad ch = c.offsetNormal(height * 0.9);
     32 		addGPUQuad(ch, Couleurs::mur);
     33 		addGPUQuad(Quad(chh[NW], ch[NW], ch[NE], chh[NE]), Couleurs::mur);
     34 		addGPUQuad(Quad(chh[SE], ch[SE], ch[SW], chh[SW]), Couleurs::mur);
     35 		addGPUQuad(Quad(ch[NW], c[NW], c[SW], ch[SW]), Couleurs::mur);
     36 		addGPUQuad(Quad(ch[SE], c[SE], c[NE], ch[NE]), Couleurs::mur);
     37 	} else {
     38 		Quad ch = c.offsetNormal(height);
     39 		Quad che = c.offsetNormal(f(end) * height * 0.9f);
     40 		Quad chw = c.offsetNormal(f(start) * height * 0.9f);
     41 		addGPUQuad(Quad(ch[NW], chw[NW], che[NE], ch[NE]), Couleurs::mur);
     42 		addGPUQuad(Quad(ch[SE], che[SE], chw[SW], ch[SW]), Couleurs::mur);
     43 		addGPUQuad(Quad(che[SE], che[NE], chw[NW], chw[SW]), Couleurs::mur);
     44 	}
     45 }
     46 
     47 void ArcheQuad::getBoundingBoxPoints() {
     48 	addBBPoints(c, height);
     49 }
     50 
     51 float ArcheQuad::f(float x) {
     52 	switch(type){
     53 	case OGIVE: return std::sin(std::acos(std::abs(x - 0.5f) + 0.5f)) / std::sin(std::acos(0.5f));
     54 	case BERCEAU: return std::sin(std::acos(2*x-1));
     55 	case PLAT:
     56 	default: return 1;
     57 	}
     58 }