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

Revision 13890, 2.7 kB (checked in by robert, 16 hours ago)

Added .tf & .tf-255 plugin for reading ascii 1D transfer functon files in support for volume rendering.

  • 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::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
65float PointsEventHandler::getPointSize() const
66{
67    return _point->getSize();
68}
69
70void 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
84void PointsEventHandler::changePointSize(float delta)
85{
86    setPointSize(getPointSize()+delta);
87}
88
89void 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}
Note: See TracBrowser for help on using the browser.