Mesh PaterneQuad::remplissageCoin(const int& indicePointCoin, Vector2D& point1Batiment, Vector2D& pointCentre, Vector2D& point3Batiment) { /* point1 X----X point2 | | | | point0 X----X point3 */ Quadrangle centreTmp = *this; // Taille aléatoire float aleatoire = (rand()%100) / 100.0; centreTmp.shrink( _par->minLargeurBatiment + aleatoire*(coeffShrinkMax()-_par->minLargeurBatiment-_par->largeurRuelle) ); // pointCentre = centreTmp[indicePointCoin]; Vector2D shrink = pointCentre - get(indicePointCoin); Vector2D pIpIm1 = get((indicePointCoin-1)%4) - get(indicePointCoin); Vector2D pIpIp1 = get((indicePointCoin+1)%4) - get(indicePointCoin); pIpIm1.normalise(); pIpIp1.normalise(); // disposition des points en losange float dpIpIm1 = shrink.scalareProduct(pIpIm1); dpIpIm1 = shrink.getNorm()*shrink.getNorm() / (dpIpIm1*2); if(dpIpIm1 >= (get((indicePointCoin-1)%4) - get(indicePointCoin)).getNorm()/2) dpIpIm1 = (get((indicePointCoin-1)%4) - get(indicePointCoin)).getNorm()/2 - _par->largeurRuelle/2; float dpIpIp1 = shrink.scalareProduct(pIpIp1); dpIpIp1 = shrink.getNorm()*shrink.getNorm() / (dpIpIp1*2); if(dpIpIp1 >= (get((indicePointCoin+1)%4) - get(indicePointCoin)).getNorm()/2) dpIpIp1 = (get((indicePointCoin+1)%4) - get(indicePointCoin)).getNorm()/2 - _par->largeurRuelle/2; point1Batiment = get(indicePointCoin) + pIpIp1*dpIpIp1; point3Batiment = get(indicePointCoin) + pIpIm1*dpIpIm1; Batiment b = Batiment(Vector3D(get(indicePointCoin).x, get(indicePointCoin).y, 0), Vector3D(point1Batiment.x, point1Batiment.y, 0), Vector3D(pointCentre.x, pointCentre.y, 0), Vector3D(point3Batiment.x, point3Batiment.y, 0), _par); return b.generate(); }
void PaterneQuad::faireTrotoir(Mesh& m){ Quadrangle centre = *this, notreQuadrangle = *this; centre.shrink(_par->largeurTrotoir); for(int i=0; i<4; i++){ m.addTriangle( Vector3D(notreQuadrangle[i].x, notreQuadrangle[i].y, 0), Vector3D(notreQuadrangle[(i-1)%4].x, notreQuadrangle[(i-1)%4].y, 0), Vector3D(centre[i].x, centre[i].y, 0) ); m.addTriangle( Vector3D(centre[i].x, centre[i].y, 0), Vector3D(notreQuadrangle[(i-1)%4].x, notreQuadrangle[(i-1)%4].y, 0), Vector3D(centre[(i-1)%4].x, centre[(i-1)%4].y, 0) ); } this->shrink(_par->largeurTrotoir); }
Batiment::Batiment(const Quadrangle& q, const unsigned int& typeCentre, const double& hauteurMax) { listePoints.push_back(q[0]); listePoints.push_back(q[1]); listePoints.push_back(q[2]); listePoints.push_back(q[3]); airMin = q.Area()*0.3; setBatimentInfos(typeCentre, hauteurMax); }
BaseBuilding::BaseBuilding(const Quadrangle& q, const unsigned int& typeCentre, const double& heightMax) { seed = rand(); listPoints.push_back(q[0]); listPoints.push_back(q[1]); listPoints.push_back(q[2]); listPoints.push_back(q[3]); airMin = q.Area()*0.3; setBuildingInfo(typeCentre, heightMax); }
Quadrangle * addQIntoL( char * p1, char * p2, char * p3, char * p4, char * style ){ Quadrangle * q; if( ( q = findQInL( p1, p2, p3, p4 ) ) == 0 ){ Point * v1 = addPIntoL( p1 ); Point * v2 = addPIntoL( p2 ); Point * v3 = addPIntoL( p3 ); Point * v4 = addPIntoL( p4 ); q = new Quadrangle( v1, v2, v3, v4 ); objList->add( q ); } if( strcmp( style, "四边形" ) == 0 ) q->setTypeR( Quadrangle::QUAD ); else if( strcmp( style, "矩形" ) == 0 ) q->setTypeR( Quadrangle::RECT ); else if( strcmp( style, "正方形" ) == 0 ) q->setTypeR( Quadrangle::SQUA ); else if( strcmp( style, "平行四边形" ) == 0 ) q->setTypeR( Quadrangle::PARA ); else q->setTypeR( Quadrangle::QUAD ); return q; }
GraphicElements::QuadrangularPrism::QuadrangularPrism(glm::vec3 pos, glm::vec3 col, glm::vec3 rot, float scale, glm::vec3 topFaceTrans, float h, Quadrangle * face) : Figure(pos, col, rot, scale), _facePointer(face), _topFaceTranslation(topFaceTrans), _height(h) { Quadrangle * top = new Quadrangle(glm::vec3(topFaceTrans.x, h / 2 + topFaceTrans.y, topFaceTrans.z), col, glm::vec3(PI / 2, 0, 0), face); Quadrangle * bottom = new Quadrangle(glm::vec3(topFaceTrans.x, -h / 2 + topFaceTrans.y, topFaceTrans.z), col, glm::vec3(PI / 2, 0, 0), face); top->setNormal(glm::vec3(0, 0, -1)); bottom->setNormal(glm::vec3(0, 0, -1)); addFace(top); addFace(bottom); addFace(new Quadrangle(glm::vec3(0, 0, 0), col, glm::vec3(0, 0, 0), top->points()[0], bottom->points()[0], top->points()[2], bottom->points()[2])); addFace(new Quadrangle(glm::vec3(0, 0, 0), col, glm::vec3(0, 0, 0), top->points()[2], bottom->points()[2], top->points()[3], bottom->points()[3])); addFace(new Quadrangle(glm::vec3(0, 0, 0), col, glm::vec3(0, 0, 0), top->points()[3], bottom->points()[3], top->points()[1], bottom->points()[1])); addFace(new Quadrangle(glm::vec3(0, 0, 0), col, glm::vec3(0, 0, 0), top->points()[1], bottom->points()[1], top->points()[0], bottom->points()[0])); }
Mesh PaterneQuad::paternTroisBatiment(){ Mesh retour; Quadrangle centre = *this, notreQuadrangle = *this; /************ Batiment Principal ********************/ Vector2D p0p3 = notreQuadrangle[3] - notreQuadrangle[0]; Vector2D p1p2 = notreQuadrangle[2] - notreQuadrangle[1]; Vector2D p2p1 = notreQuadrangle[1] - notreQuadrangle[2]; Vector2D p2p3 = notreQuadrangle[3] - notreQuadrangle[2]; Vector2D p3p2 = notreQuadrangle[2] - notreQuadrangle[3]; Vector2D p3p0 = notreQuadrangle[0] - notreQuadrangle[3]; p0p3.normalise(); p1p2.normalise(); p2p1.normalise(); p2p3.normalise(); p3p2.normalise(); p3p0.normalise(); // Taille aléatoire float aleatoire = (rand()%100) / 100.0; centre.shrink( (1-aleatoire)*_par->minLargeurBatiment + aleatoire*(coeffShrinkMax()-_par->largeurRuelle) ); // float dp0p3 = (centre[0]-notreQuadrangle[0]).scalareProduct(p0p3); dp0p3 = (centre[0]-notreQuadrangle[0]).getNorm()*(centre[0]-notreQuadrangle[0]).getNorm() / (dp0p3*2); if(dp0p3 >= (notreQuadrangle[3]-notreQuadrangle[0]).getNorm()/2) dp0p3 = (notreQuadrangle[3]-notreQuadrangle[0]).getNorm()/2 - _par->largeurRuelle/2; float dp1p2 = (centre[1]-notreQuadrangle[1]).scalareProduct(p1p2); dp1p2 = (centre[1]-notreQuadrangle[1]).getNorm()*(centre[1]-notreQuadrangle[1]).getNorm() / (dp1p2*2); if(dp1p2 >= (notreQuadrangle[2]-notreQuadrangle[1]).getNorm()/2) dp1p2 = (notreQuadrangle[2]-notreQuadrangle[1]).getNorm()/2 - _par->largeurRuelle/2; Vector2D p3B1 = notreQuadrangle[1] + p1p2*dp1p2; Vector2D p4B1 = notreQuadrangle[0] + p0p3*dp0p3; Batiment b = Batiment( Vector3D(notreQuadrangle[0].x, notreQuadrangle[0].y, 0), Vector3D(notreQuadrangle[1].x, notreQuadrangle[1].y, 0), Vector3D(p3B1.x, p3B1.y, 0), Vector3D(p4B1.x, p4B1.y, 0), _par); retour.merge( b.generate() ); ////////////////////////////////////// Quadrangle batiments[2]; retour.merge(remplissageCoin(2, batiments[0][1], batiments[0][2], batiments[0][3])); retour.merge(remplissageCoin(3, batiments[1][1], batiments[1][2], batiments[1][3])); retour.merge(remplissageBord(p3B1, centre[1], batiments[0][2], batiments[0][3] )); retour.merge(remplissageBord(batiments[0][1], batiments[0][2], batiments[1][2], batiments[1][3] )); retour.merge(remplissageBord(batiments[1][1], batiments[1][2], centre[0], p4B1 )); return retour; }
Mesh PaterneQuad::paternDeuxBatimentDiagonale(){ Mesh retour; Quadrangle centre = *this, notreQuadrangle = *this; // Taille aléatoire float aleatoire = (rand()%100) / 100.0; float coeffShrink = (1-aleatoire)*_par->minLargeurBatiment + aleatoire*(coeffShrinkMax()/2-_par->largeurRuelle); // centre.shrink( coeffShrink ); Vector2D p1p0 = notreQuadrangle[0] - notreQuadrangle[1]; Vector2D p3p2 = notreQuadrangle[2] - notreQuadrangle[3]; p1p0.normalise(); p3p2.normalise(); float dp1p0 = (centre[1]-notreQuadrangle[1]).scalareProduct(p1p0); float dp3p2 = (centre[3]-notreQuadrangle[3]).scalareProduct(p3p2); Vector2D p2p1 = notreQuadrangle[1] - notreQuadrangle[2]; p2p1.normalise(); Vector2D p2B1 = notreQuadrangle[1] + p1p0*dp1p0; Vector2D centre2Bis = centre[2] + (p2p1*(_par->largeurRuelle/2)); Batiment b = Batiment( Vector3D(notreQuadrangle[0].x + (-p1p0.x*(_par->largeurRuelle/2)) , notreQuadrangle[0].y + (-p1p0.y*(_par->largeurRuelle/2)), 0), Vector3D(p2B1.x, p2B1.y, 0), Vector3D(p2B1.x+((centre2Bis-p2B1).normalised()*coeffShrink).x, p2B1.y+((centre2Bis-p2B1).normalised()*coeffShrink).y, 0), Vector3D(centre[0].x + (-p1p0.x*(_par->largeurRuelle/2)), centre[0].y + (-p1p0.y*(_par->largeurRuelle/2)), 0), _par); retour.merge( b.generate() ); b = Batiment(Vector3D(notreQuadrangle[1].x, notreQuadrangle[1].y, 0), Vector3D(notreQuadrangle[2].x + (p2p1.x*(_par->largeurRuelle/2)), notreQuadrangle[2].y + (p2p1.y*(_par->largeurRuelle/2)), 0), Vector3D(centre2Bis.x, centre2Bis.y, 0), Vector3D(p2B1.x, p2B1.y, 0), _par); retour.merge( b.generate() ); Vector2D p0p3 = notreQuadrangle[3] - notreQuadrangle[0]; p0p3.normalise(); Vector2D p2B3 = notreQuadrangle[3] + p3p2*dp3p2; Vector2D centre0Bis = centre[0] + (p0p3*(_par->largeurRuelle/2)); b = Batiment(Vector3D(notreQuadrangle[2].x + (-p3p2.x*(_par->largeurRuelle/2)), notreQuadrangle[2].y + (-p3p2.y*(_par->largeurRuelle/2)), 0), Vector3D(p2B3.x, p2B3.y, 0), Vector3D(p2B3.x+((centre0Bis-p2B3).normalised()*coeffShrink).x, p2B3.y+((centre0Bis-p2B3).normalised()*coeffShrink).y, 0), Vector3D(centre[2].x + (-p3p2.x*(_par->largeurRuelle/2)), centre[2].y + (-p3p2.y*(_par->largeurRuelle/2)), 0), _par); retour.merge( b.generate() ); b = Batiment(Vector3D(notreQuadrangle[3].x, notreQuadrangle[3].y, 0), Vector3D(notreQuadrangle[0].x + (p0p3*(_par->largeurRuelle/2)).x, notreQuadrangle[0].y + (p0p3*(_par->largeurRuelle/2)).y, 0), Vector3D(centre0Bis.x, centre0Bis.y, 0), Vector3D(p2B3.x, p2B3.y, 0), _par); retour.merge( b.generate() ); return retour; }
bool Quadrangle::overlap(Quadrangle q) { return isIn(q) || intersect(q) || q.isIn(*this) || q.intersect(*this); }