版本:OpenSceneGraph 3.6.5
osgManipulator.TabBoxDragger
是一个基于轴对称的拖拽器,用于在场景中标记复杂几何体的任意表面,可用于选择,移动,旋转等交互式编辑。TabBoxDragger可以被添加到场景图的任何节点中,并且可以与场景图一起进行渲染和更新。
class OSGMANIPULATOR_EXPORT TabBoxDragger : public CompositeDragger
osgManipulator.TabBoxDragger
是一个osgManipulator.CompositeDragger
的子类,组合了八个osgManipulator.Translate1DDragger
、七个osgManipulator.TrackballDragger
和一个 osgManipulator.Scale1DDragger
来创建基于轴对称的拖拽器。
TabBoxDragger();
默认构造函数。创建一个新的实例,初始化后将不可见。
void setupDefaultGeometry();
创建默认的几何体,旋转圆,线框盒子和8个箭头
void setupGeometry(Dragger *draggerComp, const osg::Vec3& corner, const osg::Vec3& oppositeCorner);
使用给定的corner和oppositeCorner参数创建几何体
void setPickCylinderHeight(float height);
设置鼠标拾取圆柱的高度
float getPickCylinderHeight() const;
获取鼠标拾取圆柱的高度
void setRotationMode(osgManipulator::TrackballDragger::RotationMode mode);
设置旋转模式,当前支持单轴旋转和双轴旋转
void setTranslationMode(osgManipulator::Translate1DDragger::MovementMode mode);
设置平移模式,当前支持沿轴方向平移和平面上的平移
void setScaleMode(osgManipulator::Scale1DDragger::ScaleMode mode);
设置缩放模式,当前支持单轴缩放和双轴缩放
void setRotationActive(bool isRotationActive);
启用或禁用旋转操作
bool getRotationActive() const;
获取当前是否启用旋转操作
void setTranslationActive(bool isTranslationActive);
启用或禁用平移操作
bool getTranslationActive() const;
获取当前是否启用平移操作
void setScaleActive(bool isScaleActive);
启用或禁用缩放操作
bool getScaleActive() const;
获取当前是否启用缩放操作
void setPickColor(const osg::Vec4& color);
设置鼠标拾取颜色
const osg::Vec4& getPickColor() const;
获取鼠标拾取颜色
void setHoverColor(const osg::Vec4& color);
设置悬停鼠标颜色
const osg::Vec4& getHoverColor() const;
获取悬停鼠标颜色
void setSelectedColor(const osg::Vec4& color);
设置选中颜色
const osg::Vec4& getSelectedColor() const;
获取选中颜色
void setSelectedAxisColor(const osg::Vec4& color);
设置选中轴的颜色
const osg::Vec4& getSelectedAxisColor() const;
获取选中轴的颜色
TabBoxDragger* dragger = new osgManipulator::TabBoxDragger();
osg::ref_ptr<osg::MatrixTransform> scaleTrans = new osg::MatrixTransform;
scaleTrans->addChild(geode.get());
scaleTrans->addChild(draggingGeode.get());
scaleTrans->addChild(dragger);
// Create main viewer.
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
// Attach event handler.
viewer->addEventHandler(new osgManipulator::TabBoxDraggerCallback(dragger));
// Set the scene data.
viewer->setSceneData(scene.get());
#include <osg/MatrixTransform>
#include <osgViewer/Viewer>
#include <osgManipulator/TabBoxDragger>
#include <osgManipulator/CommandManager>
int main(int argc, char** argv)
{
// Create root node.
osg::ref_ptr<osg::Group> root = new osg::Group;
// Create geometry node.
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0, 0, 0), 1.f)));
// Create dragging geometry node.
osg::ref_ptr<osg::Geode> draggingGeode = new osg::Geode;
// Create scaled transform.
osg::ref_ptr<osg::MatrixTransform> scaleTrans = new osg::MatrixTransform;
scaleTrans->addChild(geode.get());
scaleTrans->addChild(draggingGeode.get());
// Create dragger.
osg::ref_ptr<osgManipulator::TabBoxDragger> dragger = new osgManipulator::TabBoxDragger;
dragger->setupDefaultGeometry();
scaleTrans->addChild(dragger);
// Create command manager.
osg::ref_ptr<osgManipulator::CommandManager> commander = new osgManipulator::CommandManager;
// Attach event handler.
osg::ref_ptr<osgManipulator::TabBoxDraggerCallback> draggerCallback = new osgManipulator::TabBoxDraggerCallback(dragger.get());
draggerCallback->setCommandManager(commander.get());
root->addChild(draggerCallback);
// Set the scene data.
viewer->setSceneData(root.get());
// Set up the camera manipulators.
viewer->setCameraManipulator(new osgGA::TrackballManipulator);
// Run the viewer.
return viewer->run();
}