| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- /**************************************************************************************************
- 版本所有(C), 2020-2022, 北京普达迪泰
- ***************************************************************************************************
- 文 件 名: CoreOSG.h
- 功能描述: OSG封装类
- 版 本 号: 1.00初版
- 作 者: HYF
- 生成日期; 2021-12-20
- 最近修改:
- 函数列表:
- 修改历史:
- 1.日 期 :2021-12-20
- 作 者 : HYF
- 修改内容 : 创建文件
- **************************************************************************************************/
- #pragma once
- #include <osgViewer/Viewer>
- #include <osgViewer/ViewerEventHandlers>
- #include <osgViewer/api/win32/GraphicsWindowWin32>
- #include <osgGA/TrackballManipulator>
- #include <osgGA/KeySwitchMatrixManipulator>
- #include <osgGA/StateSetManipulator>
- #include <osgDB/DatabasePager>
- #include <osgDB/Registry>
- #include <osgDB/ReadFile>
- #include <osgUtil/Optimizer>
- #include <osg/MatrixTransform>
- #include <osg/BlendColor>
- #include <osg/BlendFunc>
- #include <osg/Geode>
- #include <osg/Geometry>
- #include <osg/LineWidth>
- #include <osg/ComputeBoundsVisitor>
- #include <osg/Node>
- #include <osg/Group>
- #include <osg/Matrix>
- #include <osg/FrameStamp>
- #include <osg/Camera>
- #include <string>
- 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<string> &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<osg::Node> CreateLine(osg::Vec3 firstpoit, osg::Vec3 endpoint);
- void Export(const std::string& strPaths, const std::string& strPathd);
- public:
-
- bool AddLine();
- std::vector<osg::ref_ptr<osg::MatrixTransform>> m_vecEngine;
- void VibrateEngine(int iMearObj);
- osg::Camera* createHudCamera();
- void RotateCurModel(const double fx, const double fy, const double fz);
- osg::ref_ptr<ModelRotateCallback> 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<osgViewer::Viewer> m_Viewer;
- osg::ref_ptr<osg::Group> m_Root;
- osg::ref_ptr<osg::MatrixTransform> m_gEngineR = nullptr;
- osg::ref_ptr<osg::MatrixTransform> m_gEngineL = nullptr;
-
- osg::ref_ptr<osgGA::TrackballManipulator> m_Trackball;
- osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> 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<osgViewer::Viewer> 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<osg::Camera> _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<osg::Vec3Array> m_extractedverts;
- //推力线终点坐标
- osg::Vec3 m_vThrustlineEndPoit;
- std::string m_strThrustlineName;
- double m_fAxisX;
- double m_fAxisY;
- double m_fAxisZ;
- };
|