| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include <osgManipulator/ScaleAxisDragger> |
|---|
| 16 | |
|---|
| 17 | #include <osg/ShapeDrawable> |
|---|
| 18 | #include <osg/Geometry> |
|---|
| 19 | #include <osg/LineWidth> |
|---|
| 20 | #include <osg/Quat> |
|---|
| 21 | |
|---|
| 22 | using namespace osgManipulator; |
|---|
| 23 | |
|---|
| 24 | ScaleAxisDragger::ScaleAxisDragger() |
|---|
| 25 | { |
|---|
| 26 | _xDragger = new osgManipulator::Scale1DDragger(); |
|---|
| 27 | addChild(_xDragger.get()); |
|---|
| 28 | addDragger(_xDragger.get()); |
|---|
| 29 | |
|---|
| 30 | _yDragger = new osgManipulator::Scale1DDragger(); |
|---|
| 31 | addChild(_yDragger.get()); |
|---|
| 32 | addDragger(_yDragger.get()); |
|---|
| 33 | |
|---|
| 34 | _zDragger = new osgManipulator::Scale1DDragger(); |
|---|
| 35 | addChild(_zDragger.get()); |
|---|
| 36 | addDragger(_zDragger.get()); |
|---|
| 37 | |
|---|
| 38 | setParentDragger(getParentDragger()); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | ScaleAxisDragger::~ScaleAxisDragger() |
|---|
| 42 | { |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | void ScaleAxisDragger::setupDefaultGeometry() |
|---|
| 46 | { |
|---|
| 47 | |
|---|
| 48 | osg::Geode* lineGeode = new osg::Geode; |
|---|
| 49 | { |
|---|
| 50 | osg::Geometry* geometry = new osg::Geometry(); |
|---|
| 51 | |
|---|
| 52 | osg::Vec3Array* vertices = new osg::Vec3Array(2); |
|---|
| 53 | (*vertices)[0] = osg::Vec3(0.0f,0.0f,0.0f); |
|---|
| 54 | (*vertices)[1] = osg::Vec3(1.0f,0.0f,0.0f); |
|---|
| 55 | |
|---|
| 56 | geometry->setVertexArray(vertices); |
|---|
| 57 | geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,2)); |
|---|
| 58 | |
|---|
| 59 | lineGeode->addDrawable(geometry); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | { |
|---|
| 64 | osg::LineWidth* linewidth = new osg::LineWidth(); |
|---|
| 65 | linewidth->setWidth(2.0f); |
|---|
| 66 | lineGeode->getOrCreateStateSet()->setAttributeAndModes(linewidth, osg::StateAttribute::ON); |
|---|
| 67 | lineGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | _xDragger->addChild(lineGeode); |
|---|
| 72 | _yDragger->addChild(lineGeode); |
|---|
| 73 | _zDragger->addChild(lineGeode); |
|---|
| 74 | |
|---|
| 75 | osg::Geode* geode = new osg::Geode; |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(1.0f,0.0f,0.0f), 0.05))); |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | _xDragger->addChild(geode); |
|---|
| 82 | _yDragger->addChild(geode); |
|---|
| 83 | _zDragger->addChild(geode); |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | { |
|---|
| 87 | osg::Quat rotation; rotation.makeRotate(osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f)); |
|---|
| 88 | _zDragger->setMatrix(osg::Matrix(rotation)); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | { |
|---|
| 93 | osg::Quat rotation; rotation.makeRotate(osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 1.0f, 0.0f)); |
|---|
| 94 | _yDragger->setMatrix(osg::Matrix(rotation)); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | _xDragger->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); |
|---|
| 99 | _yDragger->setColor(osg::Vec4(0.0f,1.0f,0.0f,1.0f)); |
|---|
| 100 | _zDragger->setColor(osg::Vec4(0.0f,0.0f,1.0f,1.0f)); |
|---|
| 101 | } |
|---|