/************************************************************************************************** 版本所有(C), 2020-2022, 北京普达迪泰 *************************************************************************************************** 文 件 名: CoreOSG.h 功能描述: OSG封装类 版 本 号: 1.00初版 作 者: HYF 生成日期; 2021-12-20 最近修改: 函数列表: 修改历史: 1.日 期 :2021-12-20 作 者 : HYF 修改内容 : 创建文件 **************************************************************************************************/ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class ModelRotateCallback : public osg::NodeCallback { public: ModelRotateCallback(); virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); void setRotateAnglexyz(const double fx, const double fy, const double fz); private: double m_fAxisX; double m_fAxisY; double m_fAxisZ; }; class CoreOSG { public: CoreOSG(HWND hWnd); ~CoreOSG(); BOOL InitOSG(); void InitManipulators(); // 加载模型文件 BOOL LoadModel(std::vector &vecModel, std::string axesPath); //BOOL ReLoadModel(std::string modelname); BOOL InitCameraConfig(void); BOOL ReInitCameraConfig(void); void setColor(osg::Node* pNode, osg::Vec4 vecColor); //void SetupWindow(void); //void SetupCamera(void); void PreFrameUpdate(void); void PostFrameUpdate(void); void Done(bool value) { m_bDone = value; } bool Done(void) { return m_bDone; } //static void Render(void* ptr); BOOL Release(); BOOL ReleaseViewer(); osgViewer::Viewer* getViewer() { return m_Viewer; }; osg::Vec3d DegreesToRadians(const osg::Vec3& vecRotate); osg::Vec3d RadiansToDegrees(const osg::Vec3& vecRotate); void Quat2RadiansRotate(const osg::Quat& quat, osg::Vec3& vecRotate); void Quat2DegreesRotate(const osg::Quat& quat, osg::Vec3& vecRotate); osg::Matrix RadiansRotate2Matrix(const osg::Vec3d& vecRotate); osg::Matrix DegreesRotate2Matrix(const osg::Vec3d& vecRotate); osg::ref_ptr CreateLine(osg::Vec3 firstpoit, osg::Vec3 endpoint); void Export(const std::string& strPaths, const std::string& strPathd); public: bool AddLine(); std::vector> m_vecEngine; void VibrateEngine(int iMearObj); osg::Camera* createHudCamera(); void RotateCurModel(const double fx, const double fy, const double fz); osg::ref_ptr m_pModelRotateCallback; //class HudCallback; private: HWND m_hWnd; int m_giCurMearObj = 2;//当前测试对象 0表示左发动机 1表示右发动机 bool m_bDone; std::string m_szModelName; //osgViewer::Viewer* m_Viewer; osg::ref_ptr m_Viewer; osg::ref_ptr m_Root; osg::ref_ptr m_gEngineR = nullptr; osg::ref_ptr m_gEngineL = nullptr; osg::ref_ptr m_Trackball; osg::ref_ptr m_KeyswitchManipulator; // }; class RenderingThread : public OpenThreads::Thread { public: RenderingThread(CoreOSG* ptr); virtual ~RenderingThread(); virtual void run(); void Done(bool value) { _done = value; } bool Done(void) { return _done; } protected: CoreOSG* _ptr; bool _done; }; class HudCallback : public osg::NodeCallback { public: HudCallback(osgViewer::Viewer* viewer); ~HudCallback(); void operator()(osg::Node* node, osg::NodeVisitor* nv); private: osg::ref_ptr m_xyzviewer; }; class HUDAxis :public osg::Camera { public: HUDAxis(); //HUDAxis(HUDAxis const& copy, CopyOp copyOp = CopyOp::SHALLOW_COPY); //META_Node(osg, HUDAxis); inline void setMainCamera(osg::Camera* camera) { _mainCamera = camera; } virtual void traverse(osg::NodeVisitor& nv); protected: //virtual ~HUDAxis(); osg::ref_ptr _mainCamera; }; //node访问器,继承自osg::NodeVisitor类 class VertexVisitor : public osg::NodeVisitor { public: //构造函数,初始化一下并设置为遍历所有子节点 VertexVisitor(); // ~VertexVisitor(); //设置推力线终点坐标 void setThrustlineEndPoit(osg::Vec3 vThrustlineEndPoit); //设置要查找的推力线几何体名称 void setFindThrustlineName(const std::string strThrustlineName); void setRotatexyz(const double fx, const double fy, const double fz); void apply(osg::MatrixTransform& geode); void apply(osg::Node& node); void apply(osg::Geode& genode); void apply(osg::Transform &genode); private: //保存顶点数据 //osg::ref_ptr m_extractedverts; //推力线终点坐标 osg::Vec3 m_vThrustlineEndPoit; std::string m_strThrustlineName; double m_fAxisX; double m_fAxisY; double m_fAxisZ; };