PointShape.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Include own headers
  2. #include "PointShape.hpp"
  3. // Include modules
  4. #include "OSGWidget.hpp"
  5. #include "defaults.hpp"
  6. #include "MainWindow.hpp"
  7. // Include dependencies
  8. #include <osgUtil/MeshOptimizers>
  9. #include "lib3mf_implicit.hpp"
  10. PointShape::PointShape(const osg::ref_ptr<osg::Group> renderRoot, const ActiveTrackingSystem activeTrackingSystem, osg::Vec3f point, osg::Vec3f normal, osg::Vec3f normalModifier) {
  11. _renderRoot = renderRoot;
  12. _activeTrackingSystem = activeTrackingSystem;
  13. _screwMove = new osg::MatrixTransform;
  14. _selectionRotateGroup = new osg::MatrixTransform;
  15. _selectionRotateGroup->addChild(_screwMove.get());
  16. _selectionMoveToEndGroup = new osg::MatrixTransform;
  17. _selectionMoveToEndGroup->addChild(_selectionRotateGroup.get());
  18. _selectionTranslateGroup = new osg::MatrixTransform;
  19. _selectionTranslateGroup->addChild(_selectionMoveToEndGroup.get());
  20. _selectionSwitch = new osg::Switch;
  21. _selectionSwitch->addChild(_selectionTranslateGroup.get());
  22. _renderRoot->addChild(_selectionSwitch.get());
  23. moveTo(point);
  24. setNormalModifier(normalModifier);
  25. rotateToNormalVector(normal);
  26. }
  27. PointShape::~PointShape() {
  28. _renderRoot->removeChild(_selectionSwitch.get());
  29. }
  30. void PointShape::moveTo(osg::Vec3f position) {
  31. _selectionTranslateGroup->setMatrix(osg::Matrix::translate(position));
  32. }
  33. void PointShape::setNormalModifier(osg::Vec3f normalModifier) {
  34. _normalModifier = normalModifier;
  35. }
  36. void PointShape::rotateToNormalVector(osg::Vec3f normal) {
  37. normal = normal.operator+(_normalModifier);
  38. normal.normalize();
  39. _selectionRotateGroup->setMatrix(osg::Matrix::rotate(osg::Vec3f(0.0f, 0.0f, 1.0f), normal));
  40. if (_activeTrackingSystem == OptiTrack || _activeTrackingSystem == SteamVRTrack) {
  41. osg::Vec3f movementVector = normal.operator*(_optiTrackSteamVRLength / 2);
  42. _selectionMoveToEndGroup->setMatrix(osg::Matrix::translate(movementVector));
  43. }
  44. if (_activeTrackingSystem == SteamVRTrack) {
  45. osg::Vec3f movementVector = osg::Vec3f(0.0f, 0.0f, 1.0f).operator*(_optiTrackSteamVRLength / 2);
  46. _screwMove->setMatrix(osg::Matrix::translate(movementVector));
  47. }
  48. }
  49. void PointShape::setVisibility(bool mode) {
  50. _selectionSwitch->setValue(0, mode);
  51. }
  52. void PointShape::setColor(osg::Vec4 color) {
  53. _shape->setColor(color);
  54. if (_thread) {
  55. OSGWidget::fixMaterialState(_thread, &color);
  56. }
  57. }
  58. void PointShape::setupOptiTrack(OptiTrackSettings optiTrackSettings) {
  59. if (_activeTrackingSystem == OptiTrack) {
  60. _optiTrackSteamVRLength = optiTrackSettings.length;
  61. _geode = new osg::Geode;
  62. _shape = new osg::ShapeDrawable();
  63. _shape->setShape(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 0.0f), optiTrackSettings.radius, optiTrackSettings.length));
  64. _shape->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 0.2f));
  65. _geode->addDrawable(_shape.get());
  66. OSGWidget::fixMaterialState(_geode);
  67. _selectionRotateGroup->addChild(_geode.get());
  68. }
  69. }
  70. void PointShape::setupSteamVRTrack(SteamVRTrackSettings steamVrTrackSettings) {
  71. if (_activeTrackingSystem == SteamVRTrack) {
  72. _optiTrackSteamVRLength = steamVrTrackSettings.length;
  73. _geode = new osg::Geode;
  74. _shape = new osg::ShapeDrawable();
  75. _shape->setShape(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 0.0f), STEAMVR_CONSTANT_RADIUS, steamVrTrackSettings.length));
  76. _shape->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 0.2f));
  77. _geode->addDrawable(_shape.get());
  78. MainWindow::getInstance()->getOsgWidget()->loadSteamvrThread();
  79. _thread = new osg::Geode;
  80. _thread->addDrawable(MainWindow::getInstance()->getOsgWidget()->_steamvrThreadMesh.get());
  81. OSGWidget::fixMaterialState(_thread);
  82. _screwMove->addChild(_thread.get());
  83. OSGWidget::fixMaterialState(_geode);
  84. _selectionRotateGroup->addChild(_geode.get());
  85. }
  86. }
  87. void PointShape::setupActionPoints() {
  88. if (_activeTrackingSystem == ActionPoints) {
  89. _geode = new osg::Geode;
  90. _shape = new osg::ShapeDrawable();
  91. _shape->setShape(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 0.5f));
  92. _shape->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 0.2f));
  93. _geode->addDrawable(_shape.get());
  94. OSGWidget::fixMaterialState(_geode);
  95. _selectionRotateGroup->addChild(_geode.get());
  96. }
  97. }
  98. osg::ref_ptr<osg::Geode> PointShape::getMesh() {
  99. return _geode;
  100. }