Completed refactor of osgManipulator, key changes are:

Selection is now just a typedef of osg::MatrixTransform, and is deprecated

   CommandManager is shell class that just sets values directly on Dragger, and is deprecated

   Dragger now has list of DraggerCallback that takes over the roll of tracking changes to the Dragger, and
   allows users to track the dragger in any way they wish.

   Dragger now has a convinience method making MatrixTransforms track a dragger.

   Selection and CommandManager are no longer required for use of osgManipulator and are kept around for backwards compatibility.
This commit is contained in:
Robert Osfield
2009-07-01 14:01:09 +00:00
parent 4e305cf46b
commit 2525bb5d06
16 changed files with 476 additions and 414 deletions

View File

@@ -38,7 +38,6 @@ ADD_LIBRARY(${LIB_NAME}
${LIB_PUBLIC_HEADERS}
AntiSquish.cpp
Command.cpp
CommandManager.cpp
Constraint.cpp
Dragger.cpp
Projector.cpp
@@ -47,7 +46,6 @@ ADD_LIBRARY(${LIB_NAME}
Scale1DDragger.cpp
Scale2DDragger.cpp
ScaleAxisDragger.cpp
Selection.cpp
TabBoxDragger.cpp
TabPlaneDragger.cpp
TabPlaneTrackballDragger.cpp

View File

@@ -13,7 +13,6 @@
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#include <osgManipulator/Command>
#include <osgManipulator/Selection>
#include <osgManipulator/Constraint>
#include <algorithm>

View File

@@ -1,62 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#include <osgManipulator/CommandManager>
#include <osgManipulator/Command>
using namespace osgManipulator;
CommandManager::CommandManager()
{
}
CommandManager::~CommandManager()
{
}
bool CommandManager::connect(Dragger& dragger, Selection& selection)
{
dragger.addSelection(&selection);
return true;
}
bool CommandManager::connect(Dragger& dragger, Constraint& constraint)
{
dragger.addConstraint(&constraint);
return true;
}
bool CommandManager::disconnect(Dragger& dragger)
{
dragger.getConstraints().clear();
dragger.getSelections().clear();
return true;
}
CommandManager::Selections CommandManager::getConnectedSelections(Dragger& dragger)
{
Selections selections;
for(Dragger::Selections::iterator itr = dragger.getSelections().begin();
itr != dragger.getSelections().end();
++itr)
{
selections.push_back(*itr);
}
return selections;
}

View File

@@ -14,6 +14,7 @@
#include <osgManipulator/Constraint>
#include <osgManipulator/Command>
#include <osgManipulator/Dragger>
#include <osg/Vec2d>
#include <math.h>

View File

@@ -20,6 +20,78 @@
using namespace osgManipulator;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// computeNodePathToRoot
//
void osgManipulator::computeNodePathToRoot(osg::Node& node, osg::NodePath& np)
{
np.clear();
osg::NodePathList nodePaths = node.getParentalNodePaths();
if (!nodePaths.empty())
{
np = nodePaths.front();
if (nodePaths.size()>1)
{
osg::notify(osg::NOTICE)<<"osgManipulator::computeNodePathToRoot(,) taking first parent path, ignoring others."<<std::endl;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// DraggerTransformCallback
//
DraggerTransformCallback::DraggerTransformCallback(osg::MatrixTransform* transform):
_transform(transform)
{
}
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:
{
// 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;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// PointerInfo
@@ -57,6 +129,15 @@ Dragger::Dragger() :
{
_parentDragger = this;
getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);
_selfUpdater = new DraggerTransformCallback(this);
}
Dragger::Dragger(const Dragger& rhs, const osg::CopyOp& copyop):
osg::MatrixTransform(rhs, copyop)
{
osg::notify(osg::NOTICE)<<"CompositeDragger::CompositeDragger(const CompositeDragger& rhs, const osg::CopyOp& copyop) not Implemented yet."<<std::endl;
}
Dragger::~Dragger()
@@ -101,39 +182,41 @@ void Dragger::removeConstraint(Constraint* constraint)
}
}
void Dragger::objectDeleted(void* object)
void Dragger::addTransformUpdating(osg::MatrixTransform* transform)
{
removeSelection(reinterpret_cast<Selection*>(object));
addDraggerCallback(new DraggerTransformCallback(transform));
}
void Dragger::addSelection(Selection* selection)
void Dragger::removeTransformUpdating(osg::MatrixTransform* transform)
{
// check to make sure constaint hasn't already been attached.
for(Selections::iterator itr = _selections.begin();
itr != _selections.end();
for(Dragger::DraggerCallbacks::iterator itr = _draggerCallbacks.begin();
itr != _draggerCallbacks.end();
++itr)
{
if (*itr == selection) return;
}
selection->addObserver(this);
_selections.push_back(selection);
}
void Dragger::removeSelection(Selection* selection)
{
for(Selections::iterator itr = _selections.begin();
itr != _selections.end();
++itr)
{
if (*itr == selection)
DraggerCallback* dc = itr->get();
DraggerTransformCallback* dtc = dynamic_cast<DraggerTransformCallback*>(dc);
if (dtc && dtc->getTransform()==transform)
{
selection->removeObserver(this);
_selections.erase(itr);
return;
_draggerCallbacks.erase(itr);
}
}
}
void Dragger::addDraggerCallback(DraggerCallback* dc)
{
for(DraggerCallbacks::iterator itr = _draggerCallbacks.begin();
itr != _draggerCallbacks.end();
++itr)
{
if (*itr == dc) return;
}
_draggerCallbacks.push_back(dc);
}
void Dragger::removeDraggerCallback(DraggerCallback* dc)
{
}
@@ -155,7 +238,7 @@ void Dragger::traverse(osg::NodeVisitor& nv)
return;
}
Selection::traverse(nv);
MatrixTransform::traverse(nv);
}
bool Dragger::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
@@ -231,6 +314,12 @@ bool Dragger::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&
return handled;
}
bool Dragger::receive(const MotionCommand& command)
{
if (_selfUpdater.valid()) return _selfUpdater->receive(command);
else return false;
}
void Dragger::dispatch(MotionCommand& command)
{
// apply any constraints
@@ -244,9 +333,9 @@ void Dragger::dispatch(MotionCommand& command)
// move self
getParentDragger()->receive(command);
// then run through any selections
for(Selections::iterator itr = getParentDragger()->getSelections().begin();
itr != getParentDragger()->getSelections().end();
for(DraggerCallbacks::iterator itr = getParentDragger()->getDraggerCallbacks().begin();
itr != getParentDragger()->getDraggerCallbacks().end();
++itr)
{
(*itr)->receive(command);
@@ -258,6 +347,11 @@ void Dragger::dispatch(MotionCommand& command)
//
// CompositeDragger
//
CompositeDragger::CompositeDragger(const CompositeDragger& rhs, const osg::CopyOp& copyop):
Dragger(rhs, copyop)
{
osg::notify(osg::NOTICE)<<"CompositeDragger::CompositeDragger(const CompositeDragger& rhs, const osg::CopyOp& copyop) not Implemented yet."<<std::endl;
}
bool CompositeDragger::handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{

View File

@@ -1,86 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#include <osgManipulator/Selection>
#include <osgManipulator/Command>
#include <osg/Notify>
#include <algorithm>
using namespace osgManipulator;
void osgManipulator::computeNodePathToRoot(osg::Node& node, osg::NodePath& np)
{
np.clear();
osg::NodePathList nodePaths = node.getParentalNodePaths();
if (!nodePaths.empty())
{
np = nodePaths.front();
if (nodePaths.size()>1)
{
osg::notify(osg::NOTICE)<<"osgManipulator::computeNodePathToRoot(,) taking first parent path, ignoring others."<<std::endl;
}
}
}
Selection::Selection()
{
}
Selection::~Selection()
{
}
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;
}
}