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.

153 lines
4.5 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/* -*-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 BASEDRAGGER_H
#define BASEDRAGGER_H
#include <osgManipulator/Translate1DDragger>
#include <osgManipulator/Translate2DDragger>
#include <osgManipulator/RotateCylinderDragger>
#include <osgManipulator/RotateSphereDragger>
#include <osgManipulator/Scale1DDragger>
#include <osg/Node>
//#define OSGDRAGGER_DYNAMIC
//#include "Exports.h"
namespace osgDragger
{
//pointDragger
void setMaterialColorExtend(const osg::Vec4& color, osg::Node& node);
class PointDragger : public osgManipulator::Dragger
{
public:
PointDragger();
META_OSGMANIPULATOR_Object(osgDragger, PointDragger);
//操作器响应函数在Translate1DDragger下的handle()中响应用来分发Command
virtual void dispatch(osgManipulator::MotionCommand& command);
/** Handle pick events on dragger and generate TranslateInLine commands. */
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Set/Get color for dragger. */
inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
inline const osg::Vec4& getColor() const { return _color; }
/** Set/Get pick color for dragger. Pick color is color of the dragger when picked.
It gives a visual feedback to show that the dragger has been picked. */
inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
inline const osg::Vec4& getPickColor() const { return _pickColor; }
protected:
virtual ~PointDragger() {}
osg::Vec3 _startPickedPt;
osg::Vec4 _color;
osg::Vec4 _pickColor;
};
class Move1DDragger : public osgManipulator::Translate1DDragger
{
public:
Move1DDragger();
Move1DDragger(const osg::Vec3d& s, const osg::Vec3d& e);
META_OSGMANIPULATOR_Object(osgDragger,Move1DDragger);
//操作器响应函数在Translate1DDragger下的handle()中响应用来分发Command
virtual void dispatch(osgManipulator::MotionCommand& command);
/** Handle pick events on dragger and generate TranslateInLine commands. */
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
void SetStepLenght(double step){ _translationStep = step;}
private:
double _translationStep;
};
class Move2DDragger : public osgManipulator::Translate2DDragger
{
public:
Move2DDragger();
Move2DDragger(const osg::Plane& plane);
META_OSGMANIPULATOR_Object(osgDragger,Move2DDragger);
virtual void dispatch(osgManipulator::MotionCommand& command);
};
class CylinderDragger : public osgManipulator::RotateCylinderDragger
{
public:
CylinderDragger();
META_OSGMANIPULATOR_Object(osgDragger,CylinderDragger);
void SetStepLenght(double step){ _rotateStep = step;}
protected:
virtual bool handle(const osgManipulator::PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) override;
virtual void dispatch(osgManipulator::MotionCommand& command);
double _rotateStep;
};
class SphereDragger : public osgManipulator::RotateSphereDragger
{
public:
SphereDragger();
META_OSGMANIPULATOR_Object(osgDragger,SphereDragger);
virtual void dispatch(osgManipulator::MotionCommand& command);
};
class BaseDragger : public osgManipulator::CompositeDragger
{
public:
META_OSGMANIPULATOR_Object(osgDragger,BaseDragger)
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
virtual bool handle(const osgManipulator::PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
virtual void handlePushMessage(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa){};
virtual void handleDragMessage(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa){};
virtual void handleReleaseMessage(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
void setIntersectionCamera(osg::Camera* camera);
protected:
BaseDragger();
virtual ~BaseDragger();
osg::observer_ptr<osg::Camera> _intersectionCamera;
};
} //end namespace
#endif // BASEDRAGGER_H