| 770 | | |
| | 772 | class DraggerVolumeTileCallback : public osgManipulator::DraggerCallback |
| | 773 | { |
| | 774 | public: |
| | 775 | |
| | 776 | DraggerVolumeTileCallback(osgVolume::VolumeTile* volume, osgVolume::Locator* locator): |
| | 777 | _volume(volume), |
| | 778 | _locator(locator) {} |
| | 779 | |
| | 780 | |
| | 781 | virtual bool receive(const osgManipulator::MotionCommand& command); |
| | 782 | |
| | 783 | |
| | 784 | osg::observer_ptr<osgVolume::VolumeTile> _volume; |
| | 785 | osg::ref_ptr<osgVolume::Locator> _locator; |
| | 786 | |
| | 787 | osg::Matrix _startMotionMatrix; |
| | 788 | |
| | 789 | osg::Matrix _localToWorld; |
| | 790 | osg::Matrix _worldToLocal; |
| | 791 | |
| | 792 | }; |
| | 793 | |
| | 794 | bool DraggerVolumeTileCallback::receive(const osgManipulator::MotionCommand& command) |
| | 795 | { |
| | 796 | if (!_locator) return false; |
| | 797 | |
| | 798 | switch (command.getStage()) |
| | 799 | { |
| | 800 | case osgManipulator::MotionCommand::START: |
| | 801 | { |
| | 802 | // Save the current matrix |
| | 803 | _startMotionMatrix = _locator->getTransform(); |
| | 804 | |
| | 805 | // Get the LocalToWorld and WorldToLocal matrix for this node. |
| | 806 | osg::NodePath nodePathToRoot; |
| | 807 | osgManipulator::computeNodePathToRoot(*_volume,nodePathToRoot); |
| | 808 | _localToWorld = _startMotionMatrix * osg::computeLocalToWorld(nodePathToRoot); |
| | 809 | _worldToLocal = osg::Matrix::inverse(_localToWorld); |
| | 810 | |
| | 811 | return true; |
| | 812 | } |
| | 813 | case osgManipulator::MotionCommand::MOVE: |
| | 814 | { |
| | 815 | // Transform the command's motion matrix into local motion matrix. |
| | 816 | osg::Matrix localMotionMatrix = _localToWorld * command.getWorldToLocal() |
| | 817 | * command.getMotionMatrix() |
| | 818 | * command.getLocalToWorld() * _worldToLocal; |
| | 819 | |
| | 820 | // Transform by the localMotionMatrix |
| | 821 | _locator->setTransform(localMotionMatrix * _startMotionMatrix); |
| | 822 | |
| | 823 | // osg::notify(osg::NOTICE)<<"New locator matrix "<<_locator->getTransform()<<std::endl; |
| | 824 | |
| | 825 | return true; |
| | 826 | } |
| | 827 | case osgManipulator::MotionCommand::FINISH: |
| | 828 | { |
| | 829 | _volume->setDirty(true); |
| | 830 | |
| | 831 | return true; |
| | 832 | } |
| | 833 | case osgManipulator::MotionCommand::NONE: |
| | 834 | default: |
| | 835 | return false; |
| | 836 | } |
| | 837 | } |
| | 1467 | osg::ref_ptr<osg::Node> loadedModel = volume.get(); |
| | 1468 | |
| | 1469 | if (useManipulator) |
| | 1470 | { |
| | 1471 | osg::ref_ptr<osg::Group> group = new osg::Group; |
| | 1472 | |
| | 1473 | osg::ref_ptr<osgManipulator::TabBoxDragger> dragger = new osgManipulator::TabBoxDragger; |
| | 1474 | dragger->setupDefaultGeometry(); |
| | 1475 | dragger->setHandleEvents(true); |
| | 1476 | dragger->addDraggerCallback(new DraggerVolumeTileCallback(tile.get(), tile->getLocator())); |
| | 1477 | dragger->setMatrix(osg::Matrix::translate(0.5,0.5,0.5)*tile->getLocator()->getTransform()); |
| | 1478 | |
| | 1479 | |
| | 1480 | group->addChild(dragger.get()); |
| | 1481 | |
| | 1482 | //dragger->addChild(volume.get()); |
| | 1483 | |
| | 1484 | group->addChild(volume.get()); |
| | 1485 | |
| | 1486 | loadedModel = group; |
| | 1487 | } |
| | 1488 | |
| | 1489 | |