root/OpenSceneGraph/trunk/src/osgManipulator/TranslatePlaneDragger.cpp @ 13041

Revision 13041, 3.5 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
14
15#include <osgManipulator/TranslatePlaneDragger>
16
17#include <osg/ShapeDrawable>
18#include <osg/Geometry>
19#include <osg/LineWidth>
20#include <osg/Quat>
21#include <osg/PolygonMode>
22#include <osg/CullFace>
23#include <osg/AutoTransform>
24
25using namespace osgManipulator;
26
27TranslatePlaneDragger::TranslatePlaneDragger() : _usingTranslate1DDragger(false)
28{
29    _translate2DDragger = new Translate2DDragger();
30    _translate2DDragger->setColor(osg::Vec4(0.7f, 0.7f, 0.7f, 1.0f));
31    addChild(_translate2DDragger.get());
32    addDragger(_translate2DDragger.get());
33
34    _translate1DDragger = new Translate1DDragger(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(0.0f,1.0f,0.0f));
35    _translate1DDragger->setCheckForNodeInNodePath(false);
36    addChild(_translate1DDragger.get());
37    addDragger(_translate1DDragger.get());
38
39    setParentDragger(getParentDragger());
40}
41
42TranslatePlaneDragger::~TranslatePlaneDragger()
43{
44}
45
46bool TranslatePlaneDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
47{
48    // Check if the dragger node is in the nodepath.
49    if (!pointer.contains(this)) return false;
50
51    if ((ea.getButtonMask() & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) &&
52        ea.getEventType() == osgGA::GUIEventAdapter::PUSH)
53        _usingTranslate1DDragger = true;
54
55    bool handled = false;
56    if (_usingTranslate1DDragger)
57    {
58        if (_translate1DDragger->handle(pointer, ea, aa))
59            handled = true;
60    }
61    else
62    {
63        if (_translate2DDragger->handle(pointer, ea, aa))
64            handled = true;
65    }
66
67    if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
68        _usingTranslate1DDragger = false;
69
70    return handled;
71}
72
73void TranslatePlaneDragger::setupDefaultGeometry()
74{
75    // Create a polygon.
76    {
77        osg::Geode* geode = new osg::Geode;
78        osg::Geometry* geometry = new osg::Geometry();
79
80        osg::Vec3Array* vertices = new osg::Vec3Array(4);
81        (*vertices)[0] = osg::Vec3(-0.5,0.0,0.5);
82        (*vertices)[1] = osg::Vec3(-0.5,0.0,-0.5);
83        (*vertices)[2] = osg::Vec3(0.5,0.0,-0.5);
84        (*vertices)[3] = osg::Vec3(0.5,0.0,0.5);
85
86        geometry->setVertexArray(vertices);
87        geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,vertices->size()));
88
89        osg::Vec3Array* normals = new osg::Vec3Array;
90        normals->push_back(osg::Vec3(0.0,1.0,0.0));
91        geometry->setNormalArray(normals);
92        geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
93
94        geode->addDrawable(geometry);
95
96        osg::PolygonMode* polymode = new osg::PolygonMode;
97        polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
98        geode->getOrCreateStateSet()->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
99
100        geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
101
102        _translate2DDragger->addChild(geode);
103    }
104}
Note: See TracBrowser for help on using the browser.