void Sphere::sub(int n, Point3 p1, Point3 p2, Point3 p3) { Vector3 pv1(p1.x,p1.y,p1.z); Vector3 pv2(p2.x,p2.y,p2.z); Vector3 pv3(p3.x,p3.y,p3.z); if (n == 1) { pv1.normalize(); pv2.normalize(); pv3.normalize(); pv1 *= 0.5; pv2 *= 0.5; pv3 *= 0.5; p1.x = pv1.x; p1.y = pv1.y; p1.z = pv1.z; p2.x = pv2.x; p2.y = pv2.y; p2.z = pv2.z; p3.x = pv3.x; p3.y = pv3.y; p3.z = pv3.z; addTriangle(p1,p2,p3); } else { Vector3 av = pv1+pv2; Vector3 bv = pv2+pv3; Vector3 cv = pv3+pv1; av.normalize(); bv.normalize(); cv.normalize(); Point3 v12(av.x,av.y,av.z); Point3 v23(bv.x,bv.y,bv.z); Point3 v31(cv.x,cv.y,cv.z); sub(n-1,p1,v12,v31); sub(n-1,p2,v23,v12); sub(n-1,p3,v31,v23); sub(n-1,v12,v23,v31); } }
bool SceneParser::addElement(struct basicxmlnode * elementNode, Scene * scene){ if (!elementNode) { std::cout << "SceneParser::addElement: empty element node \n"; return false; } // find out element type if (std::string(elementNode->tag) == "Plane") { return addPlane(elementNode, scene); } else if (std::string(elementNode->tag) == "CirclePlane") { return addCirclePlane(elementNode, scene); } else if (std::string(elementNode->tag) == "Sphere") { return addSphere(elementNode, scene); } else if (std::string(elementNode->tag) == "Triangle") { return addTriangle(elementNode, scene); } else if (std::string(elementNode->tag) == "Quadric") { return addQuadric(elementNode, scene); } else if (std::string(elementNode->tag) == "Torus") { return addTorus(elementNode, scene); } else if (std::string(elementNode->tag) == "TriangleMesh") { return addTriangleMesh(elementNode, scene); } else { std::cout << "SceneParser::addElement: do not know how to generate \"" << elementNode->tag << "\"\n"; return false; } }
//! [2] void MainWindow::createActions() { deleteAction = new QAction(tr("&Delete Item"), this); deleteAction->setShortcut(tr("Del")); connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); //! [2] //! [3] //! [3] //! [4] addBoxAction = new QAction(tr("Add &Box"), this); //! [4] addBoxAction->setShortcut(tr("Ctrl+O")); connect(addBoxAction, SIGNAL(triggered()), this, SLOT(addBox())); addTriangleAction = new QAction(tr("Add &Triangle"), this); addTriangleAction->setShortcut(tr("Ctrl+T")); connect(addTriangleAction, SIGNAL(triggered()), this, SLOT(addTriangle())); //! [5] undoAction = undoStack->createUndoAction(this, tr("&Undo")); undoAction->setShortcuts(QKeySequence::Undo); redoAction = undoStack->createRedoAction(this, tr("&Redo")); redoAction->setShortcuts(QKeySequence::Redo); //! [5] exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcuts(QKeySequence::Quit); connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); aboutAction = new QAction(tr("&About"), this); QList<QKeySequence> aboutShortcuts; aboutShortcuts << tr("Ctrl+A") << tr("Ctrl+B"); aboutAction->setShortcuts(aboutShortcuts); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); }
void TSphere::subdivide(const GLfloat inA[3], const GLfloat inB[3], const GLfloat inC[3], size_t inDepth) { if (!inDepth) { addTriangle(inA, inB, inC); return; } GLfloat ab[3]; GLfloat bc[3]; GLfloat ca[3]; for (size_t i = 0; i < 3; ++i) { ab[i] = (inA[i] + inB[i]) / 2.0f; bc[i] = (inB[i] + inC[i]) / 2.0f; ca[i] = (inC[i] + inA[i]) / 2.0f; } normalize(ab); normalize(bc); normalize(ca); subdivide(inA, ab, ca, inDepth - 1); subdivide(inB, bc, ab, inDepth - 1); subdivide(inC, ca, bc, inDepth - 1); subdivide(ab, bc, ca, inDepth - 1); }
/** * @param newTriangleIndexes [out] Indexes of new triangles added to convex hull * @param removedTriangleIndexes [out] Indexes of removed triangles from convex hull * @return Returns index of point added. If point doesn't make part of convex, result is zero. */ template<class T> unsigned int ConvexHull3D<T>::addNewPoint(const Point3<T> &newPoint, std::vector<unsigned int> &newTriangleIndexes, std::vector<unsigned int> &removedTriangleIndexes) { std::map<long long, std::pair<unsigned int, unsigned int>> edges; constexpr int HALF_SIZE_INDEX = (sizeof(unsigned int) * 8) / 2; //deletes all triangles visible by the new point for(typename std::map<unsigned int, IndexedTriangle3D<T>>::iterator itTriangle=indexedTriangles.begin(); itTriangle!=indexedTriangles.end();) { const IndexedTriangle3D<T> indexedTriangle = itTriangle->second; const Vector3<T> &triangleNormal = indexedTriangle.computeNormal(points); const Point3<T> &point0 = points.find(indexedTriangle.getIndexes()[0])->second; const Vector3<T> &triangleToPoint = point0.vector(newPoint); if(triangleNormal.dotProduct(triangleToPoint) > 0.0) { for(int i=0; i<3; i++) { //each edge int index1 = indexedTriangle.getIndexes()[i]; int index2 = indexedTriangle.getIndexes()[(i+1)%3]; long long idEdge = (std::min(index1, index2) << HALF_SIZE_INDEX) | std::max(index1, index2); std::map<long long, std::pair<unsigned int, unsigned int>>::iterator itEdge = edges.find(idEdge); if(itEdge==edges.end()) { edges[idEdge] = std::make_pair(index1, index2); }else { edges.erase(itEdge); } } removedTriangleIndexes.push_back(itTriangle->first); removeTriangle(itTriangle++); }else { ++itTriangle; } } //adds the new triangles if(edges.size()>0) { newTriangleIndexes.reserve(edges.size()); unsigned int pointIndex = nextPointIndex++; points[pointIndex] = newPoint; for(std::map<long long, std::pair<unsigned int, unsigned int>>::iterator it = edges.begin(); it!=edges.end(); ++it) { unsigned int triangleIndex = addTriangle(IndexedTriangle3D<T>(it->second.first, it->second.second, pointIndex)); newTriangleIndexes.push_back(triangleIndex); } return pointIndex; } return 0; }
Mesh::Mesh(const std::vector<Vector3>& vertices, const std::vector<Index*>& triangles) { for(unsigned int i = 0; i < vertices.size(); ++i) addVertex(vertices[i]); for(unsigned int i = 0; i < triangles.size(); ++i) addTriangle(triangles[i][0], triangles[i][1], triangles[i][2]); }
void Path::addTriangle (float x1, float y1, float x2, float y2, float x3, float y3) { addTriangle (Point<float> (x1, y1), Point<float> (x2, y2), Point<float> (x3, y3)); }
void Terrain2D::addGrass(Position p1, Position p2, Position p3) { // 4 float/vertices * 3 vertices. std::array<GLfloat, 4 * 3> data_; int index = 0; addTriangle(data_.data(), index, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, 0, 0, 0, 0, 0, 0); grass_.insert(grass_.end(), data_.begin(), data_.end()); numberVerticesGrass_ += 3; }
bool arlCore::Mesh::addTriangle( Point::csptr P1, Point::csptr P2, Point::csptr P3 ) { std::vector<unsigned int> index; index.push_back(addPoint(P1)); index.push_back(addPoint(P2)); index.push_back(addPoint(P3)); return addTriangle(index[0], index[1], index[2]); }
QWidget *WalkmeshManager::buildWalkmeshPage() { QWidget *ret = new QWidget(this); ListWidget *listWidget = new ListWidget(ret); listWidget->addAction(ListWidget::Add, tr("Ajouter triangle"), this, SLOT(addTriangle())); listWidget->addAction(ListWidget::Rem, tr("Supprimer triangle"), this, SLOT(removeTriangle())); idToolbar = listWidget->toolBar(); idList = listWidget->listWidget(); idVertices[0] = new VertexWidget(ret); idVertices[1] = new VertexWidget(ret); idVertices[2] = new VertexWidget(ret); idAccess[0] = new QSpinBox(ret); idAccess[1] = new QSpinBox(ret); idAccess[2] = new QSpinBox(ret); idAccess[0]->setRange(-32768, 32767); idAccess[1]->setRange(-32768, 32767); idAccess[2]->setRange(-32768, 32767); QHBoxLayout *accessLayout0 = new QHBoxLayout; accessLayout0->addWidget(new QLabel(tr("Triangle accessible via la ligne 1-2 :"))); accessLayout0->addWidget(idAccess[0]); QHBoxLayout *accessLayout1 = new QHBoxLayout; accessLayout1->addWidget(new QLabel(tr("Triangle accessible via la ligne 2-3 :"))); accessLayout1->addWidget(idAccess[1]); QHBoxLayout *accessLayout2 = new QHBoxLayout; accessLayout2->addWidget(new QLabel(tr("Triangle accessible via la ligne 3-1 :"))); accessLayout2->addWidget(idAccess[2]); QGridLayout *layout = new QGridLayout(ret); layout->addWidget(listWidget, 0, 0, 7, 1, Qt::AlignLeft); layout->addWidget(new QLabel(tr("Point 1 :")), 0, 1); layout->addWidget(idVertices[0], 0, 2); layout->addWidget(new QLabel(tr("Point 2 :")), 1, 1); layout->addWidget(idVertices[1], 1, 2); layout->addWidget(new QLabel(tr("Point 3 :")), 2, 1); layout->addWidget(idVertices[2], 2, 2); layout->addLayout(accessLayout0, 3, 1, 1, 2); layout->addLayout(accessLayout1, 4, 1, 1, 2); layout->addLayout(accessLayout2, 5, 1, 1, 2); layout->setRowStretch(6, 1); connect(idList, SIGNAL(currentRowChanged(int)), SLOT(setCurrentId(int))); connect(idVertices[0], SIGNAL(valuesChanged(Vertex_s)), SLOT(editIdTriangle(Vertex_s))); connect(idVertices[1], SIGNAL(valuesChanged(Vertex_s)), SLOT(editIdTriangle(Vertex_s))); connect(idVertices[2], SIGNAL(valuesChanged(Vertex_s)), SLOT(editIdTriangle(Vertex_s))); connect(idAccess[0], SIGNAL(valueChanged(int)), SLOT(editIdAccess(int))); connect(idAccess[1], SIGNAL(valueChanged(int)), SLOT(editIdAccess(int))); connect(idAccess[2], SIGNAL(valueChanged(int)), SLOT(editIdAccess(int))); return ret; }
GeometrySphereGeodesic::GeometrySphereGeodesic(int subdivisions) { float t = (1 + sqrt(5.0))/2.0; float s = sqrt(1 + t*t); // create the 12 vertices ofVec3f v0 = ofVec3f(t, 1, 0)/s; ofVec3f v1 = ofVec3f(-t, 1, 0)/s; ofVec3f v2 = ofVec3f(t, -1, 0)/s; ofVec3f v3 = ofVec3f(-t, -1, 0)/s; ofVec3f v4 = ofVec3f(1, 0, t)/s; ofVec3f v5 = ofVec3f(1, 0, -t)/s; ofVec3f v6 = ofVec3f(-1, 0, t)/s; ofVec3f v7 = ofVec3f(-1, 0, -t)/s; ofVec3f v8 = ofVec3f(0, t, 1)/s; ofVec3f v9 = ofVec3f(0, -t, 1)/s; ofVec3f v10 = ofVec3f(0, t, -1)/s; ofVec3f v11 = ofVec3f(0, -t, -1)/s; vector<Triangle> triangles; // create the 20 triangles triangles.push_back(Triangle(v0, v8, v4)); triangles.push_back(Triangle(v1, v10, v7)); triangles.push_back(Triangle(v2, v9, v11)); triangles.push_back(Triangle(v7, v3, v1)); triangles.push_back(Triangle(v0, v5, v10)); triangles.push_back(Triangle(v3, v9, v6)); triangles.push_back(Triangle(v3, v11, v9)); triangles.push_back(Triangle(v8, v6, v4)); triangles.push_back(Triangle(v2, v4, v9)); triangles.push_back(Triangle(v3, v7, v11)); triangles.push_back(Triangle(v4, v2, v0)); triangles.push_back(Triangle(v9, v4, v6)); triangles.push_back(Triangle(v2, v11, v5)); triangles.push_back(Triangle(v0, v10, v8)); triangles.push_back(Triangle(v5, v0, v2)); triangles.push_back(Triangle(v10, v5, v7)); triangles.push_back(Triangle(v1, v6, v8)); triangles.push_back(Triangle(v1, v8, v10)); triangles.push_back(Triangle(v6, v1, v3)); triangles.push_back(Triangle(v11, v7, v5)); for (int ctr = 0; ctr < subdivisions; ctr++) subdivide(triangles); for(int i = 0; i<triangles.size(); i++) { Triangle& tri = triangles[i]; addVertex(tri.v0); addVertex(tri.v1); addVertex(tri.v2); addTriangle(i*3,i*3+1, i*3+2); } mergeDuplicateVertices(); }
void my::ParametricMesh::parametricTriangleInsertion(const int & imax, const int & jmax) { int iA, iB, iC, iD; for(int i=0; i<imax; ++i){ for(int j=0; j<jmax; ++j){ iA = _indiceOfSampled(i,j); iB = _indiceOfSampled(i+1, j); iC = _indiceOfSampled(i+1, j+1); iD = _indiceOfSampled(i, j+1); addTriangle(iA, iB, iC); if(iA != iD){ addTriangle(iA, iC, iD); } } } }
osgToy::ColorOriginTetra::ColorOriginTetra() { osg::Vec3 o(0,0,0); osg::Vec3 x(1,0,0); osg::Vec3 y(0,1,0); osg::Vec3 z(0,0,1); addTriangle( o, y, x ); addTriangle( o, z, y ); addTriangle( o, x, z ); addTriangle( x, y, z ); setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE ); setColorBinding( osg::Geometry::BIND_PER_VERTEX ); osg::Vec3Array* vAry = dynamic_cast<osg::Vec3Array*>( getVertexArray() ); addPrimitiveSet( new osg::DrawArrays( GL_TRIANGLES, 0, vAry->size() ) ); }
/* private */ void Centroid::addHole(const CoordinateSequence& pts) { bool isPositiveArea = CGAlgorithms::isCCW(&pts); for (size_t i = 0, e = pts.size() - 1; i < e; ++i) { addTriangle(*areaBasePt, pts[i], pts[i+1], isPositiveArea); } addLineSegments(pts); }
void generateMesh(const std::vector<TriangleIndices>& faces) { for (auto i = 0; i < faces.size(); ++i) { auto face = faces[i]; addTriangle( scale(vertexList_[face.V1]) + center_, scale(vertexList_[face.V2]) + center_, scale(vertexList_[face.V3]) + center_); } }
void CentroidArea::addShell(const CoordinateSequence *pts) { bool isPositiveArea=!CGAlgorithms::isCCW(pts); std::size_t const n=pts->getSize()-1; for(std::size_t i=0; i<n; ++i) { addTriangle(basePt, pts->getAt(i), pts->getAt(i+1), isPositiveArea); } }
bool Physics3DShape::initMesh( const cocos2d::Vec3 *triangles, int numTriangles ) { _shapeType = ShapeType::MESH; auto mesh = new btTriangleMesh(false); for (int i = 0; i < numTriangles * 3; i += 3){ mesh->addTriangle(convertVec3TobtVector3(triangles[i]), convertVec3TobtVector3(triangles[i + 1]), convertVec3TobtVector3(triangles[i + 2])); } _btShape = new btBvhTriangleMeshShape(mesh, true); return true; }
void DynoTree::makeLeaves(glm::vec3 pos, glm::vec3 dir, float len) { for (int i = 1;i<6;i++) { glm::vec3 leafDir = glm::normalize(dir) * 0.5f + glm::sphericalRand(0.5f); glm::vec3 leafCross = glm::normalize(glm::cross(leafDir,glm::vec3(random(i+(int)pos.x*1000),0.f,random(i+(int)pos.y*1000))))*0.5f; glm::vec3 leafPos = pos + dir*len/6.f*(float)i + leafDir*0.3f; glm::vec3 leafNorm = glm::normalize(glm::cross(leafCross,leafDir)); leafDir = leafDir*2.f; leafCross = leafCross*2.f; addPoint(numberOfPoints, leafPos, leafNorm, 0.f,0.7f,0.0f); editTextureCoord(numberOfPoints,0.38f,1.f); numberOfPoints++; addPoint(numberOfPoints, leafPos+leafDir/2.f+leafCross, leafNorm, 0.f ,0.7f,0.f); editTextureCoord(numberOfPoints,0.63f,1.f); numberOfPoints++; addPoint(numberOfPoints, leafPos+leafDir, leafNorm, 0.f,0.7f,0.f); editTextureCoord(numberOfPoints,0.63f,0.75f); numberOfPoints++; addTriangle(numberOfTriangles,numberOfPoints-2,numberOfPoints-1,numberOfPoints-3); numberOfTriangles++; addPoint(numberOfPoints, leafPos+leafDir/2.f-leafCross, leafNorm, 0.f ,0.7f,0.f); editTextureCoord(numberOfPoints,0.38f,0.75f); numberOfPoints++; addTriangle(numberOfTriangles,numberOfPoints-2,numberOfPoints-1,numberOfPoints-4); numberOfTriangles++; } }
void SpotLight::generateVertices() { m_triangles.clear(); float angleRad = m_angle * M_PI / 180.0; float openAngleRad = m_openAngle * M_PI / 180.0; addTriangle(sf::Vector2f(m_radius * cos(angleRad - openAngleRad), m_radius * sin(angleRad - openAngleRad)), sf::Vector2f(m_radius * cos(angleRad + openAngleRad), m_radius * sin(angleRad + openAngleRad))); }
Cone::Cone(int n, int m) : Shape() { if( n < 3 ) n = 3; // Your code for tessellating a cone goes here const static double MAXY = 0.5; const static double RAD = 0.5; double YINC = 2.0*(MAXY/(double)m); for ( double i = 0; i < 360; i += 360/(double)n ) { Point3 a; Point3 b; Point3 c; Point3 d; double dl = i*(PI/180.0); double dr = (i+(360.0/(double)n))*(PI/180.0); a.x = std::cos(dl)*RAD; a.z = std::sin(dl)*RAD; a.y = -MAXY; b.x = std::cos(dr)*RAD; b.z = std::sin(dr)*RAD; b.y = -MAXY; c.x = 0; c.z = 0; c.y = -MAXY; addTriangle(a,b,c); double yval = -MAXY; c.y = yval; d.y = yval; double r = RAD; for ( int j = 1; j < m; j++ ) { a.y = yval; b.y = yval; r = r - RAD/(double)m; c.x = cos(dl)*r; c.z = sin(dl)*r; c.y += YINC; d.x = cos(dr)*r; d.z = sin(dr)*r; d.y += YINC; addTriangle(d,b,a); addTriangle(c,d,a); a.x = c.x; a.z = c.z; b.x = d.x; b.z = d.z; yval += YINC; } a.y = yval; b.y = yval; c.x = 0; c.z = 0; c.y = MAXY; addTriangle(c,b,a); } }
void generate() { int heightSegments = (int) std::ceil(height_ / maxSegmentHeight_); double heightStep = height_ / heightSegments; double angleStep = 2 * pi / radialSegments_; for (int j = 0; j < radialSegments_; j++) { double firstAngle = j * angleStep; double secondAngle = (j == radialSegments_ - 1 ? 0 : j + 1) * angleStep; utymap::meshing::Vector2 first( radius_ * std::cos(firstAngle) + center_.x, radius_ * std::sin(firstAngle) + center_.z); utymap::meshing::Vector2 second( radius_ * std::cos(secondAngle) + center_.x, radius_ * std::sin(secondAngle) + center_.z); // bottom cap addTriangle(center_, utymap::meshing::Vector3(first.x, center_.y, first.y), utymap::meshing::Vector3(second.x, center_.y, second.y)); // top cap addTriangle(utymap::meshing::Vector3(center_.x, center_.y + height_, center_.z), utymap::meshing::Vector3(second.x, center_.y + height_, second.y), utymap::meshing::Vector3(first.x, center_.y + height_, first.y)); for (int i = 0; i < heightSegments; i++) { double bottomHeight = i * heightStep + center_.y; double topHeight = (i + 1) * heightStep + center_.y; utymap::meshing::Vector3 v0(first.x, bottomHeight, first.y); utymap::meshing::Vector3 v1(second.x, bottomHeight, second.y); utymap::meshing::Vector3 v2(second.x, topHeight, second.y); utymap::meshing::Vector3 v3(first.x, topHeight, first.y); addTriangle(v0, v2, v1); addTriangle(v3, v2, v0); } } }
/** * @param points Points of the convex hull (all points must belong to the convex hull and indexes should start from 0 to points size - 1) * @param indexedTriangles Triangles of the convex hull (the triangles must form a convex and indexes should start from 0 to triangle size - 1) */ template<class T> ConvexHull3D<T>::ConvexHull3D(const std::map<unsigned int, Point3<T>> &points, const std::map<unsigned int, IndexedTriangle3D<T>> &indexedTriangles) : nextPointIndex(points.size()), nextTriangleIndex(0) { this->points = points; for(typename std::map<unsigned int, IndexedTriangle3D<T>>::const_iterator it = indexedTriangles.begin(); it!=indexedTriangles.end(); ++it) { addTriangle(it->second); } }
//-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button) { if(breakupIntoTriangles) { // This is the manual way to triangulate the shape // you can then add many little triangles // first simplify the shape shape.simplify(); // save the outline of the shape ofPolyline outline = shape; // resample shape ofPolyline resampled = shape.getResampledBySpacing(25); // trangleate the shape, return am array of traingles vector <TriangleShape> tris = triangulatePolygonWithOutline(resampled, outline); // add some random points inside addRandomPointsInside(shape, 255); // now loop through all the trainles and make a box2d triangle for(int i=0; i<tris.size(); i++) { auto triangle = std::make_shared<ofxBox2dPolygon>(); triangle->addTriangle(ofDefaultVertexType(tris[i].a.x, tris[i].a.y, 0), ofDefaultVertexType(tris[i].b.x, tris[i].b.y, 0), ofDefaultVertexType(tris[i].c.x, tris[i].c.y, 0)); triangle->setPhysics(1.0, 0.3, 0.3); triangle->create(box2d.getWorld()); polyShapes.push_back(triangle); } } else { auto poly = std::make_shared<ofxBox2dPolygon>(); poly->addVertices(shape.getVertices()); poly->setPhysics(1.0, 0.3, 0.3); poly->triangulatePoly(); poly->create(box2d.getWorld()); polyShapes.push_back(poly); } // done with shape clear it now shape.clear(); }
void Terrain::storePointsTriangles(){ int i,j,k=0; float init_scale_factor = 0.5; int center_factor = (this->side_size-1)/2; for (i=0; i<this->side_size-1; i++){ for (j=0; j<this->side_size-1; j++){ point4 p1 = point4(i-center_factor,j-center_factor,terrain[i][j],1.0); point4 p2 = point4(i-center_factor,j+1-center_factor,terrain[i][j+1],1.0); point4 p3 = point4(i+1-center_factor,j+1-center_factor,terrain[i+1][j+1],1.0); point4 p4 = point4(i+1-center_factor,j-center_factor,terrain[i+1][j],1.0); color4 high = color4(.95f, .95f, .95f, 1.0); // White color4 mid = color4(.05f, .75f, .45f, 1.0); // Green color4 low = color4(.05f, .05f, .95f, 1.0); // Blue color4 brown = color4(0.5f, 0.35f, 0.05f, 1.0); // Brown addTriangle(p1, p2, p3, high, mid, low, brown); addTriangle(p1, p3, p4, high, mid, low, brown); } } }
void GraphicsScene::paintTriangulation(Triangulation *tri, int i) { for(auto p : tri->getPoints()) { addPoint(p, i); } for(auto s : tri->getSegments()) { addSegment(s, i); } for(auto t : tri->getTriangles()) { addTriangle(t, i); } }
Turret::Turret() : GameObject(0) { shared_ptr<Coordinate> c0{new Coordinate{0,0.0001}}; shared_ptr<Coordinate> c1{new Coordinate{50.0001,0}}; shared_ptr<Coordinate> c2{new Coordinate{25.00006,50.0001}}; shared_ptr<Triangle> t0{new Triangle{c0,c1,c2}}; addTriangle(t0); _health = 200; _range = 500; _glued = true; }
//-------------------------------------------------------------------------------------------------- /// Add a triangle strip /// /// Vertex ordering for triangle strips: /// <PRE> /// v0 v2 v4 Resulting triangles: /// *-------*-------* t1: v0, v1, v2 /// \ / \ / \ t2: v2, v1, v3 /// \ / \ / \ t3: v2, v3, v4 /// \ / \ / \ t4: v4, v3, v5 /// *-------*-------* /// v1 v3 v5 </PRE> /// /// \remarks The number of entries in the \a indices array must be at least 3. //-------------------------------------------------------------------------------------------------- void GeometryBuilder::addTriangleStrip(const UIntArray& indices) { size_t numIndices = indices.size(); CVF_ASSERT(numIndices >= 3); size_t numTriangles = numIndices - 2; CVF_ASSERT(numTriangles >= 1); size_t i; for (i = 0; i < numTriangles; i++) { if (i % 2 == 0) { addTriangle(indices[i], indices[i + 1], indices[i + 2]); } else { addTriangle(indices[i + 1], indices[i], indices[i + 2]); } } }
//helper addtriangle function to insert texture coordinates too void Object::addTriangle(Vec3f v1, Vec3f u1, Vec3f v2, Vec3f u2, Vec3f v3, Vec3f u3){ //add triangle normally addTriangle(v1, v2, v3); //TODO integrate uv coordinates in face //add extra texture coordinates to the uv vector uv.push_back(u1); uv.push_back(u2); uv.push_back(u3); Vec3f e1 = v2 - v1; Vec3f e2 = v3 - v1; float deltaU1 = u2.x - u1.x; float deltaV1 = u2.y - u1.y; float deltaU2 = u3.x - u1.x; float deltaV2 = u3.y - u1.y; float f = 1.f / (deltaU1 * deltaV2 - deltaU2 * deltaV1); Vec3f tangent; tangent = f * (deltaV2 * e1 - deltaV1 * e2); auto tangentIter = find(tangents.begin(), tangents.end(), tangent); // if tangent not in the vector, then add it and set iter to the // vector's tail. if (tangentIter == tangents.end()){ tangents.push_back(tangent); tangentIter = tangents.end() - 1; } GLuint tangentIndex = tangentIter - tangents.begin(); face* face = faces.back(); face->t = tangentIndex; vector<Vec3f> triangleVertices; triangleVertices.push_back(v1); triangleVertices.push_back(v2); triangleVertices.push_back(v3); for (unsigned i = 0; i < triangleVertices.size(); i++){ Vec3f v = triangleVertices.at(i); if (sharedTangents.find(v) == sharedTangents.end()){ sharedTangents.insert(pair<Vec3f, Vec3f>(v, tangent)); } else{ Vec3f& vt = sharedTangents.at(v); vt += tangent; } } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void GeometryBuilder::addTriangleByVertices(const Vec3f& v0, const Vec3f& v1, const Vec3f& v2) { Vec3fArray verts; verts.resize(3); verts[0] = v0; verts[1] = v1; verts[2] = v2; uint firstVertexIdx = addVertices(verts); addTriangle(firstVertexIdx, firstVertexIdx + 1, firstVertexIdx + 2); }
/* private */ void Centroid::addShell(const CoordinateSequence& pts) { size_t len = pts.size(); if (len > 0) setBasePoint(pts[0]); bool isPositiveArea = ! CGAlgorithms::isCCW(&pts); for (size_t i = 0; i < len - 1; ++i) { addTriangle(*areaBasePt, pts[i], pts[i+1], isPositiveArea); } addLineSegments(pts); }