00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SG_SCENE_USERDATA_HXX
00023 #define SG_SCENE_USERDATA_HXX
00024
00025 #include <vector>
00026 #include <osg/Node>
00027 #include <osg/Object>
00028 #include <simgear/scene/bvh/BVHNode.hxx>
00029 #include "SGPickCallback.hxx"
00030
00031 class SGSceneUserData : public osg::Object {
00032 public:
00033 META_Object(simgear, SGSceneUserData);
00034 SGSceneUserData() {}
00035 SGSceneUserData(const SGSceneUserData& rhs,
00036 const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY)
00037 : _bvhNode(rhs._bvhNode), _velocity(rhs._velocity),
00038 _pickCallbacks(rhs._pickCallbacks)
00039 {
00040 }
00041 static SGSceneUserData* getSceneUserData(osg::Node* node);
00042 static const SGSceneUserData* getSceneUserData(const osg::Node* node);
00043 static SGSceneUserData* getOrCreateSceneUserData(osg::Node* node);
00044
00046 unsigned getNumPickCallbacks() const;
00047 SGPickCallback* getPickCallback(unsigned i) const;
00048 void setPickCallback(SGPickCallback* pickCallback);
00049 void addPickCallback(SGPickCallback* pickCallback);
00050
00051 const simgear::BVHNode* getBVHNode() const
00052 { return _bvhNode; }
00053 simgear::BVHNode* getBVHNode()
00054 { return _bvhNode; }
00055 void setBVHNode(simgear::BVHNode* bvhNode)
00056 { _bvhNode = bvhNode; }
00057
00058 struct Velocity : public SGReferenced {
00059 Velocity() :
00060 linear(SGVec3d::zeros()),
00061 angular(SGVec3d::zeros()),
00062 referenceTime(0),
00063 id(simgear::BVHNode::getNewId())
00064 {}
00065 SGVec3d linear;
00066 SGVec3d angular;
00067 double referenceTime;
00068 simgear::BVHNode::Id id;
00069 };
00070 const Velocity* getVelocity() const
00071 { return _velocity; }
00072 Velocity* getOrCreateVelocity()
00073 { if (!_velocity) _velocity = new Velocity; return _velocity; }
00074 void setVelocity(Velocity* velocity)
00075 { _velocity = velocity; }
00076
00077 private:
00078
00079 SGSharedPtr<simgear::BVHNode> _bvhNode;
00080
00081
00082 SGSharedPtr<Velocity> _velocity;
00083
00085 std::vector<SGSharedPtr<SGPickCallback> > _pickCallbacks;
00086 };
00087
00088 #endif