00001 #ifndef __SceneObject__ 00002 #define __SceneObject__ 00003 00004 #include <osg/MatrixTransform> 00005 #include <string> 00006 00007 #include "MaterialFactory.h" 00008 00009 00010 00017 class SceneObject : public osg::Group { 00018 friend class ObjectManipulatorProxy; 00019 00020 public: 00021 struct State { 00022 static const int NORMAL = 0; 00023 static const int HIGHLIGHTED = 1; 00024 static const int TRANSLUCENT = 2; 00025 }; 00026 00027 00028 00029 SceneObject(osg::Node* model = NULL, const char* filename = NULL); 00030 ~SceneObject(); 00031 00032 00033 osg::Vec3 getPosition(); 00034 osg::Vec3 getOrientation(); 00035 osg::Quat getOrientationAsQuaternion(); 00036 osg::Vec3 getScale(); 00037 00038 int getState(); 00039 void setState(int state); 00040 00041 void setModelFilename(const char* filename); 00042 void setModelFilename(std::string& filename); 00043 std::string& getModelFilename(); 00044 00045 double getBoundingRadius() const; 00046 osg::Matrix getTransformationMatrix(); 00047 00048 bool intersects(const osg::Vec3d& rayDirection, const osg::Vec3d& rayPoint); 00049 00050 protected: 00051 class UpdateStateCallback : public osg::Uniform::Callback { 00052 public: 00053 UpdateStateCallback(SceneObject& sceneObject) 00054 : _sceneObject(sceneObject) {} 00055 00056 virtual void operator()(osg::Uniform* uniform, osg::NodeVisitor* nv) { 00057 uniform->set(_sceneObject.getState()); 00058 } 00059 00060 protected: 00061 SceneObject& _sceneObject; 00062 }; 00063 00064 bool _checkIntersection(osg::Node* node, const osg::Vec3d& rayDirection, const osg::Vec3d& rayPoint, const osg::Vec3d& sphereHit1, const osg::Vec3d& sphereHit2); 00065 00066 void setPosition(const osg::Vec3& position); 00067 void setOrientation(const osg::Vec3& orientation); 00068 void setScale(const osg::Vec3& scale); 00069 00070 00071 osg::MatrixTransform* _T; 00072 osg::MatrixTransform* _R; 00073 osg::MatrixTransform* _S; 00074 00075 osg::Node* _objectNode; 00076 std::string _objectFilename; 00077 00078 osg::Vec3 _eulerOrientation; 00079 double _bbRadius; 00080 00081 MaterialFactory& _materialFactory; 00082 00083 int _state; 00084 }; 00085 00086 #endif