void Dragger::dispatch(MotionCommand& command) { // apply any constraints for(Constraints::iterator itr = _constraints.begin(); itr != _constraints.end(); ++itr) { command.accept(*(*itr)); } // apply any constraints of parent dragger. if (getParentDragger()!=this) { for(Constraints::iterator itr = getParentDragger()->getConstraints().begin(); itr != getParentDragger()->getConstraints().end(); ++itr) { command.accept(*(*itr)); } } // move self getParentDragger()->receive(command); // pass on movement to any dragger callbacks for(DraggerCallbacks::iterator itr = getParentDragger()->getDraggerCallbacks().begin(); itr != getParentDragger()->getDraggerCallbacks().end(); ++itr) { command.accept(*(*itr)); } }
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; } }