PointShape.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Include own headers
  2. #include "PointShape.hpp"
  3. // Include modules
  4. #include "OSGWidget.hpp"
  5. PointShape::PointShape(const osg::ref_ptr<osg::Group> renderRoot, const ActiveTrackingSystem activeTrackingSystem, osg::Vec3f point, osg::Vec3f normal, osg::Vec3f normalModifier) {
  6. _renderRoot = renderRoot;
  7. _activeTrackingSystem = activeTrackingSystem;
  8. _selectionRotateGroup = new osg::MatrixTransform;
  9. _selectionMoveToEndGroup = new osg::MatrixTransform;
  10. _selectionMoveToEndGroup->addChild(_selectionRotateGroup.get());
  11. _selectionTranslateGroup = new osg::MatrixTransform;
  12. _selectionTranslateGroup->addChild(_selectionMoveToEndGroup.get());
  13. _selectionSwitch = new osg::Switch;
  14. _selectionSwitch->addChild(_selectionTranslateGroup.get());
  15. _renderRoot->addChild(_selectionSwitch.get());
  16. moveTo(point);
  17. setNormalModifier(normalModifier);
  18. rotateToNormalVector(normal);
  19. }
  20. PointShape::~PointShape() {
  21. _renderRoot->removeChild(_selectionSwitch.get());
  22. }
  23. void PointShape::moveTo(osg::Vec3f position) {
  24. _selectionTranslateGroup->setMatrix(osg::Matrix::translate(position));
  25. }
  26. void PointShape::setNormalModifier(osg::Vec3f normalModifier) {
  27. _normalModifier = normalModifier;
  28. }
  29. void PointShape::rotateToNormalVector(osg::Vec3f normal) {
  30. normal = normal.operator+(_normalModifier);
  31. normal.normalize();
  32. _selectionRotateGroup->setMatrix(osg::Matrix::rotate(osg::Vec3f(0.0f, 0.0f, 1.0f), normal));
  33. osg::Vec3f movementVector = normal.operator*(_optiTrackSteamVRLength / 2);
  34. _selectionMoveToEndGroup->setMatrix(osg::Matrix::translate(movementVector));
  35. }
  36. void PointShape::setVisibility(bool mode) {
  37. _selectionSwitch->setValue(0, mode);
  38. }
  39. void PointShape::setColor(osg::Vec4 color) {
  40. _shape->setColor(color);
  41. }
  42. void PointShape::setupOptiTrack(OptiTrackSettings optiTrackSettings) {
  43. if (_activeTrackingSystem == OptiTrack) {
  44. _optiTrackSteamVRLength = optiTrackSettings.length;
  45. osg::ref_ptr<osg::Geode> geode = new osg::Geode;
  46. _shape = new osg::ShapeDrawable();
  47. _shape->setShape(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 0.0f), optiTrackSettings.radius, optiTrackSettings.length));
  48. _shape->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 0.2f));
  49. geode->addDrawable(_shape.get());
  50. OSGWidget::fixMaterialState(geode);
  51. _selectionRotateGroup->addChild(geode.get());
  52. }
  53. }