|
|
|
|
|
|
|
|
/* -*-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 MYDRAGGER_H
|
|
|
#define MYDRAGGER_H
|
|
|
|
|
|
|
|
|
#include "BaseDragger.h"
|
|
|
|
|
|
#include <osg/AutoTransform>
|
|
|
#include <osg/Geometry>
|
|
|
#include <osg/Geode>
|
|
|
#include <osg/ClipNode>
|
|
|
#include <osg/LineWidth>
|
|
|
#include <osg/ShapeDrawable>
|
|
|
#include <osg/PolygonMode>
|
|
|
|
|
|
#include <osgText/Font>
|
|
|
#include <osgText/Text>
|
|
|
|
|
|
#include <osgManipulator/AntiSquish>
|
|
|
|
|
|
#include <osg/Material>
|
|
|
#include <osg/Light>
|
|
|
#include <osg/BlendFunc>
|
|
|
#include <osg/Depth>
|
|
|
|
|
|
#include <osgUtil/SmoothingVisitor>
|
|
|
#include "../Assist/SceneGraphDef.h"
|
|
|
|
|
|
namespace osgDragger
|
|
|
{
|
|
|
|
|
|
osg::Geode* createPlane();
|
|
|
|
|
|
osg::Geode* createAxis(std::string tex, osgText::Font* font, osg::Vec4 color);
|
|
|
osg::Geode* InsertAxis(float size);
|
|
|
|
|
|
osg::Drawable* InsertCircle(float radius, unsigned int numSegments);
|
|
|
|
|
|
template<typename Dragger1DType, typename Dragger2DType>
|
|
|
class TemplateMoveDragger : public BaseDragger
|
|
|
{
|
|
|
public:
|
|
|
|
|
|
typedef Dragger1DType LineDragger;
|
|
|
typedef Dragger2DType PlaneDragger;
|
|
|
|
|
|
TemplateMoveDragger(void)
|
|
|
{
|
|
|
float pixelSize = 80.0f;
|
|
|
osg::ref_ptr<osg::MatrixTransform> scaler = new osg::MatrixTransform;
|
|
|
scaler->setMatrix(osg::Matrix::scale(pixelSize, pixelSize, pixelSize)); //¸ù¾ÝÏñËØÀ´Ëõ·Å
|
|
|
|
|
|
osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform;
|
|
|
at->setAutoScaleToScreen(true);
|
|
|
at->addChild(scaler);
|
|
|
|
|
|
osg::ref_ptr<osgManipulator::AntiSquish> as = new osgManipulator::AntiSquish;
|
|
|
as->addChild(at);
|
|
|
addChild(as);
|
|
|
|
|
|
_xDragger = new LineDragger(osg::Vec3(0.0,0.0,0.0),
|
|
|
osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(_xDragger.get());
|
|
|
addDragger(_xDragger.get());
|
|
|
|
|
|
_yDragger = new LineDragger(osg::Vec3(0.0,0.0,0.0),
|
|
|
osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(_yDragger.get());
|
|
|
addDragger(_yDragger.get());
|
|
|
|
|
|
_zDragger = new LineDragger(osg::Vec3(0.0,0.0,0.0),
|
|
|
osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(_zDragger.get());
|
|
|
addDragger(_zDragger.get());
|
|
|
|
|
|
//_xoyDragger = new PlaneDragger();
|
|
|
//scaler->addChild(_xoyDragger.get());
|
|
|
//addDragger(_xoyDragger.get());
|
|
|
|
|
|
//_xozDragger = new PlaneDragger();
|
|
|
//scaler->addChild(_xozDragger.get());
|
|
|
//addDragger(_xozDragger.get());
|
|
|
|
|
|
//_yozDragger = new PlaneDragger();
|
|
|
//scaler->addChild(_yozDragger.get());
|
|
|
//addDragger(_yozDragger.get());
|
|
|
|
|
|
setParentDragger(getParentDragger());
|
|
|
}
|
|
|
|
|
|
virtual void setupDefaultGeometry()
|
|
|
{
|
|
|
osg::Vec4 xColor = osg::Vec4(1.0, 0.0, 0.0, 1.0);
|
|
|
osg::Vec4 yColor = osg::Vec4(0.0, 1.0, 0.0, 1.0);
|
|
|
osg::Vec4 zColor = osg::Vec4(0.0, 0.0, 1.0, 1.0);
|
|
|
|
|
|
osg::Vec4 pickColor = osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
|
|
|
|
|
|
osg::ref_ptr<osgText::Font> font = osgText::readFontFile("font/times.ttf"); //simsun.ttc arial.ttf font\\times.ttf
|
|
|
|
|
|
_xDragger->addChild( createAxis("x", font.get(), xColor));
|
|
|
_yDragger->addChild( createAxis("y", font.get(), yColor));
|
|
|
_zDragger->addChild( createAxis("z", font.get(), zColor));
|
|
|
|
|
|
_xDragger->setColor(xColor);
|
|
|
_yDragger->setColor(yColor);
|
|
|
_zDragger->setColor(zColor);
|
|
|
|
|
|
// Rotate X-axis dragger appropriately.
|
|
|
{
|
|
|
osg::Quat rotation;
|
|
|
rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(1.0f, 0.0f, 0.0f));
|
|
|
_xDragger->setMatrix(osg::Matrix(rotation));
|
|
|
}
|
|
|
|
|
|
// Rotate Y-axis dragger appropriately.
|
|
|
{
|
|
|
osg::Quat rotation;
|
|
|
rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(0.0f, 1.0f, 0.0f));
|
|
|
_yDragger->setMatrix(osg::Matrix(rotation));
|
|
|
}
|
|
|
|
|
|
|
|
|
////xoz->xoy
|
|
|
//{
|
|
|
// osg::Quat rotation;
|
|
|
// rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(0.0f, 1.0f, 0.0f));
|
|
|
// _xoyDragger->setMatrix(osg::Matrix(rotation));
|
|
|
//}
|
|
|
|
|
|
////xoz->yoz
|
|
|
//{
|
|
|
// osg::Quat rotation;
|
|
|
// rotation.makeRotate(osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 1.0f, 0.0f));
|
|
|
// _yozDragger->setMatrix(osg::Matrix(rotation));
|
|
|
//}
|
|
|
//
|
|
|
//{
|
|
|
// osg::ref_ptr<osg::Geode> plane = createPlane();
|
|
|
|
|
|
// _xoyDragger->addChild( plane.get() );
|
|
|
// _yozDragger->addChild( plane.get() );
|
|
|
// _xozDragger->addChild( plane.get() );
|
|
|
|
|
|
// _xoyDragger->setColor(zColor);
|
|
|
// _yozDragger->setColor(xColor);
|
|
|
// _xozDragger->setColor(yColor);
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
virtual ~TemplateMoveDragger(void) {}
|
|
|
|
|
|
osg::ref_ptr< LineDragger > _xDragger;
|
|
|
osg::ref_ptr< LineDragger > _yDragger;
|
|
|
osg::ref_ptr< LineDragger > _zDragger;
|
|
|
|
|
|
osg::ref_ptr< PlaneDragger > _yozDragger;
|
|
|
osg::ref_ptr< PlaneDragger > _xoyDragger;
|
|
|
osg::ref_ptr< PlaneDragger > _xozDragger;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
//Ö¸¶¨·½ÏòÒÆ¶¯Í϶¯Æ÷
|
|
|
template<typename Dragger1DType, typename Dragger2DType>
|
|
|
class TemplateMoveDirDragger : public BaseDragger
|
|
|
{
|
|
|
public:
|
|
|
|
|
|
typedef Dragger1DType LineDragger;
|
|
|
typedef Dragger2DType PlaneDragger;
|
|
|
|
|
|
TemplateMoveDirDragger(void)
|
|
|
{
|
|
|
float pixelSize = 80.0f;
|
|
|
osg::ref_ptr<osg::MatrixTransform> scaler = new osg::MatrixTransform;
|
|
|
scaler->setMatrix(osg::Matrix::scale(pixelSize, pixelSize, pixelSize)); //¸ù¾ÝÏñËØÀ´Ëõ·Å
|
|
|
|
|
|
osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform;
|
|
|
at->setAutoScaleToScreen(true);
|
|
|
at->addChild(scaler);
|
|
|
|
|
|
osg::ref_ptr<osgManipulator::AntiSquish> as = new osgManipulator::AntiSquish;
|
|
|
as->addChild(at);
|
|
|
addChild(as);
|
|
|
|
|
|
m_Dragger = new LineDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(m_Dragger.get());
|
|
|
addDragger(m_Dragger.get());
|
|
|
|
|
|
setParentDragger(getParentDragger());
|
|
|
}
|
|
|
|
|
|
virtual void setupDefaultGeometry()
|
|
|
{
|
|
|
osg::Vec4 Color = osg::Vec4(1.0, 0.0, 0.0, 1.0);
|
|
|
osg::Vec4 pickColor = osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
|
|
|
|
|
|
osg::ref_ptr<osgText::Font> font = osgText::readFontFile("font/times.ttf"); //simsun.ttc arial.ttf font\\times.ttf
|
|
|
|
|
|
m_Dragger->addChild( createAxis("", font.get(), Color));
|
|
|
m_Dragger->setColor(Color);
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
virtual ~TemplateMoveDirDragger(void) {}
|
|
|
|
|
|
osg::ref_ptr< LineDragger > m_Dragger;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
//Ö¸¶¨·½ÏòÒÆ¶¯£«ÈÆÖáÐýתÍ϶¯Æ÷
|
|
|
template<typename DraggerType1, typename DraggerType2>
|
|
|
class TemplateMoveDirAndRotateDragger : public BaseDragger
|
|
|
{
|
|
|
public:
|
|
|
typedef DraggerType1 LineDragger;
|
|
|
typedef DraggerType2 RotateDragger;
|
|
|
|
|
|
TemplateMoveDirAndRotateDragger(void)
|
|
|
{
|
|
|
float pixelSize = 80.0f;
|
|
|
osg::ref_ptr<osg::MatrixTransform> scaler = new osg::MatrixTransform;
|
|
|
scaler->setMatrix(osg::Matrix::scale(pixelSize, pixelSize, pixelSize));
|
|
|
|
|
|
osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform;
|
|
|
at->setAutoScaleToScreen(true);
|
|
|
at->addChild(scaler);
|
|
|
|
|
|
osg::ref_ptr<osgManipulator::AntiSquish> as = new osgManipulator::AntiSquish;
|
|
|
as->addChild(at);
|
|
|
addChild(as);
|
|
|
|
|
|
m_Dragger = new LineDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(m_Dragger.get());
|
|
|
addDragger(m_Dragger.get());
|
|
|
|
|
|
m_RotateZ = new RotateDragger;
|
|
|
scaler->addChild(m_RotateZ.get());
|
|
|
addDragger(m_RotateZ.get());
|
|
|
|
|
|
setParentDragger(getParentDragger());
|
|
|
}
|
|
|
|
|
|
virtual void setupDefaultGeometry()
|
|
|
{
|
|
|
osg::Vec4 Color = osg::Vec4(1.0, 0.0, 0.0, 1.0);
|
|
|
osg::Vec4 pickColor = osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f);
|
|
|
osg::ref_ptr<osgText::Font> font = osgText::readFontFile("font/times.ttf"); //simsun.ttc arial.ttf font\\times.ttf
|
|
|
m_Dragger->addChild( createAxis("", font.get(), Color));
|
|
|
m_Dragger->setColor(Color);
|
|
|
|
|
|
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
|
|
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
|
osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
|
|
|
hints->setCreateTop(true);
|
|
|
hints->setCreateBottom(true);
|
|
|
hints->setCreateBackFace(true);
|
|
|
|
|
|
osg::ref_ptr<osg::Cylinder> cylinder = new osg::Cylinder;
|
|
|
cylinder->setHeight(0.1f);
|
|
|
osg::ref_ptr<osg::ShapeDrawable> cylinderDrawable = new osg::ShapeDrawable(cylinder,hints);
|
|
|
geode->addDrawable(cylinderDrawable);
|
|
|
osgManipulator::setDrawableToAlwaysCull(*cylinderDrawable);
|
|
|
geode->addDrawable(InsertCircle(0.5f, 150));
|
|
|
|
|
|
osg::ref_ptr<osg::LineWidth> lineWidth = new osg::LineWidth;
|
|
|
lineWidth->setWidth(2.0f);
|
|
|
geode->getOrCreateStateSet()->setAttributeAndModes(lineWidth.get(), osg::StateAttribute::ON);
|
|
|
m_RotateZ->addChild(geode);
|
|
|
|
|
|
osg::Matrix mat;
|
|
|
mat.setTrans(osg::Vec3d(0,0,1.0));
|
|
|
m_RotateZ->setMatrix(mat);
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
virtual ~TemplateMoveDirAndRotateDragger(void) {}
|
|
|
|
|
|
osg::ref_ptr<LineDragger> m_Dragger;
|
|
|
osg::ref_ptr<RotateDragger> m_RotateZ;
|
|
|
};
|
|
|
|
|
|
//2DÒÆ¶¯Í϶¯Æ÷¼ÓÐýת
|
|
|
template<typename Dragger1DType, typename Dragger2DType>
|
|
|
class TemplateMoveDragger2D : public BaseDragger
|
|
|
{
|
|
|
public:
|
|
|
typedef Dragger1DType LineDragger;
|
|
|
typedef Dragger2DType RotateDragger;
|
|
|
|
|
|
TemplateMoveDragger2D(void)
|
|
|
{
|
|
|
osg::ref_ptr<osgManipulator::AntiSquish> as = new osgManipulator::AntiSquish;
|
|
|
this->addChild(as);
|
|
|
|
|
|
osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform;
|
|
|
at->setAutoScaleToScreen(true);
|
|
|
as->addChild(at);
|
|
|
|
|
|
osg::ref_ptr<osg::MatrixTransform> scaler = new osg::MatrixTransform;
|
|
|
scaler->setMatrix(osg::Matrix::scale(80.0f, 80.0f, 80.0f));
|
|
|
at->addChild(scaler);
|
|
|
|
|
|
m_TranslateX1 = new LineDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(m_TranslateX1.get());
|
|
|
addDragger(m_TranslateX1.get());
|
|
|
|
|
|
m_TranslateX2 = new LineDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(m_TranslateX2.get());
|
|
|
addDragger(m_TranslateX2.get());
|
|
|
|
|
|
m_TranslateY1 = new LineDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(m_TranslateY1.get());
|
|
|
addDragger(m_TranslateY1.get());
|
|
|
|
|
|
m_TranslateY2 = new LineDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
|
|
|
scaler->addChild(m_TranslateY2.get());
|
|
|
addDragger(m_TranslateY2.get());
|
|
|
|
|
|
m_RotateZ = new RotateDragger;
|
|
|
scaler->addChild(m_RotateZ.get());
|
|
|
addDragger(m_RotateZ.get());
|
|
|
|
|
|
setParentDragger(getParentDragger());
|
|
|
}
|
|
|
|
|
|
virtual void setupDefaultGeometry()
|
|
|
{
|
|
|
osg::Quat rotation;
|
|
|
osg::Vec4 Color1 = osg::Vec4(0.0, 0.0, 1.0, 1.0);
|
|
|
osg::Vec4 Color2 = osg::Vec4(0.0, 1.0, 0.0, 1.0);
|
|
|
osg::Vec4 Color3 = osg::Vec4(0.0, 1.0, 1.0, 1.0);
|
|
|
osg::ref_ptr<osgText::Font> font = osgText::readFontFile("font/times.ttf");
|
|
|
|
|
|
m_TranslateX1->addChild(createAxis("", font.get(), Color1));
|
|
|
//m_TranslateX1->setColor(Color1);
|
|
|
rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(1.0f, 0.0f, 0.0f));
|
|
|
m_TranslateX1->setMatrix(osg::Matrix(rotation));
|
|
|
|
|
|
m_TranslateX2->addChild(createAxis("", font.get(), Color1));
|
|
|
//m_TranslateX2->setColor(Color1);
|
|
|
rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(-1.0f, 0.0f, 0.0f));
|
|
|
m_TranslateX2->setMatrix(osg::Matrix(rotation));
|
|
|
|
|
|
m_TranslateY1->addChild(createAxis("", font.get(), Color2));
|
|
|
//m_TranslateY1->setColor(Color2);
|
|
|
rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(0.0f, 1.0f, 0.0f));
|
|
|
m_TranslateY1->setMatrix(osg::Matrix(rotation));
|
|
|
|
|
|
m_TranslateY2->addChild(createAxis("", font.get(), Color2));
|
|
|
//m_TranslateY2->setColor(Color2);
|
|
|
rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(0.0f, -1.0f, 0.0f));
|
|
|
m_TranslateY2->setMatrix(osg::Matrix(rotation));
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
|
|
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
|
osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
|
|
|
hints->setCreateTop(false);
|
|
|
hints->setCreateBottom(false);
|
|
|
hints->setCreateBackFace(false);
|
|
|
|
|
|
osg::ref_ptr<osg::Cylinder> cylinder = new osg::Cylinder;
|
|
|
cylinder->setHeight(0.515f);
|
|
|
osg::ref_ptr<osg::ShapeDrawable> cylinderDrawable = new osg::ShapeDrawable(cylinder,hints);
|
|
|
geode->addDrawable(cylinderDrawable);
|
|
|
osgManipulator::setDrawableToAlwaysCull(*cylinderDrawable);
|
|
|
geode->addDrawable(InsertCircle(1.0f, 150));
|
|
|
|
|
|
osg::ref_ptr<osg::LineWidth> lineWidth = new osg::LineWidth;
|
|
|
lineWidth->setWidth(1.4f);
|
|
|
geode->getOrCreateStateSet()->setAttributeAndModes(lineWidth.get(), osg::StateAttribute::ON);
|
|
|
m_RotateZ->addChild(geode);
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
virtual ~TemplateMoveDragger2D(void) {}
|
|
|
|
|
|
osg::ref_ptr<LineDragger> m_TranslateX1;
|
|
|
osg::ref_ptr<LineDragger> m_TranslateX2;
|
|
|
osg::ref_ptr<LineDragger> m_TranslateY1;
|
|
|
osg::ref_ptr<LineDragger> m_TranslateY2;
|
|
|
|
|
|
osg::ref_ptr<RotateDragger> m_RotateZ;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Dragger1DType, typename Dragger2DType>
|
|
|
class TemplateRotateDragger : public BaseDragger
|
|
|
{
|
|
|
public:
|
|
|
typedef Dragger1DType DraggerCylinder;
|
|
|
typedef Dragger2DType DraggerSphere;
|
|
|
|
|
|
TemplateRotateDragger(void)
|
|
|
{
|
|
|
float pixelSize = 80.0f;
|
|
|
osg::ref_ptr<osg::MatrixTransform> scaler = new osg::MatrixTransform;
|
|
|
scaler->setMatrix(osg::Matrix::scale(pixelSize, pixelSize, pixelSize));
|
|
|
|
|
|
osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform;
|
|
|
at->setAutoScaleToScreen(true);
|
|
|
at->addChild(scaler);
|
|
|
|
|
|
osg::ref_ptr<osgManipulator::AntiSquish> as = new osgManipulator::AntiSquish;
|
|
|
as->addChild(at);
|
|
|
addChild(as);
|
|
|
|
|
|
_opDragger = new PointDragger;
|
|
|
scaler->addChild(_opDragger);
|
|
|
addDragger(_opDragger.get());
|
|
|
|
|
|
_xDragger = new DraggerCylinder;
|
|
|
scaler->addChild(_xDragger.get());
|
|
|
addDragger(_xDragger.get());
|
|
|
|
|
|
_yDragger = new DraggerCylinder;
|
|
|
scaler->addChild(_yDragger.get());
|
|
|
addDragger(_yDragger.get());
|
|
|
|
|
|
_zDragger = new DraggerCylinder;
|
|
|
scaler->addChild(_zDragger.get());
|
|
|
addDragger(_zDragger.get());
|
|
|
|
|
|
//_xyzDragger = new DraggerSphere;
|
|
|
//scaler->addChild(_xyzDragger.get());
|
|
|
//addDragger(_xyzDragger.get());
|
|
|
|
|
|
_clipPar = new osg::AutoTransform;
|
|
|
_clipPar->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
|
|
|
_clipPar->setNormal(osg::Vec3(0, -1, 0));
|
|
|
scaler->addChild(_clipPar.get());
|
|
|
|
|
|
osg::ref_ptr<osg::ClipNode> clipNode = new osg::ClipNode;
|
|
|
osg::ref_ptr<osg::ClipPlane> cp = new osg::ClipPlane(0,0,0,1,0.01f);
|
|
|
clipNode->addClipPlane(cp);
|
|
|
_clipPar->addChild(clipNode.get());
|
|
|
|
|
|
scaler->setStateSet(clipNode->getStateSet());
|
|
|
|
|
|
osg::ref_ptr<osg::MatrixTransform> scalerAxis = new osg::MatrixTransform;
|
|
|
scalerAxis->setMatrix(osg::Matrix::scale(pixelSize, pixelSize, pixelSize));
|
|
|
scalerAxis->addChild(InsertAxis(0.4f));
|
|
|
|
|
|
at->addChild(scalerAxis);
|
|
|
|
|
|
setParentDragger(getParentDragger());
|
|
|
}
|
|
|
|
|
|
virtual void setupDefaultGeometry()
|
|
|
{
|
|
|
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
|
|
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
|
{
|
|
|
osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
|
|
|
hints->setCreateTop(false);
|
|
|
hints->setCreateBottom(false);
|
|
|
hints->setCreateBackFace(false);
|
|
|
|
|
|
osg::ref_ptr<osg::Cylinder> cylinder = new osg::Cylinder;
|
|
|
cylinder->setHeight(0.15f);
|
|
|
osg::ref_ptr<osg::ShapeDrawable> cylinderDrawable = new osg::ShapeDrawable(cylinder,hints);
|
|
|
geode->addDrawable(cylinderDrawable);
|
|
|
osgManipulator::setDrawableToAlwaysCull(*cylinderDrawable);
|
|
|
geode->addDrawable(InsertCircle(1.0f, 150));
|
|
|
}
|
|
|
|
|
|
// Draw in line mode.
|
|
|
osg::ref_ptr<osg::PolygonMode> polymode = new osg::PolygonMode;
|
|
|
polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
|
|
|
osg::ref_ptr<osg::LineWidth> lineWidth = new osg::LineWidth;
|
|
|
lineWidth->setWidth(1.4f);
|
|
|
|
|
|
//geode->getOrCreateStateSet()->setAttributeAndModes(polymode.get(), osg::StateAttribute::ON);
|
|
|
geode->getOrCreateStateSet()->setAttributeAndModes(lineWidth.get(), osg::StateAttribute::ON);
|
|
|
|
|
|
_opDragger->addChild(HUtility::InsertSphere(osg::Vec3(0.0, 0.0, 0.0), 0.05, Green_Color));
|
|
|
_xDragger->addChild(geode);
|
|
|
_yDragger->addChild(geode);
|
|
|
_zDragger->addChild(geode);
|
|
|
|
|
|
{
|
|
|
osg::ref_ptr<osg::Geode> clipGeode = new osg::Geode;
|
|
|
clipGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
//clipGeode->getOrCreateStateSet()->setAttributeAndModes(polymode.get(), osg::StateAttribute::ON);
|
|
|
clipGeode->getOrCreateStateSet()->setAttributeAndModes(lineWidth.get(), osg::StateAttribute::ON);
|
|
|
|
|
|
clipGeode->addDrawable(InsertCircle(1.0f, 150));
|
|
|
clipGeode->addDrawable(InsertCircle(1.2f, 150));
|
|
|
|
|
|
osgManipulator::setMaterialColor(osg::Vec4(188/255.0,143/255.0,143/255.0,255/255.0),*clipGeode);
|
|
|
|
|
|
_clipPar->addChild(clipGeode);
|
|
|
}
|
|
|
|
|
|
{
|
|
|
osg::Quat rotation;
|
|
|
rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(1.0f, 0.0f, 0.0f));
|
|
|
_xDragger->setMatrix(osg::Matrix(rotation));
|
|
|
}
|
|
|
|
|
|
{
|
|
|
osg::Quat rotation;
|
|
|
rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(0.0f, 1.0f, 0.0f));
|
|
|
_yDragger->setMatrix(osg::Matrix(rotation));
|
|
|
}
|
|
|
|
|
|
osg::Vec4 xColor = osg::Vec4(1.0, 0.0, 0.0, 1.0);
|
|
|
osg::Vec4 yColor = osg::Vec4(0.0, 1.0, 0.0, 1.0);
|
|
|
osg::Vec4 zColor = osg::Vec4(0.0, 0.0, 1.0, 1.0);
|
|
|
|
|
|
_xDragger->setColor(xColor);
|
|
|
_yDragger->setColor(yColor);
|
|
|
_zDragger->setColor(zColor);
|
|
|
|
|
|
{
|
|
|
//osg::Drawable* sphereDrawable = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 0.95f));
|
|
|
//osgManipulator::setDrawableToAlwaysCull(*sphereDrawable);
|
|
|
//osg::Geode* sphereGeode = new osg::Geode;
|
|
|
//sphereGeode->addDrawable(sphereDrawable);
|
|
|
//_xyzDragger->addChild(sphereGeode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
virtual ~TemplateRotateDragger(){};
|
|
|
|
|
|
protected:
|
|
|
|
|
|
osg::ref_ptr<PointDragger> _opDragger; //ÐýתÇòÐIJÙ×÷Æ÷
|
|
|
osg::ref_ptr<DraggerCylinder> _xDragger;
|
|
|
osg::ref_ptr<DraggerCylinder> _yDragger;
|
|
|
osg::ref_ptr<DraggerCylinder> _zDragger;
|
|
|
|
|
|
osg::ref_ptr<DraggerSphere> _xyzDragger;
|
|
|
osg::ref_ptr<osg::AutoTransform> _clipPar;
|
|
|
};
|
|
|
|
|
|
template<typename Dragger1DType>
|
|
|
class TemplateCylinderDragger : public BaseDragger
|
|
|
{
|
|
|
public:
|
|
|
typedef Dragger1DType DraggerCylinder;
|
|
|
|
|
|
TemplateCylinderDragger(void)
|
|
|
{
|
|
|
float pixelSize = 80.0f;
|
|
|
osg::ref_ptr<osg::MatrixTransform> scaler = new osg::MatrixTransform;
|
|
|
scaler->setMatrix(osg::Matrix::scale(pixelSize, pixelSize, pixelSize));
|
|
|
|
|
|
osg::ref_ptr<osg::AutoTransform> at = new osg::AutoTransform;
|
|
|
at->setAutoScaleToScreen(true);
|
|
|
at->addChild(scaler);
|
|
|
|
|
|
osg::ref_ptr<osgManipulator::AntiSquish> as = new osgManipulator::AntiSquish;
|
|
|
as->addChild(at);
|
|
|
addChild(as);
|
|
|
|
|
|
_zDragger = new DraggerCylinder;
|
|
|
scaler->addChild(_zDragger.get());
|
|
|
addDragger(_zDragger.get());
|
|
|
|
|
|
_clipPar = new osg::AutoTransform;
|
|
|
_clipPar->setAutoRotateMode(osg::AutoTransform::ROTATE_TO_SCREEN);
|
|
|
_clipPar->setNormal(osg::Vec3(0, -1, 0));
|
|
|
scaler->addChild(_clipPar.get());
|
|
|
|
|
|
osg::ref_ptr<osg::ClipNode> clipNode = new osg::ClipNode;
|
|
|
osg::ref_ptr<osg::ClipPlane> cp = new osg::ClipPlane(0,0,0,1,0.01f);
|
|
|
clipNode->addClipPlane(cp);
|
|
|
_clipPar->addChild(clipNode.get());
|
|
|
|
|
|
scaler->setStateSet(clipNode->getStateSet());
|
|
|
|
|
|
osg::ref_ptr<osg::MatrixTransform> scalerAxis = new osg::MatrixTransform;
|
|
|
scalerAxis->setMatrix(osg::Matrix::scale(pixelSize, pixelSize, pixelSize));
|
|
|
scalerAxis->addChild(InsertAxis(0.4f));
|
|
|
|
|
|
at->addChild(scalerAxis);
|
|
|
|
|
|
setParentDragger(getParentDragger());
|
|
|
}
|
|
|
|
|
|
virtual void setupDefaultGeometry()
|
|
|
{
|
|
|
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
|
|
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
|
{
|
|
|
osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
|
|
|
hints->setCreateTop(false);
|
|
|
hints->setCreateBottom(false);
|
|
|
hints->setCreateBackFace(false);
|
|
|
|
|
|
osg::ref_ptr<osg::Cylinder> cylinder = new osg::Cylinder;
|
|
|
cylinder->setHeight(0.15f);
|
|
|
osg::ref_ptr<osg::ShapeDrawable> cylinderDrawable = new osg::ShapeDrawable(cylinder,hints);
|
|
|
geode->addDrawable(cylinderDrawable);
|
|
|
osgManipulator::setDrawableToAlwaysCull(*cylinderDrawable);
|
|
|
geode->addDrawable(InsertCircle(1.0f, 150));
|
|
|
}
|
|
|
|
|
|
// Draw in line mode.
|
|
|
osg::ref_ptr<osg::PolygonMode> polymode = new osg::PolygonMode;
|
|
|
polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
|
|
|
osg::ref_ptr<osg::LineWidth> lineWidth = new osg::LineWidth;
|
|
|
lineWidth->setWidth(1.4f);
|
|
|
|
|
|
//geode->getOrCreateStateSet()->setAttributeAndModes(polymode.get(), osg::StateAttribute::ON);
|
|
|
geode->getOrCreateStateSet()->setAttributeAndModes(lineWidth.get(), osg::StateAttribute::ON);
|
|
|
_zDragger->addChild(geode);
|
|
|
|
|
|
{
|
|
|
osg::ref_ptr<osg::Geode> clipGeode = new osg::Geode;
|
|
|
clipGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
//clipGeode->getOrCreateStateSet()->setAttributeAndModes(polymode.get(), osg::StateAttribute::ON);
|
|
|
clipGeode->getOrCreateStateSet()->setAttributeAndModes(lineWidth.get(), osg::StateAttribute::ON);
|
|
|
|
|
|
clipGeode->addDrawable(InsertCircle(1.0f, 150));
|
|
|
clipGeode->addDrawable(InsertCircle(1.2f, 150));
|
|
|
|
|
|
osgManipulator::setMaterialColor(osg::Vec4(188/255.0,143/255.0,143/255.0,255/255.0),*clipGeode);
|
|
|
|
|
|
_clipPar->addChild(clipGeode);
|
|
|
}
|
|
|
|
|
|
osg::Vec4 zColor = osg::Vec4(0.0, 0.0, 1.0, 1.0);
|
|
|
_zDragger->setColor(zColor);
|
|
|
}
|
|
|
|
|
|
protected:
|
|
|
virtual ~TemplateCylinderDragger(){};
|
|
|
|
|
|
protected:
|
|
|
osg::ref_ptr<DraggerCylinder> _zDragger;
|
|
|
osg::ref_ptr<osg::AutoTransform> _clipPar;
|
|
|
};
|
|
|
|
|
|
|
|
|
class ScaleDragger : public BaseDragger
|
|
|
{
|
|
|
public:
|
|
|
ScaleDragger(void);
|
|
|
|
|
|
virtual void setupDefaultGeometry();
|
|
|
|
|
|
protected:
|
|
|
virtual ~ScaleDragger();
|
|
|
|
|
|
protected:
|
|
|
osg::ref_ptr<osgManipulator::Scale1DDragger> _xDragger;
|
|
|
osg::ref_ptr<osgManipulator::Scale1DDragger> _yDragger;
|
|
|
osg::ref_ptr<osgManipulator::Scale1DDragger> _zDragger;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
typedef TemplateMoveDragger<osgDragger::Move1DDragger, osgManipulator::Translate2DDragger> MoveDragger;
|
|
|
|
|
|
typedef TemplateMoveDirDragger<osgDragger::Move1DDragger, osgManipulator::Translate2DDragger> MoveDirDragger;
|
|
|
|
|
|
typedef TemplateRotateDragger<osgDragger::CylinderDragger, osgManipulator::RotateSphereDragger> RotateDragger;
|
|
|
|
|
|
typedef TemplateCylinderDragger<osgDragger::CylinderDragger> RotateDirDragger;
|
|
|
|
|
|
typedef TemplateMoveDirAndRotateDragger<osgDragger::Move1DDragger, osgDragger::CylinderDragger> MoveDirAndRotateDragger;
|
|
|
|
|
|
typedef TemplateMoveDragger2D<osgDragger::Move1DDragger, osgDragger::CylinderDragger> TranslateRotate2DDragger;
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|