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

Revision 13041, 3.7 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/TranslateAxisDragger>
16
17#include <osg/ShapeDrawable>
18#include <osg/Geometry>
19#include <osg/LineWidth>
20#include <osg/Quat>
21
22using namespace osgManipulator;
23
24TranslateAxisDragger::TranslateAxisDragger()
25{
26    _xDragger = new Translate1DDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
27    addChild(_xDragger.get());
28    addDragger(_xDragger.get());
29
30    _yDragger = new Translate1DDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
31    addChild(_yDragger.get());
32    addDragger(_yDragger.get());
33
34    _zDragger = new Translate1DDragger(osg::Vec3(0.0,0.0,0.0), osg::Vec3(0.0,0.0,1.0));
35    addChild(_zDragger.get());
36    addDragger(_zDragger.get());
37
38    setParentDragger(getParentDragger());
39}
40
41TranslateAxisDragger::~TranslateAxisDragger()
42{
43}
44
45void TranslateAxisDragger::setupDefaultGeometry()
46{
47    // Create a line.
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(0.0f,0.0f,1.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    // Turn of lighting for line and set line width.
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    // Add line to all the individual 1D draggers.
71    _xDragger->addChild(lineGeode);
72    _yDragger->addChild(lineGeode);
73    _zDragger->addChild(lineGeode);
74
75    osg::Geode* geode = new osg::Geode;
76
77    // Create a cone.
78    {
79        osg::Cone* cone = new osg::Cone (osg::Vec3(0.0f, 0.0f, 1.0f), 0.025f, 0.10f);
80        geode->addDrawable(new osg::ShapeDrawable(cone));
81    }
82
83    // Create an invisible cylinder for picking the line.
84    {
85        osg::Cylinder* cylinder = new osg::Cylinder (osg::Vec3(0.0f,0.0f,0.5f), 0.015f, 1.0f);
86        osg::Drawable* geometry = new osg::ShapeDrawable(cylinder);
87        setDrawableToAlwaysCull(*geometry);
88        geode->addDrawable(geometry);
89    }
90
91    // Add geode to all 1D draggers.
92    _xDragger->addChild(geode);
93    _yDragger->addChild(geode);
94    _zDragger->addChild(geode);
95
96    // Rotate X-axis dragger appropriately.
97    {
98        osg::Quat rotation; rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(1.0f, 0.0f, 0.0f));
99        _xDragger->setMatrix(osg::Matrix(rotation));
100    }
101
102    // Rotate Y-axis dragger appropriately.
103    {
104        osg::Quat rotation; rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(0.0f, 1.0f, 0.0f));
105        _yDragger->setMatrix(osg::Matrix(rotation));
106    }
107
108    // Send different colors for each dragger.
109    _xDragger->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f));
110    _yDragger->setColor(osg::Vec4(0.0f,1.0f,0.0f,1.0f));
111    _zDragger->setColor(osg::Vec4(0.0f,0.0f,1.0f,1.0f));
112}
Note: See TracBrowser for help on using the browser.