3 * Copyright (C) 2006-2007 Mathias Froehlich
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 # include <simgear_config.h>
26 #include <osgDB/Registry>
27 #include <osgDB/Input>
28 #include <osgDB/ParameterOutput>
30 #include "SGSceneUserData.hxx"
33 SGSceneUserData::getSceneUserData(osg::Node* node)
37 osg::Referenced* referenced = node->getUserData();
40 return dynamic_cast<SGSceneUserData*>(referenced);
43 const SGSceneUserData*
44 SGSceneUserData::getSceneUserData(const osg::Node* node)
48 const osg::Referenced* referenced = node->getUserData();
51 return dynamic_cast<const SGSceneUserData*>(referenced);
55 SGSceneUserData::getOrCreateSceneUserData(osg::Node* node)
57 SGSceneUserData* userData = getSceneUserData(node);
60 userData = new SGSceneUserData;
61 node->setUserData(userData);
66 SGSceneUserData::getNumPickCallbacks() const
68 return _pickCallbacks.size();
72 SGSceneUserData::getPickCallback(unsigned i) const
74 if (_pickCallbacks.size() <= i)
76 return _pickCallbacks[i];
80 SGSceneUserData::setPickCallback(SGPickCallback* pickCallback)
82 _pickCallbacks.clear();
83 addPickCallback(pickCallback);
87 SGSceneUserData::addPickCallback(SGPickCallback* pickCallback)
91 _pickCallbacks.push_back(pickCallback);
94 bool SGSceneUserData_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
96 const SGSceneUserData& data = static_cast<const SGSceneUserData&>(obj);
98 unsigned numPickCallbacks = data.getNumPickCallbacks();
99 if (numPickCallbacks > 0)
100 fw.indent() << "num_pickCallbacks " << numPickCallbacks << "\n";
101 if (data.getBVHNode())
102 fw.indent() << "hasBVH true\n";
103 const SGSceneUserData::Velocity* vel = data.getVelocity();
105 fw.indent() << "velocity {\n";
107 fw.indent() << "linear " << vel->linear << "\n";
108 fw.indent() << "angular " << vel->angular << "\n";
109 fw.indent() << "referenceTime " << vel->referenceTime << "\n";
110 fw.indent() << "id " << static_cast<unsigned>(vel->id) << "\n";
112 fw.indent() << "}\n";
119 osgDB::RegisterDotOsgWrapperProxy SGSceneUserDataProxy
122 "simgear::SGSceneUserData",
123 "Object simgear::SGSceneUserData",
125 &SGSceneUserData_writeLocalData