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

Revision 13855, 3.8 kB (checked in by robert, 11 minutes ago)

Added in source shaders

  • 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    _axisLineWidth = 2.0f;
39    _boxSize = 0.05f;
40
41    setParentDragger(getParentDragger());
42}
43
44ScaleAxisDragger::~ScaleAxisDragger()
45{
46}
47
48void ScaleAxisDragger::setupDefaultGeometry()
49{
50    // Create a line.
51    _lineGeode = new osg::Geode;
52    {
53        osg::Geometry* geometry = new osg::Geometry();
54
55        osg::Vec3Array* vertices = new osg::Vec3Array(2);
56        (*vertices)[0] = osg::Vec3(0.0f,0.0f,0.0f);
57        (*vertices)[1] = osg::Vec3(1.0f,0.0f,0.0f);
58
59        geometry->setVertexArray(vertices);
60        geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,2));
61
62        _lineGeode->addDrawable(geometry);
63    }
64
65    // Turn of lighting for line and set line width.
66    {
67        _lineWidth = new osg::LineWidth();
68        _lineWidth->setWidth(_axisLineWidth);
69        _lineGeode->getOrCreateStateSet()->setAttributeAndModes(_lineWidth, osg::StateAttribute::ON);
70        _lineGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
71    }
72
73    // Add line to all the individual 1D draggers.
74    _xDragger->addChild(_lineGeode);
75    _yDragger->addChild(_lineGeode);
76    _zDragger->addChild(_lineGeode);
77
78    osg::Geode* geode = new osg::Geode;
79
80    // Create a box.
81    _box = new osg::Box(osg::Vec3(1.0f,0.0f,0.0f), _boxSize);
82    geode->addDrawable(new osg::ShapeDrawable(_box));
83
84    // This ensures correct lighting for scaled draggers.
85#if !defined(OSG_GLES2_AVAILABLE)
86    geode->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
87#endif
88
89    // Add geode to all 1D draggers.
90    _xDragger->addChild(geode);
91    _yDragger->addChild(geode);
92    _zDragger->addChild(geode);
93
94    // Rotate Z-axis dragger appropriately.
95    {
96        osg::Quat rotation; rotation.makeRotate(osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 0.0f, 1.0f));
97        _zDragger->setMatrix(osg::Matrix(rotation));
98    }
99
100    // Rotate Y-axis dragger appropriately.
101    {
102        osg::Quat rotation; rotation.makeRotate(osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 1.0f, 0.0f));
103        _yDragger->setMatrix(osg::Matrix(rotation));
104    }
105
106    // Send different colors for each dragger.
107    _xDragger->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f));
108    _yDragger->setColor(osg::Vec4(0.0f,1.0f,0.0f,1.0f));
109    _zDragger->setColor(osg::Vec4(0.0f,0.0f,1.0f,1.0f));
110}
111
112void ScaleAxisDragger::setAxisLineWidth(float linePixelWidth)
113{
114    _axisLineWidth = linePixelWidth;
115    if (_lineWidth.valid())
116        _lineWidth->setWidth(linePixelWidth);
117}
118
119void ScaleAxisDragger::setBoxSize(float size)
120{
121    _boxSize = size;
122    if (_box.valid())
123        _box->setHalfLengths(osg::Vec3(size * 0.5f, size * 0.5f, size * 0.5f));
124}
Note: See TracBrowser for help on using the browser.