bool DraggerTransformCallback::receive(const MotionCommand& command) { if (!_transform) return false; switch (command.getStage()) { case MotionCommand::START: { // Save the current matrix _startMotionMatrix = _transform->getMatrix(); // Get the LocalToWorld and WorldToLocal matrix for this node. osg::NodePath nodePathToRoot; computeNodePathToRoot(*_transform,nodePathToRoot); _localToWorld = osg::computeLocalToWorld(nodePathToRoot); _worldToLocal = osg::Matrix::inverse(_localToWorld); return true; } case MotionCommand::MOVE: { //OSG_NOTICE<<"MotionCommand::MOVE "<<command.getMotionMatrix()<<std::endl; // Transform the command's motion matrix into local motion matrix. osg::Matrix localMotionMatrix = _localToWorld * command.getWorldToLocal() * command.getMotionMatrix() * command.getLocalToWorld() * _worldToLocal; // Transform by the localMotionMatrix _transform->setMatrix(localMotionMatrix * _startMotionMatrix); return true; } case MotionCommand::FINISH: { return true; } case MotionCommand::NONE: default: return false; } }
bool Selection::receive(const MotionCommand& command) { switch (command.getStage()) { case MotionCommand::START: { // Save the current matrix _startMotionMatrix = getMatrix(); // Get the LocalToWorld and WorldToLocal matrix for this node. osg::NodePath nodePathToRoot; computeNodePathToRoot(*this,nodePathToRoot); _localToWorld = osg::computeLocalToWorld(nodePathToRoot); _worldToLocal = osg::Matrix::inverse(_localToWorld); return true; } case MotionCommand::MOVE: { // Transform the command's motion matrix into local motion matrix. osg::Matrix localMotionMatrix = _localToWorld * command.getWorldToLocal() * command.getMotionMatrix() * command.getLocalToWorld() * _worldToLocal; // Transform by the localMotionMatrix setMatrix(localMotionMatrix * _startMotionMatrix); return true; } case MotionCommand::FINISH: { return true; } case MotionCommand::NONE: default: return false; } }