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

Revision 13041, 3.2 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/ScaleAxisDragger>
16
17#include <osg/ShapeDrawable>
18#include <osg/Geometry>
19#include <osg/LineWidth>
20#include <osg/Quat>
21
22using namespace osgManipulator;
23
24ScaleAxisDragger::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
41ScaleAxisDragger::~ScaleAxisDragger()
42{
43}
44
45void ScaleAxisDragger::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(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    // 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 box.
78    geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(1.0f,0.0f,0.0f), 0.05)));
79
80    // Add geode to all 1D draggers.
81    _xDragger->addChild(geode);
82    _yDragger->addChild(geode);
83    _zDragger->addChild(geode);
84
85    // Rotate Z-axis dragger appropriately.
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    // Rotate Y-axis dragger appropriately.
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    // Send different colors for each dragger.
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}
Note: See TracBrowser for help on using the browser.