Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OSG::NodeRefPtr createDual(OSG::NodeRefPtr nodegeo) {
- OSG::TriangleIterator triangleIterator;
- OSG::GeometryRefPtr geocore = dynamic_cast<OSG::Geometry *>(nodegeo->getCore());
- std::vector<OSG::Pnt3f> centrePositions;
- float x;
- float y;
- float z;
- for (triangleIterator = geocore->beginTriangles();
- triangleIterator != geocore->endTriangles();
- ++triangleIterator)
- {
- OSG::Pnt3f pos1 = triangleIterator.getPosition(0);
- OSG::Pnt3f pos2 = triangleIterator.getPosition(1);
- OSG::Pnt3f pos3 = triangleIterator.getPosition(2);
- x = ((pos1.x() + pos2.x() + pos3.x()) / 3);
- y = ((pos1.y() + pos2.y() + pos3.y()) / 3);
- z = ((pos1.z() + pos2.z() + pos3.z()) / 3);
- OSG::Pnt3f temp(x, y, z);
- centrePositions.push_back(temp);
- std::cout << "Triangle " << triangleIterator.getIndex() << ":" << std::endl;
- std::cout << triangleIterator.getPosition(0) << std::endl;
- std::cout << triangleIterator.getPosition(1) << std::endl;
- std::cout << triangleIterator.getPosition(2) << std::endl;
- }
- OSG::NodeRefPtr tetraNode = OSG::Node::create();
- //create a geometry
- OSG::GeometryRefPtr tetraGeo = OSG::Geometry::create();
- //The primitive types.
- OSG::GeoUInt8PropertyRefPtr type = OSG::GeoUInt8Property::create();
- type->addValue(GL_TRIANGLES);
- //The primitive lengths.
- OSG::GeoUInt32PropertyRefPtr lens = OSG::GeoUInt32Property::create();
- lens->addValue(12);
- //the verticies.
- OSG::GeoPnt3fPropertyRefPtr pnts = OSG::GeoPnt3fProperty::create();
- pnts->addValue(centrePositions[0]);
- pnts->addValue(centrePositions[1]);
- pnts->addValue(centrePositions[2]);
- pnts->addValue(centrePositions[3]);
- OSG::GeoUInt32PropertyRefPtr indices = OSG::GeoUInt32Property::create();
- //Face 1: Top
- indices->addValue(1);
- indices->addValue(3);
- indices->addValue(2);
- //Face 2: Front Left
- indices->addValue(0);
- indices->addValue(3);
- indices->addValue(1);
- //Face 3: Front Right
- indices->addValue(0);
- indices->addValue(3);
- indices->addValue(2);
- //Face 4: Back
- indices->addValue(0);
- indices->addValue(2);
- indices->addValue(1);
- std::cout << "This geometry has: " << triangleIterator.getIndex() << " triangles." << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement