DiskHole::DiskHole(int nvertices, float radius, int ndisk) : TriMesh() { _name = "Disk Hole"; // using same algorithm as cone but with a constant Z //vertices for (int i=0;i<ndisk;++i) { float r = 1-(1-radius)*i/((float)ndisk-1); this->addVertex(0,0,0); for (float i=0; i<2*M_PI ; i+=(2/(float)nvertices)*M_PI) this->addVertex(r*cos(i),r*sin(i),0); } // triangles for(int i=0;i<ndisk-1;++i) { for (int j=1; j<nvertices+1; ++j) this->addTriangle(1+j%nvertices+i*(nvertices+1), j+i*(nvertices+1), j+1+nvertices+i*(nvertices+1)); for (int j=1; j<nvertices+1; ++j) this->addTriangle(j%nvertices+2+nvertices+i*(nvertices+1), j%nvertices+1+i*(nvertices+1), nvertices+j+1+i*(nvertices+1)); } computeNormalsT(); computeNormalsV(); }
my::DiskHole::DiskHole(const float & bigRadius, const float & smallRadius, const int & nbSlices, const int & nbCirc) :ParametricMesh("DiskHole", nbCirc+2, 2*nbSlices), _bigRadius(bigRadius), _smallRadius(smallRadius), _nbSlices(nbSlices), _nbCirc(nbCirc) { _preDiskHole(_bigRadius, _smallRadius, _nbSlices, _nbCirc); Circular coord(_bigRadius); parametricVertexInsertion(imax(), jmax(), coord); parametricTriangleInsertion(imax()-1, jmax()); computeNormalsT(); computeNormalsV(); }
my::Torus::Torus(const float & pathRadius, const float & tubeRadius, const int & nbSlices, const int & nbStacks) :ParametricMesh("Torus", 2*nbSlices, 2*(nbStacks+1)), _pathRadius(pathRadius), _tubeRadius(tubeRadius), _nbSlices(nbSlices), _nbStacks(nbStacks) { _preTorus(_pathRadius, _tubeRadius, _nbSlices, _nbStacks); my::Toric coord(_pathRadius, _tubeRadius); parametricVertexInsertion(imax(), jmax(), coord); parametricTriangleInsertion(imax(), jmax()); computeNormalsT(); computeNormalsV(); }
CubeCorner::CubeCorner() { _name = "CubeCorner"; // vertex coordinates //The corner is on the right up side static const GLfloat v[13][3] = { //bottom vertexes {-1,-1,1},{-1,-1,-1},{1,-1,1},{1,-1,-1}, //top vertexes {-1,1, 1},{-1,1,-1},{1,1,-1}, //corner vertexes {0,1,1},{1,1,0},{1,0,1}, //front center {0,0,1}, //right center {1,0,0}, //top center {0,1,0} }; // triangles vertex indices static const GLint t[19][3] = { {0,1,2},{3,2,1}, // bottom triangles {1,0,4},{4,5,1}, // cornerless left side triangles {1,5,3},{3,5,6}, // Back triangles {4,0,2},{7,4,10},{9,10,2},{9,7,10}, // front face {6,2,3},{11,9,2},{11,6,8},{9,11,8}, // right face {5,4,6},{12,4,7},{12,8,6},{12,7,8},//top face {8,7,9} //corner triangle }; //--- Fill vertices and triangles vectors // Fill vertices vector for (int i=0; i<13 ; ++i) this->addVertex(v[i][0], v[i][1], v[i][2]); // Fill triangles vector for (int i=0; i<19; ++i) this->addTriangle(t[i][0], t[i][1], t[i][2]); computeNormalsT(); computeNormalsV(); }
my::ConicMesh::ConicMesh(const float & height, const float & aperture, const int & nbSlices, const int & nbStacks) :ParametricMesh("ConicMesh", nbStacks+2, 2*nbSlices), _height(height), _aperture(aperture), _nbSlices(nbSlices), _nbStacks(nbStacks) { _preConicMesh(_height, _aperture, _nbSlices, _nbStacks); my::Conic coord(Point(0,-1,0), _aperture); parametricVertexInsertion(imax()-1, jmax(), coord); this->addVertex(0,-1,0); parametricTriangleInsertion(imax()-1, jmax()); flipTriangles(); computeNormalsT(); computeNormalsV(); }
Torus::Torus(int nbCircles, int nbVertexCircle) { _name="Torus"; _vertices.clear(); double x,y,z; double circleStep=(2.*M_PI)/nbVertexCircle; double longStep=(2.*M_PI)/nbCircles; //Adding Vertex for(double i=0.;i<2.*M_PI;i+=longStep) { for(double j=0.;j<2.*M_PI;j+=circleStep) { x=((2./3.)+(1./3.)*cos(j))*cos(i); y=((2./3.)+(1./3.)*cos(j))*sin(i); z=(1./3.)*sin(j); addVertex(x,y,z); } } int nbVertex = nbCircles*nbVertexCircle; //Adding triangles for(int i=0;i<nbCircles;++i) for(int j=0;j<nbVertexCircle;++j) { addTriangle((i*nbVertexCircle+j+1)%(nbVertex), (i*nbVertexCircle+j)%(nbVertex), ((i+1)*nbVertexCircle+j)%(nbVertex)); addTriangle(((i+1)*nbVertexCircle+j)%(nbVertex), ((i+1)*nbVertexCircle+j+1)%(nbVertex), (i*nbVertexCircle+j+1)%(nbVertex)); } computeNormalsT(); computeNormalsV(); }
Pyramid::Pyramid() : TriMesh("Pyramid") { static const GLfloat ps[5][3] = { {-1,-1,-1},{-1,1,-1},{1,1,-1},{1,-1,-1}, {0,0,1} }; static const GLint ts[6][3] = { {0,1,2},{0,2,3}, // bottom triangles {0,3,4},{3,2,4},{2,1,4},{1,0,4} // side triangles }; int i; for (i=0; i<5 ; ++i) this->addVertex(ps[i][0], ps[i][1], ps[i][2]); for (i=0; i<6; ++i) this->addTriangle(ts[i][0], ts[i][1], ts[i][2]); computeNormalsT(); // to be fixed computeNormalsV(); // to be fixed }
Torus::Torus(int nbpoint):TriMesh() { _name = "Torus"; //angle variation computing if(nbpoint < 4){ throw std::domain_error("Dot number deficient: at least 4 dots are required to create Torus"); } float angle=0; float angleV=360/nbpoint; //vertices coordinates/////////////////////////////////////////////////////////////// std::vector<std::vector<GLfloat> > allVtx; //container to store all vertices std::vector<std::vector<GLfloat> > primaryCircle; //container to store a primary circle std::vector<GLfloat> aVtx(3,0); //any vertex //Triangles vertex indices/////////////////////////////////////////////////////////// //--The primary circle definition---------------------------------------------------- int nbPcVtx=0; while(angle<360){ aVtx[0]=0; aVtx[1]=0.25 * cos(angle * PI/180.0); aVtx[2]=0.25 * sin(angle * PI/180.0); primaryCircle.push_back(aVtx); nbPcVtx++; angle+=angleV; } //primary circle translation following y to get the right position for the torus construction for(unsigned int i=0;i<primaryCircle.size();i++) primaryCircle[i][1]+=0.75; //we add the primary circle to allVtx container for(unsigned int i=0;i<primaryCircle.size();i++){ allVtx.push_back(primaryCircle[i]); } //torus remaining circle computing angle=0; while(angle<360){ for(unsigned int i=0;i<primaryCircle.size();i++){ glm::vec3 vtxToRotate(primaryCircle[i][0],allVtx[i][1],allVtx[i][2]); glm::vec3 vtxRotated = glm::rotateZ(vtxToRotate,angle); aVtx[0]=vtxRotated[0]; aVtx[1]=vtxRotated[1]; aVtx[2]=vtxRotated[2]; allVtx.push_back(aVtx); } angle+=angleV; } //triangles vertex indices/////////////////////////////////////////////////////////// int nbTrgl=2 * allVtx.size(); std::vector<GLint> aTrgl(3,0); std::vector<std::vector<GLint> > torusTrgl(nbTrgl,aTrgl); int r=0; int s=nbPcVtx; int t=s+1; for (unsigned int i=0;i<torusTrgl.size()-(2 * nbPcVtx);i++){ torusTrgl[i][0]=r; torusTrgl[i][1]=s; torusTrgl[i][2]=t; if((std::abs(r-s)==1) && (std::abs(s-t)==nbPcVtx)){ r++; s=s+(nbPcVtx); t=t+(2 * nbPcVtx)+1; }else{ //r variable behavior if((i % 2)==1) r++; //t variable behavior if(((t+1) % nbPcVtx)==0 && (i % 2)==1){ t=t+1; }else{ if((i % 2)==1) t=t+nbPcVtx+1; if((i % 2)==0) t=t-(nbPcVtx); } //s variable behavior if(((s+1) % (nbPcVtx)) == 0 && (i % 2)==0){ s=s-(nbPcVtx-1); }else{ if((i % 2)==0) s++; } } int r=allVtx.size()-nbPcVtx; int s=0; int t=s+1; for(unsigned int i=torusTrgl.size()-(2 * nbPcVtx);i<torusTrgl.size();i++){ torusTrgl[i][0]=r; torusTrgl[i][1]=s; torusTrgl[i][2]=t; //r variable behavior if((i % 2)==1) r++; //t variable behavior if(t==(allVtx.size()-1) && (i % 2)==1){ t=0; }else{ if((i % 2)==1) t=t-(allVtx.size()-nbPcVtx-1); if((i % 2)==0) t=t+(allVtx.size()-nbPcVtx); } //s variable behavior if(((s+1) % (nbPcVtx)) == 0 && (i % 2)==0){ s=s-(nbPcVtx-1); }else{ if((i % 2)==0) s++; } } } //--- Fill vertices vector----------------------------------------------------------- for(unsigned int i=0;i<allVtx.size();i++){ /*std::cout<<allVtx[i][0]<<"|"<<allVtx[i][1]<<"|"<<allVtx[i][2]<<endl; std::cout<<"-------------------------------"<<endl;*/ this->addVertex(allVtx[i][0],allVtx[i][1],allVtx[i][2]); } //--Fill surface triangles----------------------------------------------------------- for(unsigned int i=0;i<torusTrgl.size();i++){ //std::cout<<torusTrgl[i][0]<<"|"<<torusTrgl[i][1]<<"|"<<torusTrgl[i][2]<<endl; this->addTriangle(torusTrgl[i][0],torusTrgl[i][1],torusTrgl[i][2]); } computeNormalsT(); computeNormalsV(); //to be fixed. }
Cube::Cube() : TriMesh() { _name = "Cube"; // vertex coordinates static const GLfloat v[8][3] = { {-1,-1,-1},{-1,1,-1},{1,1,-1},{1,-1,-1}, {-1,-1, 1},{-1,1, 1},{1,1, 1},{1,-1, 1} }; // triangles vertex indices static const GLint t[12][3] = { {1,2,0},{3,0,2}, // bottom triangles {1,5,6},{2,1,6},{2,6,3},{3,6,7},{3,7,0},{0,7,4},{0,4,1},{1,4,5}, // side triangles {4,7,5},{7,6,5} // top triangles }; // triangle normals static const GLint nt[12][3] = { {0,0,-1},{0,0,-1}, // bottom triangle normals {0,1,0},{0,1,0},{1,0,0},{1,0,0},{0,-1,0},{0,-1,0},{-1,0,0},{-1,0,0}, // side triangle normals {0,0,1},{0,0,1} // top triangle normals }; // triangle vertex normals static const GLint nv[36][3] = { {0,0,-1},{0,0,-1},{0,0,-1},{0,0,-1},{0,0,-1},{0,0,-1}, // bottom triangle vertex normals {0,1,0},{0,1,0},{0,1,0},{0,1,0},{0,1,0},{0,1,0}, // side triangle vertex normals {1,0,0},{1,0,0},{1,0,0},{1,0,0},{1,0,0},{1,0,0}, {0,-1,0},{0,-1,0},{0,-1,0},{0,-1,0},{0,-1,0},{0,-1,0}, {-1,0,0},{-1,0,0},{-1,0,0},{-1,0,0},{-1,0,0},{-1,0,0}, {0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1} // top triangle vertex normals }; //--- Fill vertices and triangles vectors // Fill vertices vector for (int i=0; i<8 ; ++i) this->addVertex(v[i][0], v[i][1], v[i][2]); // Fill triangles vector for (int i=0; i<12; ++i) this->addTriangle(t[i][0], t[i][1], t[i][2]); // Fill normals vectors bool use_computed_normals = true; if (use_computed_normals) { computeNormalsT(); // to be fixed computeNormalsV(); // to be fixed } else { // use manually defined normals // set triangle normals for (int i=0; i<12; ++i) { Normal nT(nt[i][0], nt[i][1], nt[i][2]); this->addNormalT(nT); } // set triangle vertex normals for (int i=0; i<36; ++i) { Normal nV(nv[i][0], nv[i][1], nv[i][2]); this->addNormalV(nV); } } }