Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. OSG::NodeRefPtr createDual(OSG::NodeRefPtr nodegeo) {
  2. OSG::TriangleIterator triangleIterator;
  3.  
  4. OSG::GeometryRefPtr geocore = dynamic_cast<OSG::Geometry *>(nodegeo->getCore());
  5. std::vector<OSG::Pnt3f> centrePositions;
  6.  
  7. float x;
  8. float y;
  9. float z;
  10.  
  11. for (triangleIterator = geocore->beginTriangles();
  12. triangleIterator != geocore->endTriangles();
  13. ++triangleIterator)
  14. {
  15. OSG::Pnt3f pos1 = triangleIterator.getPosition(0);
  16. OSG::Pnt3f pos2 = triangleIterator.getPosition(1);
  17. OSG::Pnt3f pos3 = triangleIterator.getPosition(2);
  18.  
  19. x = ((pos1.x() + pos2.x() + pos3.x()) / 3);
  20. y = ((pos1.y() + pos2.y() + pos3.y()) / 3);
  21. z = ((pos1.z() + pos2.z() + pos3.z()) / 3);
  22.  
  23. OSG::Pnt3f temp(x, y, z);
  24. centrePositions.push_back(temp);
  25.  
  26. std::cout << "Triangle " << triangleIterator.getIndex() << ":" << std::endl;
  27. std::cout << triangleIterator.getPosition(0) << std::endl;
  28. std::cout << triangleIterator.getPosition(1) << std::endl;
  29. std::cout << triangleIterator.getPosition(2) << std::endl;
  30. }
  31.  
  32. OSG::NodeRefPtr tetraNode = OSG::Node::create();
  33.  
  34. //create a geometry
  35. OSG::GeometryRefPtr tetraGeo = OSG::Geometry::create();
  36.  
  37. //The primitive types.
  38. OSG::GeoUInt8PropertyRefPtr type = OSG::GeoUInt8Property::create();
  39. type->addValue(GL_TRIANGLES);
  40.  
  41. //The primitive lengths.
  42. OSG::GeoUInt32PropertyRefPtr lens = OSG::GeoUInt32Property::create();
  43. lens->addValue(12);
  44.  
  45. //the verticies.
  46. OSG::GeoPnt3fPropertyRefPtr pnts = OSG::GeoPnt3fProperty::create();
  47.  
  48. pnts->addValue(centrePositions[0]);
  49. pnts->addValue(centrePositions[1]);
  50. pnts->addValue(centrePositions[2]);
  51. pnts->addValue(centrePositions[3]);
  52.  
  53.  
  54. OSG::GeoUInt32PropertyRefPtr indices = OSG::GeoUInt32Property::create();
  55.  
  56. //Face 1: Top
  57. indices->addValue(1);
  58. indices->addValue(3);
  59. indices->addValue(2);
  60.  
  61. //Face 2: Front Left
  62. indices->addValue(0);
  63. indices->addValue(3);
  64. indices->addValue(1);
  65.  
  66. //Face 3: Front Right
  67. indices->addValue(0);
  68. indices->addValue(3);
  69. indices->addValue(2);
  70.  
  71. //Face 4: Back
  72. indices->addValue(0);
  73. indices->addValue(2);
  74. indices->addValue(1);
  75.  
  76. std::cout << "This geometry has: " << triangleIterator.getIndex() << " triangles." << std::endl;
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement