root/OpenSceneGraph/trunk/applications/present3D/deprecated/PointsEventHandler.cpp @ 13720

Revision 13720, 2.8 kB (checked in by robert, 93 minutes ago)

Fixed warnings

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2 *
3 * This software is open source and may be redistributed and/or modified under 
4 * the terms of the GNU General Public License (GPL) version 2.0.
5 * The full license is in LICENSE.txt file included with this distribution,.
6 *
7 * This software is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * include LICENSE.txt for more details.
11*/
12
13#include "PointsEventHandler.h"
14
15#include <osg/Notify>
16
17PointsEventHandler::PointsEventHandler()
18{
19    _point = new osg::Point;
20    //_point->setDistanceAttenuation(osg::Vec3(0.0,0.0000,0.05f));
21}
22
23bool PointsEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
24{
25    switch(ea.getEventType())
26    {
27        case(osgGA::GUIEventAdapter::KEYDOWN):
28        {
29            if (ea.getKey()=='+' || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Add)
30            {
31               changePointSize(1.0f);
32               return true;
33            }
34            else if (ea.getKey()=='-' || ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Subtract)
35            {
36               changePointSize(-1.0f);
37               return true;
38            }
39            else if (ea.getKey()=='<')
40            {
41               changePointAttenuation(1.1f);
42               return true;
43            }
44            else if (ea.getKey()=='>')
45            {
46               changePointAttenuation(1.0f/1.1f);
47               return true;
48            }
49            break;
50        }
51        default:
52            break;
53    }
54    return false;
55}
56
57void PointsEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
58{
59    v.visit(*this);
60}
61
62void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const
63{
64    usage.addKeyboardMouseBinding("+","Increase point size");
65    usage.addKeyboardMouseBinding("-","Reduce point size");
66    usage.addKeyboardMouseBinding(">","Increase point size");
67    usage.addKeyboardMouseBinding("<","Reduce point size");
68}
69
70float PointsEventHandler::getPointSize() const
71{
72    return _point->getSize();
73}
74
75void PointsEventHandler::setPointSize(float psize)
76{
77    if (psize>0.0)
78    {
79        _point->setSize(psize);
80        _stateset->setAttribute(_point.get());
81    }
82    else
83    {
84        _stateset->setAttribute(_point.get(),osg::StateAttribute::INHERIT);
85    }
86    osg::notify(osg::INFO)<<"Point size "<<psize<<std::endl;
87}
88
89void PointsEventHandler::changePointSize(float delta)
90{
91    setPointSize(getPointSize()+delta);
92}
93
94void PointsEventHandler::changePointAttenuation(float scale)
95{
96    if (_point.valid())
97    {
98        _point->setDistanceAttenuation(_point->getDistanceAttenuation()*scale);
99        if (_stateset.valid()) _stateset->setAttribute(_point.get());
100    }
101}
Note: See TracBrowser for help on using the browser.