You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.2 KiB
C++

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2011
*
* 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.
*/
#ifndef DRAGGERMANAGER_H
#define DRAGGERMANAGER_H
#include <vector>
#include <osg/observer_ptr>
#include <osg/MatrixTransform>
#include <osg/Switch>
#include <osgManipulator/Dragger>
#include <osg/StateAttribute>
#include <osg/gl>
#include <string>
#include <map>
#include <vector>
typedef std::vector<std::string> StringList;
typedef std::map< std::string, osg::observer_ptr<osg::MatrixTransform> > SelectionMap;
typedef std::vector< osg::observer_ptr<osg::MatrixTransform> > SelectionList;
namespace osgDragger
{
class DraggerManager : public osg::Referenced
{
public:
DraggerManager();
static DraggerManager* Instance();
virtual void addDragger(osgManipulator::Dragger* dr, bool active);
virtual void removeDragger(osgManipulator::Dragger* dr);
virtual void removeDragger(std::string& str);
//是否存在激活的dragger
bool IsExistActiveDragger();
virtual void setActiveDragger(const std::string& str);
virtual void setSelections(SelectionList& sl);
void setIntersectionMask(osg::Node::NodeMask mask);
SelectionList getSelections(){return _selections;}
osg::Switch* getRoot();
virtual void reset();
virtual void addSelectionToDragger(osg::MatrixTransform* mt, osgManipulator::Dragger* dr);/////////////////rewrite function
//设置dragger的旋转矩阵
void SetDraggerRotateMatrix(osg::Matrix& mt) {_rotateMt = mt;}
void setTransDraggerStep(double step);
void setRotateDraggerStep(double step);
protected:
virtual ~DraggerManager();
virtual void setSelectionsToDragger(SelectionList& sl, osgManipulator::Dragger* dr);
virtual void updateDragger(osgManipulator::Dragger* pre, osgManipulator::Dragger* cur);
private:
osg::ref_ptr<osg::Switch> _root;
osg::observer_ptr<osgManipulator::Dragger> _activeDragger;
osg::Node::NodeMask _traversalMask;
SelectionList _selections;
osg::Matrix _rotateMt;
};
class ClearDepth : public osg::StateAttribute
{
public:
ClearDepth(bool isUse = true){m_bIsUse = isUse;}
ClearDepth(const ClearDepth& cf, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::StateAttribute(cf,copyop)
{
m_bIsUse = cf.m_bIsUse;
}
META_StateAttribute( osg, ClearDepth, (osg::StateAttribute::Type)0x1000 );
virtual int compare( const osg::StateAttribute& sa ) const
{
COMPARE_StateAttribute_Types(ClearDepth, sa)
return 0;
}
virtual void apply(osg::State& state) const
{
if(m_bIsUse == true)
{
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_BLEND);
}
else
{
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
}
}
protected:
virtual ~ClearDepth(){}
bool m_bIsUse;
};
}
#endif