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 
PointsEventHandler()17 PointsEventHandler::PointsEventHandler()
18 {
19     _point = new osg::Point;
20     //_point->setDistanceAttenuation(osg::Vec3(0.0,0.0000,0.05f));
21 }
22 
handle(const osgGA::GUIEventAdapter & ea,osgGA::GUIActionAdapter &)23 bool 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 
getUsage(osg::ApplicationUsage & usage) const57 void PointsEventHandler::getUsage(osg::ApplicationUsage& usage) const
58 {
59     usage.addKeyboardMouseBinding("+","Increase point size");
60     usage.addKeyboardMouseBinding("-","Reduce point size");
61     usage.addKeyboardMouseBinding(">","Increase point size");
62     usage.addKeyboardMouseBinding("<","Reduce point size");
63 }
64 
getPointSize() const65 float PointsEventHandler::getPointSize() const
66 {
67     return _point->getSize();
68 }
69 
setPointSize(float psize)70 void PointsEventHandler::setPointSize(float psize)
71 {
72     if (psize>0.0)
73     {
74         _point->setSize(psize);
75         _stateset->setAttribute(_point.get());
76     }
77     else
78     {
79         _stateset->setAttribute(_point.get(),osg::StateAttribute::INHERIT);
80     }
81     osg::notify(osg::INFO)<<"Point size "<<psize<<std::endl;
82 }
83 
changePointSize(float delta)84 void PointsEventHandler::changePointSize(float delta)
85 {
86     setPointSize(getPointSize()+delta);
87 }
88 
changePointAttenuation(float scale)89 void PointsEventHandler::changePointAttenuation(float scale)
90 {
91     if (_point.valid())
92     {
93         _point->setDistanceAttenuation(_point->getDistanceAttenuation()*scale);
94         if (_stateset.valid()) _stateset->setAttribute(_point.get());
95     }
96 }
97