From 2487eaa64c5535d7e4f14423e80ceed441f13b5c Mon Sep 17 00:00:00 2001 From: Yoann Date: Tue, 20 Dec 2011 15:38:09 +0100 Subject: [PATCH] Classe de ponts pour les batiments mais exeption sur des flottants. --- rules/batiment/batimentquadpont.cpp | 90 +++++++++++++++++++++++++++++ rules/batiment/batimentquadpont.hh | 27 +++++++++ 2 files changed, 117 insertions(+) create mode 100644 rules/batiment/batimentquadpont.cpp create mode 100644 rules/batiment/batimentquadpont.hh diff --git a/rules/batiment/batimentquadpont.cpp b/rules/batiment/batimentquadpont.cpp new file mode 100644 index 0000000..ebcfbe7 --- /dev/null +++ b/rules/batiment/batimentquadpont.cpp @@ -0,0 +1,90 @@ +#include "all_includes.hh" + +BatimentQuadPont::BatimentQuadPont() { +} + +BatimentQuadPont::BatimentQuadPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height) : Chose() { + 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; + this->height = height; + triangulation(); +} + +BatimentQuadPont::~BatimentQuadPont() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); +} + +std::vector BatimentQuadPont::getBoundingBoxPoints() const { + std::vector list; + return list; +} + +bool BatimentQuadPont::split() { + + return true; +} + +bool BatimentQuadPont::merge() { + for(unsigned int i = 0; i < children.size(); i++) + delete(children[i]); + children.clear(); + triangles.clear(); + return true; +} + +float ct(float x) { + return -(1.*cosh(x/1.))+1; +} + +float nt(double x, int height) { + return (ct(x) + -ct(-M_PI/2.))/(ct(0)+ -ct(-M_PI/2.)) * height; +} + +void BatimentQuadPont::triangulation() { + //triangles.reserve(2); + float var; + Quad q = Quad(ne,se,sw,nw); + Vertex a,b; + Vertex pa = nw; + Vertex pb = sw; + Vertex neh = ne + Vertex(0,0,height+100); + Vertex seh = se + Vertex(0,0,height+100); + Vertex swh = sw + Vertex(0,0,height+100); + Vertex nwh = nw + Vertex(0,0,height+100); + Vertex l1 = ne - nw; + Vertex l2 = sw - se; + float pas = (M_PI / 60); + float n1 = l1.norm()/pas; + float n2 = l2.norm()/pas; + n1=n1; + + std::cout << std::endl << std::endl; + + for(var=-M_PI/2; var <= M_PI/2; var+=pas) { + if(var == 0) continue; + std::cout << var << " \t " << nt(var,height) << std::endl; + q.offset(W,-n2); + a = q.corner[3] + Vertex(0,0,nt(var,height)); + b = q.corner[2] + Vertex(0,0,nt(var,height)); + + addQuad(a,b,pb,pa,0xFF,0xFF,0xFF); + if( var < 0) { + addTriangle(new Triangle(pa,a,nwh,0xFF,0xFF,0xFF)); + addTriangle(new Triangle(pb,b,swh,0xFF,0xFF,0xFF)); + } + else { + addTriangle(new Triangle(pa,a,neh,0xFF,0xFF,0xFF)); + addTriangle(new Triangle(pb,b,seh,0xFF,0xFF,0xFF)); + } + + pa = a; + pb = b; + } +} diff --git a/rules/batiment/batimentquadpont.hh b/rules/batiment/batimentquadpont.hh new file mode 100644 index 0000000..395de7c --- /dev/null +++ b/rules/batiment/batimentquadpont.hh @@ -0,0 +1,27 @@ +#ifndef _RULES_BATIMENTPONT_HH_ +#define _RULES_BATIMENTPONT_HH_ + +#include "all_includes.hh" + +// RectangleRoutes est un quadrilatère de routes avec des angles aux coins égaux à 90°. +class BatimentQuadPont: public Chose { + private : + Vertex ne; + Vertex se; + Vertex sw; + Vertex nw; + int height; + + public : + + BatimentQuadPont(); + BatimentQuadPont(Vertex ne, Vertex se, Vertex sw, Vertex nw, int height); + virtual ~BatimentQuadPont(); + virtual bool split(); + virtual bool merge(); + virtual void triangulation(); + Chose* factory(int seed, int n, Vertex ne, Vertex se, Vertex sw, Vertex nw); + virtual std::vector getBoundingBoxPoints() const; +}; + +#endif