diff --git a/CMakeLists.txt b/CMakeLists.txt index d629a7727..b9ae004e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ add_subdirectory (network) add_subdirectory (simulator) add_subdirectory (viewer) -#add_subdirectory(viewer2) +# add_subdirectory (viewer2) add_subdirectory (addons/passcar) add_subdirectory (addons/freightcar) diff --git a/viewer/display/include/display-types.h b/viewer/display/include/display-types.h index 3a45138dd..df15d8790 100644 --- a/viewer/display/include/display-types.h +++ b/viewer/display/include/display-types.h @@ -5,6 +5,6 @@ #include "vehicle-signals.h" -typedef std::array display_signals_t; +using display_signals_t = std::array; #endif // DISPLAY_TYPES_H diff --git a/viewer/display/include/display.h b/viewer/display/include/display.h index 9929421d9..e32521722 100644 --- a/viewer/display/include/display.h +++ b/viewer/display/include/display.h @@ -79,7 +79,7 @@ class DISPLAY_EXPORT AbstractDisplay : public QWidget //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -typedef AbstractDisplay* (*GetDisplay)(); +using GetDisplay = AbstractDisplay* (*)(); //------------------------------------------------------------------------------ // diff --git a/viewer/osgdb_dmd/include/dmd-mesh.h b/viewer/osgdb_dmd/include/dmd-mesh.h index 3bca59925..21ed498ab 100644 --- a/viewer/osgdb_dmd/include/dmd-mesh.h +++ b/viewer/osgdb_dmd/include/dmd-mesh.h @@ -4,7 +4,7 @@ #include #include -typedef std::vector face_t; +using face_t = std::vector; //------------------------------------------------------------------------------ // diff --git a/viewer/osgdb_dmd/include/dmd-writer-visitor.h b/viewer/osgdb_dmd/include/dmd-writer-visitor.h index 9742e3d64..3cc6861b3 100644 --- a/viewer/osgdb_dmd/include/dmd-writer-visitor.h +++ b/viewer/osgdb_dmd/include/dmd-writer-visitor.h @@ -4,7 +4,7 @@ #include #include -typedef std::vector dmd_content_t; +using dmd_content_t = std::vector; //------------------------------------------------------------------------------ // diff --git a/viewer/osgdb_dmd/src/dmd-parser.cpp b/viewer/osgdb_dmd/src/dmd-parser.cpp index f6d3e482e..6b661c8c7 100644 --- a/viewer/osgdb_dmd/src/dmd-parser.cpp +++ b/viewer/osgdb_dmd/src/dmd-parser.cpp @@ -75,7 +75,7 @@ void readNextMesh(std::ifstream &stream, dmd_multimesh_t &multimesh) line = getLine(stream); // Читаем массив вершин - mesh.vertices = new osg::Vec3Array; + mesh.vertices = new osg::Vec3Array; for (unsigned int i = 0; i < mesh.vertex_count; ++i) { @@ -97,7 +97,7 @@ void readNextMesh(std::ifstream &stream, dmd_multimesh_t &multimesh) for (unsigned int i = 0; i < mesh.faces_count; ++i) { line = getLine(stream); - line = delete_symbol(line, '\t'); + line = delete_symbol(line, '\t'); std::istringstream ss(line); @@ -157,7 +157,7 @@ void readTextureBlock(std::ifstream &stream, dmd_multimesh_t &multimesh) texel.y() = 1.0f - texel.y(); multimesh.texvrtices->push_back(texel); - } + } line = getLine(stream); line = getLine(stream); @@ -165,20 +165,20 @@ void readTextureBlock(std::ifstream &stream, dmd_multimesh_t &multimesh) for (unsigned int i = 0; i < multimesh.tex_f_count; ++i) { line = delete_symbol(getLine(stream), '\t'); - std::istringstream ss(line); + std::istringstream ss(line); face_t texface; while (!ss.eof()) - { + { unsigned int idx = 0; - ss >> idx; + ss >> idx; texface.push_back(idx-1); } multimesh.texfaces.push_back(texface); - } + } } diff --git a/viewer/osgdb_dmd/src/reader-writer.cpp b/viewer/osgdb_dmd/src/reader-writer.cpp index a4bb87c54..9feed0bc9 100644 --- a/viewer/osgdb_dmd/src/reader-writer.cpp +++ b/viewer/osgdb_dmd/src/reader-writer.cpp @@ -65,7 +65,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterDMD::readNode(std::ifstream &stream, vertices->push_back(mesh.vertices->at(face[0])); vertices->push_back(mesh.vertices->at(face[1])); - vertices->push_back(mesh.vertices->at(face[2])); + vertices->push_back(mesh.vertices->at(face[2])); } osg::ref_ptr geom = new osg::Geometry; diff --git a/viewer/route-loader/include/abstract-loader.h b/viewer/route-loader/include/abstract-loader.h index 21e93c734..6a715dfa4 100644 --- a/viewer/route-loader/include/abstract-loader.h +++ b/viewer/route-loader/include/abstract-loader.h @@ -54,17 +54,17 @@ class ROUTE_LOADER_EXPORT RouteLoader : public osg::Referenced virtual void load(std::string routeDir, float view_dist = 1000.0f) = 0; /// Get route scene group node - virtual osg::Group *getRoot(); + virtual osg::Group *getRoot(); virtual MotionPath *getMotionPath(int direction) = 0; -protected: +protected: /// Route directory std::string routeDir; /// Route static scene root node - osg::ref_ptr root; + osg::ref_ptr root; /// Destructor virtual ~RouteLoader() {} @@ -76,7 +76,7 @@ class ROUTE_LOADER_EXPORT RouteLoader : public osg::Referenced //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -typedef RouteLoader* (*GetRouteLoader)(); +using GetRouteLoader = RouteLoader* (*)(); //------------------------------------------------------------------------------ // diff --git a/viewer/sound-manager/include/asound-log.h b/viewer/sound-manager/include/asound-log.h index b16e312ff..71a9d6074 100644 --- a/viewer/sound-manager/include/asound-log.h +++ b/viewer/sound-manager/include/asound-log.h @@ -20,7 +20,7 @@ #include class LogFileHandler : public QObject -{ +{ public: /// Constructor diff --git a/viewer/viewer/include/QGraphicsViewAdapter.h b/viewer/viewer/include/QGraphicsViewAdapter.h index dccaf7b15..f050873fd 100644 --- a/viewer/viewer/include/QGraphicsViewAdapter.h +++ b/viewer/viewer/include/QGraphicsViewAdapter.h @@ -89,7 +89,7 @@ class QGraphicsViewAdapter : public QObject int _width; int _height; - typedef std::map KeyMap; + using KeyMap = std::map; KeyMap _keyMap; Qt::KeyboardModifiers _qtKeyModifiers; diff --git a/viewer/viewer/include/abstract-manipulator.h b/viewer/viewer/include/abstract-manipulator.h index 764169e3f..0fed00a4c 100644 --- a/viewer/viewer/include/abstract-manipulator.h +++ b/viewer/viewer/include/abstract-manipulator.h @@ -1,11 +1,11 @@ -#ifndef ABSTRACT_MANIPULATOR_H -#define ABSTRACT_MANIPULATOR_H +#ifndef ABSTRACT_MANIPULATOR_H +#define ABSTRACT_MANIPULATOR_H -#include +#include "camera-position.h" -#include +#include -#include "camera-position.h" +#include //------------------------------------------------------------------------------ // @@ -15,28 +15,24 @@ class AbstractManipulator : public QObject, public osgGA::TrackballManipulator Q_OBJECT public: + AbstractManipulator(QObject* parent = Q_NULLPTR); - AbstractManipulator(QObject *parent = Q_NULLPTR); - - bool handleFrame(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa); + bool handleFrame(const osgGA::GUIEventAdapter& event_adapter, osgGA::GUIActionAdapter& action_adapter); protected: + camera_position_t camera_position; - camera_position_t cp; - - double start_time; - float delta_time; + double start_time; + float delta_time; virtual ~AbstractManipulator(); virtual void process_displays_lock(); signals: - void lock_displays(bool lock); public slots: - void getCameraPosition(camera_position_t cp); }; diff --git a/viewer/viewer/include/analog-rotation.h b/viewer/viewer/include/analog-rotation.h index c0402076e..4365f6cec 100644 --- a/viewer/viewer/include/analog-rotation.h +++ b/viewer/viewer/include/analog-rotation.h @@ -1,32 +1,32 @@ -#ifndef ANALOG_ROTATION_H -#define ANALOG_ROTATION_H +#ifndef ANALOG_ROTATION_H +#define ANALOG_ROTATION_H -#include "proc-animation.h" +#include "proc-animation.h" + +#include +#include class AnalogRotation : public ProcAnimation { public: - - AnalogRotation(osg::MatrixTransform *transform); - + AnalogRotation(osg::MatrixTransform* transform); ~AnalogRotation(); private: + float min_angle; + float max_angle; + float angle; - float min_angle; - float max_angle; - float angle; - - float cur_pos; + float cur_pos; - bool infinity; + bool infinity; - osg::Vec3 axis; + osg::Vec3 axis; osg::Matrix matrix; void anim_step(float t, float dt); - bool load_config(ConfigReader &cfg); + bool load_config(ConfigReader& cfg); void update(); }; diff --git a/viewer/viewer/include/analog-translation.h b/viewer/viewer/include/analog-translation.h index 2a45638fd..187544011 100644 --- a/viewer/viewer/include/analog-translation.h +++ b/viewer/viewer/include/analog-translation.h @@ -1,7 +1,10 @@ -#ifndef ANALOG_TRANSLATION_H -#define ANALOG_TRANSLATION_H +#ifndef ANALOG_TRANSLATION_H +#define ANALOG_TRANSLATION_H -#include "proc-animation.h" +#include "proc-animation.h" + +#include +#include //------------------------------------------------------------------------------ // @@ -9,25 +12,23 @@ class AnalogTranslation : public ProcAnimation { public: - - AnalogTranslation(osg::MatrixTransform *transform); + AnalogTranslation(osg::MatrixTransform* transform); ~AnalogTranslation(); private: + float min_motion; + float max_motion; + float motion; - float min_motion; - float max_motion; - float motion; - - float cur_pos; + float cur_pos; - osg::Vec3 axis; + osg::Vec3 axis; osg::Matrix matrix; void anim_step(float t, float dt); - bool load_config(ConfigReader &cfg); + bool load_config(ConfigReader& cfg); void update(); }; diff --git a/viewer/viewer/include/anim-transform-visitor.h b/viewer/viewer/include/anim-transform-visitor.h index 016cfbe32..87aa3c1ea 100644 --- a/viewer/viewer/include/anim-transform-visitor.h +++ b/viewer/viewer/include/anim-transform-visitor.h @@ -1,9 +1,10 @@ #ifndef ANIM_TRANSFORM_VISITOR_H #define ANIM_TRANSFORM_VISITOR_H -#include #include "animations-list.h" +#include + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ diff --git a/viewer/viewer/include/animation-manager.h b/viewer/viewer/include/animation-manager.h index 0cf39a3b8..abf8695f0 100644 --- a/viewer/viewer/include/animation-manager.h +++ b/viewer/viewer/include/animation-manager.h @@ -5,7 +5,6 @@ #include #include "animations-list.h" -#include "proc-animation.h" //------------------------------------------------------------------------------ // diff --git a/viewer/viewer/include/animations-list.h b/viewer/viewer/include/animations-list.h index 99beab86f..bf48e6f8d 100644 --- a/viewer/viewer/include/animations-list.h +++ b/viewer/viewer/include/animations-list.h @@ -2,11 +2,12 @@ #define ANIMATIONS_LIST_H #include -#include "proc-animation.h" + +class ProcAnimation; //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -typedef QMap animations_t; +using animations_t = QMap; #endif // ANIMATIONS_LIST_H diff --git a/viewer/viewer/include/camera-position.h b/viewer/viewer/include/camera-position.h index 563ebad66..9daec8907 100644 --- a/viewer/viewer/include/camera-position.h +++ b/viewer/viewer/include/camera-position.h @@ -1,28 +1,25 @@ -#ifndef CAMERA_POSITION_H -#define CAMERA_POSITION_H +#ifndef CAMERA_POSITION_H +#define CAMERA_POSITION_H -#include +#include -#include +#include //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ struct camera_position_t { - osg::Vec3d position = {0.0, 0.0, 0.0}; - osg::Vec3d attitude = {-osg::PI_2, 0.0, 0.0}; - osg::Vec3d driver_pos = {0.0, 0.0, 1.75}; - osg::Vec3d viewer_pos = {0.0, 150.0, 0.0}; - osg::Vec3d front = {0.0, 1.0, 0.0}; - osg::Vec3d right = {1.0, 0.0, 0.0}; - osg::Vec3d up = {0.0, 0.0, 1.0}; - bool is_orient_bwd = false; + camera_position_t(); - camera_position_t() - { - - } + osg::Vec3d position; + osg::Vec3d attitude; + osg::Vec3d driver_pos; + osg::Vec3d viewer_pos; + osg::Vec3d front; + osg::Vec3d right; + osg::Vec3d up; + bool is_orient_bwd; }; Q_DECLARE_METATYPE(camera_position_t) diff --git a/viewer/viewer/include/config-reader.h b/viewer/viewer/include/config-reader.h index f9021ac8f..f4dd60264 100644 --- a/viewer/viewer/include/config-reader.h +++ b/viewer/viewer/include/config-reader.h @@ -12,21 +12,20 @@ class ConfigReader public: ConfigReader(); - - ConfigReader(const std::string &path); + ConfigReader(const std::string& path); virtual ~ConfigReader(); - bool load(const std::string &path); + bool load(const std::string& path); bool isOpenned() const; - osgDB::XmlNode *getConfigNode(); + osgDB::XmlNode* getConfigNode(); - osgDB::XmlNode *findSection(osgDB::XmlNode *node, const std::string §ion); + osgDB::XmlNode* findSection(osgDB::XmlNode* node, const std::string& section); template - bool getValue(const std::string §ion, const std::string ¶m, T &value) + bool getValue(const std::string& section, const std::string& param, T& value) { std::string contents = getStrValue(section, param); @@ -48,7 +47,7 @@ class ConfigReader return false; } - bool getValue(const std::string §ion, const std::string ¶m, std::string &value) + bool getValue(const std::string& section, const std::string& param, std::string& value) { std::string contents = getStrValue(section, param); @@ -63,11 +62,11 @@ class ConfigReader protected: - bool is_opened; + bool is_opened; osg::ref_ptr root; - std::string getStrValue(const std::string §ion, const std::string ¶m); + std::string getStrValue(const std::string& section, const std::string& param); }; #endif diff --git a/viewer/viewer/include/display-container.h b/viewer/viewer/include/display-container.h index bc19c4d97..20750450c 100644 --- a/viewer/viewer/include/display-container.h +++ b/viewer/viewer/include/display-container.h @@ -7,7 +7,6 @@ #include #include "display.h" -#include "display-config.h" //------------------------------------------------------------------------------ // @@ -29,6 +28,6 @@ struct display_container_t //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -typedef std::vector displays_t; +using displays_t = std::vector; #endif // DISPLAY_CONTAINER_H diff --git a/viewer/viewer/include/display-loader.h b/viewer/viewer/include/display-loader.h index 288affd52..06b49ed77 100644 --- a/viewer/viewer/include/display-loader.h +++ b/viewer/viewer/include/display-loader.h @@ -5,6 +5,8 @@ #include +#include "display-config.h" + void loadDisplayModule(const display_config_t &display_config, display_container_t *dc, osg::Node *model); diff --git a/viewer/viewer/include/display-surface-visitor.h b/viewer/viewer/include/display-surface-visitor.h index d43d9d9e1..df1c841c5 100644 --- a/viewer/viewer/include/display-surface-visitor.h +++ b/viewer/viewer/include/display-surface-visitor.h @@ -5,9 +5,10 @@ #include #include -#include "QWidgetImage.h" #include +#include "display-config.h" + class DisplaySurfaceVisitor : public osg::NodeVisitor { public: diff --git a/viewer/viewer/include/display-visitor.h b/viewer/viewer/include/display-visitor.h index ac9c608ba..942944778 100644 --- a/viewer/viewer/include/display-visitor.h +++ b/viewer/viewer/include/display-visitor.h @@ -7,6 +7,8 @@ #include "display-container.h" +#include "display-config.h" + class DisplayVisitor : public osg::NodeVisitor { public: diff --git a/viewer/viewer/include/free-manipulator.h b/viewer/viewer/include/free-manipulator.h index c12869b69..fc1675fa8 100644 --- a/viewer/viewer/include/free-manipulator.h +++ b/viewer/viewer/include/free-manipulator.h @@ -44,7 +44,7 @@ class FreeManipulator : public AbstractManipulator float angle_H; float angle_V; - osg::Camera *camera; + osg::Camera *camera; }; #endif // FREE_MANIPULATOR_H diff --git a/viewer/viewer/include/imgui-widgets-handler.h b/viewer/viewer/include/imgui-widgets-handler.h index 51e5191cc..70e1564f2 100644 --- a/viewer/viewer/include/imgui-widgets-handler.h +++ b/viewer/viewer/include/imgui-widgets-handler.h @@ -9,7 +9,7 @@ // //------------------------------------------------------------------------------ class ImGuiWidgetsHandler : public QObject, public OSGImGuiHandler -{ +{ Q_OBJECT public: diff --git a/viewer/viewer/include/material-animation-visitor.h b/viewer/viewer/include/material-animation-visitor.h index 6ba1fc2b6..68a121c18 100644 --- a/viewer/viewer/include/material-animation-visitor.h +++ b/viewer/viewer/include/material-animation-visitor.h @@ -4,6 +4,8 @@ #include #include "animations-list.h" +class ConfigReader; + class MaterialAnimationVisitor : public osg::NodeVisitor { public: diff --git a/viewer/viewer/include/material-animation.h b/viewer/viewer/include/material-animation.h index 39989cf76..72e99a22c 100644 --- a/viewer/viewer/include/material-animation.h +++ b/viewer/viewer/include/material-animation.h @@ -22,7 +22,7 @@ class MaterialAnimation : public ProcAnimation osg::Material *mat; osg::Drawable *drawable; - osg::ref_ptr stateset; + osg::ref_ptr stateset; float cur_pos; diff --git a/viewer/viewer/include/material-rgb-animation-visitor.h b/viewer/viewer/include/material-rgb-animation-visitor.h index 3a08acb3f..2aec10fd2 100644 --- a/viewer/viewer/include/material-rgb-animation-visitor.h +++ b/viewer/viewer/include/material-rgb-animation-visitor.h @@ -4,6 +4,8 @@ #include #include "animations-list.h" +class ConfigReader; + class MaterialRGBAnimationVisitor : public osg::NodeVisitor { public: diff --git a/viewer/viewer/include/model-part-animation.h b/viewer/viewer/include/model-part-animation.h index ae2871161..b57b6a743 100644 --- a/viewer/viewer/include/model-part-animation.h +++ b/viewer/viewer/include/model-part-animation.h @@ -21,7 +21,7 @@ class ModelPartAnimation : public osg::Referenced void setLastTime(double lastTime); -private: +private: osg::MatrixTransform *transform; osg::ref_ptr path; diff --git a/viewer/viewer/include/model-parts-list.h b/viewer/viewer/include/model-parts-list.h index f658f21dc..847b77566 100644 --- a/viewer/viewer/include/model-parts-list.h +++ b/viewer/viewer/include/model-parts-list.h @@ -4,6 +4,6 @@ #include #include "model-part-animation.h" -typedef std::vector> model_parts_list_t; +using model_parts_list_t = std::vector>; #endif // MODEL_PARTS_LIST_H diff --git a/viewer/viewer/include/proc-animation.h b/viewer/viewer/include/proc-animation.h index 58f955068..296af5c85 100644 --- a/viewer/viewer/include/proc-animation.h +++ b/viewer/viewer/include/proc-animation.h @@ -1,10 +1,15 @@ -#ifndef PROC_ANIMATION_H -#define PROC_ANIMATION_H +#ifndef PROC_ANIMATION_H +#define PROC_ANIMATION_H -#include -#include "math-funcs.h" -#include "config-reader.h" -#include +#include +#include + +namespace osg +{ + class MatrixTransform; +}; + +class ConfigReader; //------------------------------------------------------------------------------ // @@ -13,39 +18,21 @@ class ProcAnimation { public: - ProcAnimation() - : pos(0.0) - , duration(0.0) - , signal_id(0) - , transform(nullptr) - , name("") - { - - } - - ProcAnimation(const std::string &name) - : pos(0.0) - , duration(0.0) - , signal_id(0) - , transform(nullptr) - , name(name) - { - - } - - ProcAnimation(osg::MatrixTransform *transform); + ProcAnimation(); + ProcAnimation(const std::string& name); + ProcAnimation(osg::MatrixTransform* transform); virtual ~ProcAnimation(); void step(float t, float dt); - void setName(const std::string &name); + void setName(const std::string& name); - std::string getName() const; + const std::string& getName() const; - bool load(const std::string &path); + bool load(const std::string& path); - bool load(ConfigReader &cfg); + bool load(ConfigReader& cfg); void setPosition(float pos); @@ -55,41 +42,35 @@ class ProcAnimation struct key_point_t { + key_point_t(); + float param; float value; - - key_point_t() - : param(0.0f) - , value(0.0f) - { - - } }; - float pos; - float duration; + float pos; + float duration; - size_t signal_id; + size_t signal_id; - osg::MatrixTransform *transform; - std::string name; + osg::MatrixTransform* transform; + std::string name; - bool is_fixed_signal; - float fixed_signal; + bool is_fixed_signal; + float fixed_signal; std::vector keypoints; - virtual bool load_config(ConfigReader &cfg) = 0; + virtual bool load_config(ConfigReader& cfg) = 0; virtual void anim_step(float t, float dt) = 0; float interpolate(float value); private: + bool loadKeyPoints(ConfigReader& cfg); - bool loadKeyPoints(ConfigReader &cfg); - - key_point_t findBeginKeyPoint(float value, size_t &next_idx); + key_point_t findBeginKeyPoint(float value, size_t& next_idx); }; #endif // PROC_ANIMATION_H diff --git a/viewer/viewer/include/train-exterior.h b/viewer/viewer/include/train-exterior.h index 8dd8031da..151700074 100644 --- a/viewer/viewer/include/train-exterior.h +++ b/viewer/viewer/include/train-exterior.h @@ -27,11 +27,9 @@ #include "animation-manager.h" #include "camera-position.h" #include "settings.h" -#include "global-const.h" + #include "simulator-info-struct.h" #include "simulator-update-struct.h" -#include "config-reader.h" -#include "display.h" #include "sound-manager.h" diff --git a/viewer/viewer/include/train-manipulator.h b/viewer/viewer/include/train-manipulator.h index 25fd4458b..cb7c2ebd3 100644 --- a/viewer/viewer/include/train-manipulator.h +++ b/viewer/viewer/include/train-manipulator.h @@ -15,7 +15,7 @@ class TrainManipulator : public AbstractManipulator virtual osg::Matrixd getMatrix() const; - virtual osg::Matrixd getInverseMatrix() const; + virtual osg::Matrixd getInverseMatrix() const; bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, @@ -29,7 +29,7 @@ class TrainManipulator : public AbstractManipulator protected: - virtual ~TrainManipulator(); + virtual ~TrainManipulator(); private: diff --git a/viewer/viewer/include/vehicle-loader.h b/viewer/viewer/include/vehicle-loader.h index 36de6e003..a761e1214 100644 --- a/viewer/viewer/include/vehicle-loader.h +++ b/viewer/viewer/include/vehicle-loader.h @@ -15,10 +15,9 @@ #ifndef VEHICLE_LOADER_H #define VEHICLE_LOADER_H +#include "osg/Vec3" #include -#include "vehicle-exterior.h" - /*! * \fn @@ -27,7 +26,7 @@ //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -osg::Group *loadVehicle(const std::string &configDir, const std::string &configName); +osg::Node *loadVehicle(const std::string &configDir, const std::string &configName, osg::Vec3& vehicle_shift); /*! @@ -50,6 +49,6 @@ void loadCabine(osg::Group *vehicle, //------------------------------------------------------------------------------ float getLength(const std::string &configDir, const std::string &configName); -osg::Vec3 getDirverPosition(const std::string &configDir, const std::string &configName); +osg::Vec3 getDriverPosition(const std::string &configDir, const std::string &configName); #endif // VEHICLE_LOADER_H diff --git a/viewer/viewer/include/viewer.h b/viewer/viewer/include/viewer.h index 1c59ab787..bf1d02df3 100644 --- a/viewer/viewer/include/viewer.h +++ b/viewer/viewer/include/viewer.h @@ -93,7 +93,7 @@ class RouteViewer : public QObject osg::ref_ptr imguiWidgetsHandler = nullptr; /// Initialization - bool init(int argc, char *argv[]); + bool init(int argc, char *argv[]); /// Load settings from config settings_t loadSettings(const std::string &cfg_path) const; diff --git a/viewer/viewer/src/abstract-manipulator.cpp b/viewer/viewer/src/abstract-manipulator.cpp index a28f2a78f..3eec94a71 100644 --- a/viewer/viewer/src/abstract-manipulator.cpp +++ b/viewer/viewer/src/abstract-manipulator.cpp @@ -1,13 +1,14 @@ -#include "abstract-manipulator.h" -#include +#include "abstract-manipulator.h" + +#include //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -AbstractManipulator::AbstractManipulator(QObject *parent) - : QObject (parent) - , osgGA::TrackballManipulator () - , cp(camera_position_t()) +AbstractManipulator::AbstractManipulator(QObject* parent) + : QObject(parent) + , osgGA::TrackballManipulator() + , camera_position() , start_time(0.0) , delta_time(0.0f) { @@ -17,15 +18,17 @@ AbstractManipulator::AbstractManipulator(QObject *parent) //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -bool AbstractManipulator::handleFrame(const osgGA::GUIEventAdapter &ea, - osgGA::GUIActionAdapter &aa) +bool AbstractManipulator::handleFrame( + const osgGA::GUIEventAdapter& event_adapter, + osgGA::GUIActionAdapter& action_adapter +) { - (void) ea; - - osgViewer::Viewer *viewer = dynamic_cast(&aa); + auto* viewer = dynamic_cast(&action_adapter); if (!viewer) + { return false; + } double time = viewer->getFrameStamp()->getReferenceTime(); delta_time = static_cast(time - start_time); @@ -37,25 +40,21 @@ bool AbstractManipulator::handleFrame(const osgGA::GUIEventAdapter &ea, //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -AbstractManipulator::~AbstractManipulator() -{ - -} +AbstractManipulator::~AbstractManipulator() = default; //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ void AbstractManipulator::process_displays_lock() { - } //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -void AbstractManipulator::getCameraPosition(camera_position_t cp) +void AbstractManipulator::getCameraPosition(camera_position_t camera_position) { - this->cp = cp; + this->camera_position = camera_position; process_displays_lock(); } diff --git a/viewer/viewer/src/analog-rotation.cpp b/viewer/viewer/src/analog-rotation.cpp index 0413a81a4..4381d77a5 100644 --- a/viewer/viewer/src/analog-rotation.cpp +++ b/viewer/viewer/src/analog-rotation.cpp @@ -1,5 +1,11 @@ #include "analog-rotation.h" +#include "math-funcs.h" + +#include "config-reader.h" + +#include + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -44,7 +50,7 @@ bool AnalogRotation::load_config(ConfigReader &cfg) { std::string secName = "AnalogRotation"; - cfg.getValue(secName, "SignalID", signal_id); + cfg.getValue(secName, "SignalID", signal_id); cfg.getValue(secName, "Duration", duration); is_fixed_signal = cfg.getValue(secName, "FixedSignal", fixed_signal); @@ -58,7 +64,7 @@ bool AnalogRotation::load_config(ConfigReader &cfg) std::istringstream ss(tmp); - ss >> axis.x() >> axis.y() >> axis.z(); + ss >> axis.x() >> axis.y() >> axis.z(); return true; } @@ -68,11 +74,15 @@ bool AnalogRotation::load_config(ConfigReader &cfg) //------------------------------------------------------------------------------ void AnalogRotation::update() { - if (keypoints.size() == 0) + if (keypoints.empty()) + { return; + } if (!infinity) - angle = cut(angle, (*keypoints.begin()).value, (*(keypoints.end() - 1)).value); + { + angle = cut(angle, keypoints.front().value, keypoints.back().value); + } osg::Matrix rotate = osg::Matrixf::rotate(angle * osg::PIf / 180.0f, axis); transform->setMatrix(rotate * matrix); diff --git a/viewer/viewer/src/analog-translation.cpp b/viewer/viewer/src/analog-translation.cpp index 2a9023957..9c4adb480 100644 --- a/viewer/viewer/src/analog-translation.cpp +++ b/viewer/viewer/src/analog-translation.cpp @@ -1,5 +1,11 @@ #include "analog-translation.h" +#include "math-funcs.h" + +#include "config-reader.h" + +#include + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -44,7 +50,7 @@ bool AnalogTranslation::load_config(ConfigReader &cfg) { std::string secName = "AnalogTranslation"; - cfg.getValue(secName, "SignalID", signal_id); + cfg.getValue(secName, "SignalID", signal_id); cfg.getValue(secName, "Duration", duration); is_fixed_signal = cfg.getValue(secName, "FixedSignal", fixed_signal); @@ -53,7 +59,7 @@ bool AnalogTranslation::load_config(ConfigReader &cfg) std::istringstream ss(tmp); - ss >> axis.x() >> axis.y() >> axis.z(); + ss >> axis.x() >> axis.y() >> axis.z(); return true; } @@ -66,7 +72,7 @@ void AnalogTranslation::update() if (keypoints.size() == 0) return; - motion = cut(motion, (*keypoints.begin()).value, (*(keypoints.end() - 1)).value); + motion = cut(motion, keypoints.front().value, keypoints.back().value); osg::Matrix translate = osg::Matrixf::translate(axis * motion); transform->setMatrix(translate * matrix); diff --git a/viewer/viewer/src/anim-transform-visitor.cpp b/viewer/viewer/src/anim-transform-visitor.cpp index d556fc076..59a05e5b9 100644 --- a/viewer/viewer/src/anim-transform-visitor.cpp +++ b/viewer/viewer/src/anim-transform-visitor.cpp @@ -3,11 +3,12 @@ #include "config-reader.h" #include "analog-rotation.h" #include "analog-translation.h" -#include "material-animation.h" #include "material-animation-visitor.h" #include "material-rgb-animation-visitor.h" +#include + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -61,10 +62,9 @@ ProcAnimation *AnimTransformVisitor::create_animation(const std::string &name, osgDB::XmlNode *rootNode = cfg.getConfigNode(); - - for (auto it = rootNode->children.begin(); it != rootNode->children.end(); ++it) + for (auto child_ref_ptr : rootNode->children) { - osgDB::XmlNode *child = *it; + osgDB::XmlNode *child = child_ref_ptr.get(); ProcAnimation *animation = nullptr; diff --git a/viewer/viewer/src/animation-manager.cpp b/viewer/viewer/src/animation-manager.cpp index 92181c028..06e4cd4bd 100644 --- a/viewer/viewer/src/animation-manager.cpp +++ b/viewer/viewer/src/animation-manager.cpp @@ -2,6 +2,8 @@ #include +#include "proc-animation.h" + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -53,9 +55,8 @@ bool AnimationManager::handle(const osgGA::GUIEventAdapter &ea, //------------------------------------------------------------------------------ void AnimationManager::step(float t, float dt) { - for (auto it = animations->begin(); it != animations->end(); ++it) + for (auto* anim : *animations) { - ProcAnimation *anim = it.value(); anim->step(t, dt); } } diff --git a/viewer/viewer/src/camera-position.cpp b/viewer/viewer/src/camera-position.cpp new file mode 100644 index 000000000..a34b49bb1 --- /dev/null +++ b/viewer/viewer/src/camera-position.cpp @@ -0,0 +1,13 @@ +#include "camera-position.h" + +camera_position_t::camera_position_t() + : position(0.0, 0.0, 0.0) + , attitude(-osg::PI_2, 0.0, 0.0) + , driver_pos(0.0, 0.0, 1.75) + , viewer_pos(0.0, 150.0, 0.0) + , front(0.0, 1.0, 0.0) + , right(1.0, 0.0, 0.0) + , up(0.0, 0.0, 1.0) + , is_orient_bwd(false) +{ +} diff --git a/viewer/viewer/src/config-reader.cpp b/viewer/viewer/src/config-reader.cpp index 8d7aeab6e..20345f457 100644 --- a/viewer/viewer/src/config-reader.cpp +++ b/viewer/viewer/src/config-reader.cpp @@ -92,11 +92,11 @@ osgDB::XmlNode *ConfigReader::findSection(osgDB::XmlNode *node, const std::strin { osg::ref_ptr secNode; - for (auto it = node->children.begin(); it != node->children.end(); ++it) + for (auto child : node->children) { - if ((*it)->name == section) + if (child->name == section) { - secNode = (*it); + secNode = child; break; } } diff --git a/viewer/viewer/src/display-loader.cpp b/viewer/viewer/src/display-loader.cpp index 834c49afc..90f3b3d55 100644 --- a/viewer/viewer/src/display-loader.cpp +++ b/viewer/viewer/src/display-loader.cpp @@ -18,7 +18,7 @@ void loadDisplayModule(const display_config_t &display_config, { OSG_FATAL << "Module " << display_config.module_name.toStdString() << " is't found"; return; - } + } DisplayVisitor dv(dc, display_config); dv.setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN); diff --git a/viewer/viewer/src/display-visitor.cpp b/viewer/viewer/src/display-visitor.cpp index f58b4e012..33716eed9 100644 --- a/viewer/viewer/src/display-visitor.cpp +++ b/viewer/viewer/src/display-visitor.cpp @@ -1,7 +1,6 @@ #include "display-visitor.h" #include -#include "QWidgetImage.h" #include #include "display-surface-visitor.h" diff --git a/viewer/viewer/src/free-manipulator.cpp b/viewer/viewer/src/free-manipulator.cpp index 98d045bc8..645b76fdb 100644 --- a/viewer/viewer/src/free-manipulator.cpp +++ b/viewer/viewer/src/free-manipulator.cpp @@ -1,10 +1,7 @@ #include "free-manipulator.h" -#include "math-funcs.h" #include -#include - //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -58,10 +55,10 @@ void FreeManipulator::init(const osgGA::GUIEventAdapter &ea, Q_UNUSED(ea) Q_UNUSED(aa) - init_pos = cp; + init_pos = camera_position; osgViewer::Viewer *viewer = static_cast(&aa); - camera = viewer->getCamera(); + camera = viewer->getCamera(); } //------------------------------------------------------------------------------ diff --git a/viewer/viewer/src/hud.cpp b/viewer/viewer/src/hud.cpp index ec7d76120..6915bc249 100644 --- a/viewer/viewer/src/hud.cpp +++ b/viewer/viewer/src/hud.cpp @@ -3,8 +3,6 @@ #include -#include - //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -17,7 +15,7 @@ HUD::HUD(int width, int height, QObject *parent) : QObject (parent) FileSystem &fs = FileSystem::getInstance(); fontPath = fs.getFontsDir() + fs.separator() + "dejavu-sans-mono.ttf"; - camera = createCamera(width, height); + camera = createCamera(width, height); camera->setViewport(0, 0, width, height); view->setCamera(camera.get()); } @@ -105,7 +103,7 @@ osgText::Text *HUD::createText(const osg::Vec3 &position, text->setFont(fontPath); text->setCharacterSize(size); text->setPosition(position); - text->setText(content.c_str()); + text->setText(content.c_str()); text->setColor(color); return text.release(); diff --git a/viewer/viewer/src/imgui-widgets-handler.cpp b/viewer/viewer/src/imgui-widgets-handler.cpp index fab00e9b4..9c1341020 100644 --- a/viewer/viewer/src/imgui-widgets-handler.cpp +++ b/viewer/viewer/src/imgui-widgets-handler.cpp @@ -96,7 +96,7 @@ void ImGuiWidgetsHandler::showQuitDialog(bool &is_show) { ImGui::SetCursorPos(ImVec2(cx, cy)); is_show = false; - } + } ImGui::End(); } diff --git a/viewer/viewer/src/keys-translator.cpp b/viewer/viewer/src/keys-translator.cpp index 365bb0e4a..ca909c35a 100644 --- a/viewer/viewer/src/keys-translator.cpp +++ b/viewer/viewer/src/keys-translator.cpp @@ -43,5 +43,5 @@ int KeysTranslator::translate(int key) #endif - return code; + return code; } diff --git a/viewer/viewer/src/lighting.cpp b/viewer/viewer/src/lighting.cpp index b334ee35f..d71716219 100644 --- a/viewer/viewer/src/lighting.cpp +++ b/viewer/viewer/src/lighting.cpp @@ -44,7 +44,7 @@ void initEnvironmentLight(osg::Group *root, sun->setDirection(sunDir); osg::ref_ptr light0 = new osg::LightSource; - light0->setLight(sun); + light0->setLight(sun); root->getOrCreateStateSet()->setMode(GL_LIGHT0, osg::StateAttribute::ON); root->addChild(light0.get()); diff --git a/viewer/viewer/src/main.cpp b/viewer/viewer/src/main.cpp index 3db831acd..0a6c00ff3 100644 --- a/viewer/viewer/src/main.cpp +++ b/viewer/viewer/src/main.cpp @@ -13,7 +13,6 @@ */ #include "main.h" -#include /*! * \fn diff --git a/viewer/viewer/src/material-animation-visitor.cpp b/viewer/viewer/src/material-animation-visitor.cpp index ad83a0fea..3d1e8cb28 100644 --- a/viewer/viewer/src/material-animation-visitor.cpp +++ b/viewer/viewer/src/material-animation-visitor.cpp @@ -3,6 +3,8 @@ #include +#include + MaterialAnimationVisitor::MaterialAnimationVisitor(animations_t *animations, ConfigReader *cfg) : osg::NodeVisitor() , animations(animations) diff --git a/viewer/viewer/src/material-animation.cpp b/viewer/viewer/src/material-animation.cpp index c9cd5dbb9..241d8bc28 100644 --- a/viewer/viewer/src/material-animation.cpp +++ b/viewer/viewer/src/material-animation.cpp @@ -2,6 +2,10 @@ #include +#include + +#include "config-reader.h" + MaterialAnimation::MaterialAnimation(osg::Material *mat, osg::Drawable *drawable) : ProcAnimation() , mat(new osg::Material) diff --git a/viewer/viewer/src/material-rgb-animation-visitor.cpp b/viewer/viewer/src/material-rgb-animation-visitor.cpp index 17de21bcd..266f70d69 100644 --- a/viewer/viewer/src/material-rgb-animation-visitor.cpp +++ b/viewer/viewer/src/material-rgb-animation-visitor.cpp @@ -3,6 +3,8 @@ #include +#include + MaterialRGBAnimationVisitor::MaterialRGBAnimationVisitor(animations_t *animations, ConfigReader *cfg) : osg::NodeVisitor() diff --git a/viewer/viewer/src/material-rgb-animation.cpp b/viewer/viewer/src/material-rgb-animation.cpp index 5d1e34ac1..93e2b9ba6 100644 --- a/viewer/viewer/src/material-rgb-animation.cpp +++ b/viewer/viewer/src/material-rgb-animation.cpp @@ -1,5 +1,9 @@ #include "material-rgb-animation.h" +#include + +#include "config-reader.h" + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ diff --git a/viewer/viewer/src/model-part-animation.cpp b/viewer/viewer/src/model-part-animation.cpp index 66b549e11..f752f62f5 100644 --- a/viewer/viewer/src/model-part-animation.cpp +++ b/viewer/viewer/src/model-part-animation.cpp @@ -1,5 +1,4 @@ #include "model-part-animation.h" -#include "animation-path-callback.h" //------------------------------------------------------------------------------ // @@ -14,7 +13,7 @@ ModelPartAnimation::ModelPartAnimation(osg::MatrixTransform *transform) osg::AnimationPathCallback *callback = dynamic_cast(transform->getUpdateCallback()); if (callback == nullptr) - return; + return; path = callback->getAnimationPath(); @@ -62,7 +61,7 @@ void ModelPartAnimation::update() if (path == nullptr) return; - osg::Matrix matrix; + osg::Matrix matrix; path->getMatrix(pos * path->getLastTime(), matrix); diff --git a/viewer/viewer/src/proc-animation.cpp b/viewer/viewer/src/proc-animation.cpp index 116efb073..c09a9a5fe 100644 --- a/viewer/viewer/src/proc-animation.cpp +++ b/viewer/viewer/src/proc-animation.cpp @@ -1,29 +1,51 @@ #include "proc-animation.h" #include "get-value.h" +#include "config-reader.h" + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -ProcAnimation::ProcAnimation(osg::MatrixTransform *transform) +ProcAnimation::ProcAnimation() : pos(0.0f) , duration(0.0f) , signal_id(0) - , transform(transform) + , transform(nullptr) , name("") - , is_fixed_signal(false) - , fixed_signal(0.0f) { - } //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -ProcAnimation::~ProcAnimation() +ProcAnimation::ProcAnimation(const std::string& name) + : pos(0.0f) + , duration(0.0f) + , signal_id(0) + , transform(nullptr) + , name(name) { +} +//------------------------------------------------------------------------------ +// +//------------------------------------------------------------------------------ +ProcAnimation::ProcAnimation(osg::MatrixTransform* transform) + : pos(0.0f) + , duration(0.0f) + , signal_id(0) + , transform(transform) + , name("") + , is_fixed_signal(false) + , fixed_signal(0.0f) +{ } +//------------------------------------------------------------------------------ +// +//------------------------------------------------------------------------------ +ProcAnimation::~ProcAnimation() = default; + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -43,7 +65,7 @@ void ProcAnimation::setName(const std::string &name) //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -std::string ProcAnimation::getName() const +const std::string& ProcAnimation::getName() const { return name; } @@ -93,6 +115,15 @@ size_t ProcAnimation::getSignalID() const return signal_id; } +//------------------------------------------------------------------------------ +// +//------------------------------------------------------------------------------ +ProcAnimation::key_point_t::key_point_t() + : param(0.0f) + , value(0.0f) +{ +} + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -106,9 +137,9 @@ bool ProcAnimation::loadKeyPoints(ConfigReader &cfg) return false; } - for (auto it = config_node->children.begin(); it != config_node->children.end(); ++it) + for (auto child_ref_ptr : config_node->children) { - osgDB::XmlNode *child = *it; + osgDB::XmlNode *child = child_ref_ptr.get(); if (child->name == "KeyPoint") { diff --git a/viewer/viewer/src/rails-manipulator.cpp b/viewer/viewer/src/rails-manipulator.cpp index 046bbd80a..497e3922d 100644 --- a/viewer/viewer/src/rails-manipulator.cpp +++ b/viewer/viewer/src/rails-manipulator.cpp @@ -1,5 +1,4 @@ #include "rails-manipulator.h" -#include "math-funcs.h" #include @@ -21,13 +20,13 @@ RailsManipulator::RailsManipulator(settings_t settings, QObject *parent) //------------------------------------------------------------------------------ osg::Matrixd RailsManipulator::getMatrix() const { - osg::Matrix matrix = osg::Matrix::translate(osg::Vec3f(cp.driver_pos.x() + rel_pos.x(), - cp.driver_pos.z() + rel_pos.z(), - -cp.driver_pos.y() - rel_pos.y())); + osg::Matrix matrix = osg::Matrix::translate(osg::Vec3f(camera_position.driver_pos.x() + rel_pos.x(), + camera_position.driver_pos.z() + rel_pos.z(), + -camera_position.driver_pos.y() - rel_pos.y())); - matrix *= osg::Matrix::rotate(static_cast(-cp.attitude.x()), osg::Vec3(1.0f, 0.0f, 0.0f)); - matrix *= osg::Matrix::rotate(static_cast(-cp.attitude.z()), osg::Vec3(0.0f, 0.0f, 1.0f)); - matrix *= osg::Matrix::translate(cp.position); + matrix *= osg::Matrix::rotate(static_cast(-camera_position.attitude.x()), osg::Vec3(1.0f, 0.0f, 0.0f)); + matrix *= osg::Matrix::rotate(static_cast(-camera_position.attitude.z()), osg::Vec3(0.0f, 0.0f, 1.0f)); + matrix *= osg::Matrix::translate(camera_position.position); return matrix; } diff --git a/viewer/viewer/src/stat-manipulator.cpp b/viewer/viewer/src/stat-manipulator.cpp index 2d777e122..19fbe43bf 100644 --- a/viewer/viewer/src/stat-manipulator.cpp +++ b/viewer/viewer/src/stat-manipulator.cpp @@ -21,7 +21,7 @@ void StaticManipulator::init(const osgGA::GUIEventAdapter &ea, Q_UNUSED(ea) Q_UNUSED(aa) - init_pos = cp; + init_pos = camera_position; } //------------------------------------------------------------------------------ @@ -48,7 +48,7 @@ osg::Matrixd StaticManipulator::getInverseMatrix() const osg::Vec3d shift = init_pos.right * dist * dir; shift += osg::Vec3d(0.0, 0.0, settings.stat_cam_height); - osg::Matrix invMatrix = osg::Matrix::lookAt(init_pos.viewer_pos + shift, cp.position, osg::Vec3d(osg::Z_AXIS)); + osg::Matrix invMatrix = osg::Matrix::lookAt(init_pos.viewer_pos + shift, camera_position.position, osg::Vec3d(osg::Z_AXIS)); return invMatrix; } diff --git a/viewer/viewer/src/traffic-light.cpp b/viewer/viewer/src/traffic-light.cpp index ed2df4594..5c3f14b9a 100644 --- a/viewer/viewer/src/traffic-light.cpp +++ b/viewer/viewer/src/traffic-light.cpp @@ -2,6 +2,9 @@ #include #include +#include + +#include "proc-animation.h" //------------------------------------------------------------------------------ // @@ -43,7 +46,7 @@ void TrafficLight::deserialize(QByteArray &data) stream >> pos.x() >> pos.y() >> pos.z(); stream >> orth.x() >> orth.y() >> orth.z(); stream >> right.x() >> right.y() >> right.z(); - stream >> up.x() >> up.y() >> up.z(); + stream >> up.x() >> up.y() >> up.z(); } //------------------------------------------------------------------------------ @@ -58,16 +61,15 @@ void TrafficLight::update() if (lens_state != old_lens_state) { - for (auto animation = animations.begin(); animation != animations.end(); ++animation) + for (auto* anim : animations) { - ProcAnimation *anim = animation.value(); - anim->setPosition(lens_state[animation.value()->getSignalID()]); + anim->setPosition(lens_state[anim->getSignalID()]); } std::cout << "Updated signal " << this->getConnectorName().toStdString() << std::endl; old_lens_state = lens_state; - } + } } //------------------------------------------------------------------------------ diff --git a/viewer/viewer/src/traffic-lights-handler.cpp b/viewer/viewer/src/traffic-lights-handler.cpp index bd5278e6a..c2e642972 100644 --- a/viewer/viewer/src/traffic-lights-handler.cpp +++ b/viewer/viewer/src/traffic-lights-handler.cpp @@ -43,15 +43,13 @@ bool TrafficLightsHandler::handle(const osgGA::GUIEventAdapter &ea, { case osgGA::GUIEventAdapter::FRAME: { - for (auto tl = traffic_lights_fwd.begin(); tl != traffic_lights_fwd.end(); ++tl) + for (auto* traffic_light : traffic_lights_fwd) { - TrafficLight *traffic_light = tl.value(); traffic_light->update(); } - for (auto tl = traffic_lights_bwd.begin(); tl != traffic_lights_bwd.end(); ++tl) + for (auto* traffic_light : traffic_lights_bwd) { - TrafficLight *traffic_light = tl.value(); traffic_light->update(); } @@ -243,15 +241,13 @@ void TrafficLightsHandler::slotUpdateBusyData(QByteArray &data) //------------------------------------------------------------------------------ void TrafficLightsHandler::load_signal_models(const settings_t &settings) { - for (auto it = traffic_lights_fwd.begin(); it != traffic_lights_fwd.end(); ++it) + for (auto* tl : traffic_lights_fwd) { - TrafficLight *tl = it.value(); load_signal_model(tl, settings); } - for (auto it = traffic_lights_bwd.begin(); it != traffic_lights_bwd.end(); ++it) + for (auto* tl : traffic_lights_bwd) { - TrafficLight *tl = it.value(); load_signal_model(tl, settings); } } diff --git a/viewer/viewer/src/train-exterior.cpp b/viewer/viewer/src/train-exterior.cpp index cbf0a2997..c1c4a18ef 100644 --- a/viewer/viewer/src/train-exterior.cpp +++ b/viewer/viewer/src/train-exterior.cpp @@ -14,13 +14,17 @@ #include "train-exterior.h" +#include "animations-list.h" #include "config-reader.h" -#include "get-value.h" +#include "display-container.h" #include "filesystem.h" -#include "math-funcs.h" +#include "osg/CopyOp" +#include "osg/Group" +#include "osg/Vec3" #include "vehicle-loader.h" +#include #include #include @@ -28,6 +32,7 @@ #include "anim-transform-visitor.h" #include #include +#include #include "model-animation.h" @@ -311,6 +316,19 @@ std::vector TrainExteriorHandler::getAnimManagers() return anim_managers; } +struct vehicle_data_t +{ + osg::Vec3 vehicle_shift; + osg::ref_ptr model; + osg::Vec3 cabine_shift; + osg::ref_ptr cabine; + osg::Vec3 driver_position; + std::vector full_animation_paths; + std::vector animation_names; + std::string anim_config_dir; + std::vector sounds_id; +}; + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ @@ -318,6 +336,9 @@ void TrainExteriorHandler::load(const simulator_vehicles_info_t &info_data) { int count = info_data.vehicles.size(); + // std::map, vehicle_exterior_t> unique_exteriors; + std::map, vehicle_data_t> unique_vehicles; + for (int i = 0; i < count; ++i) { OSG_FATAL << "Vehicle " << i + 1 << " / " << count << " loading" << std::endl; @@ -328,7 +349,27 @@ void TrainExteriorHandler::load(const simulator_vehicles_info_t &info_data) QString cfg_file_tmp = info_data.vehicles[i].vehicle_config_file; std::string cfg_file = cfg_file_tmp.toStdString(); - osg::ref_ptr vehicle_model = loadVehicle(cfg_dir, cfg_file); + vehicle_data_t vehicle_data; + osg::ref_ptr vehicle_node; + + auto found_iterator = unique_vehicles.find(std::make_pair(cfg_dir, cfg_file)); + if (found_iterator != unique_vehicles.end()) + { + vehicle_data = found_iterator->second; + vehicle_node = vehicle_data.model; + } + else + { + vehicle_node = loadVehicle(cfg_dir, cfg_file, vehicle_data.vehicle_shift); + } + + osg::ref_ptr transShift = new osg::MatrixTransform(osg::Matrix::translate(vehicle_data.vehicle_shift)); + if (vehicle_node.valid()) + { + transShift->addChild(vehicle_node); + } + osg::ref_ptr vehicle_model = new osg::Group; + vehicle_model->addChild(transShift); if (!vehicle_model.valid()) { @@ -347,9 +388,9 @@ void TrainExteriorHandler::load(const simulator_vehicles_info_t &info_data) osg::ref_ptr cabine; loadCabine(vehicle_model.get(), cfg_dir, cfg_file, cabine); - osg::Vec3 driver_pos = getDirverPosition(cfg_dir, cfg_file); + osg::Vec3 driver_pos = getDriverPosition(cfg_dir, cfg_file); - vehicle_exterior_t vehicle_ext = vehicle_exterior_t(); + vehicle_exterior_t vehicle_ext; vehicle_ext.transform->addChild(vehicle_model.get()); vehicle_ext.cabine = cabine; vehicle_ext.driver_pos = driver_pos; @@ -365,6 +406,7 @@ void TrainExteriorHandler::load(const simulator_vehicles_info_t &info_data) vehicles_ext.push_back(vehicle_ext); trainExterior->addChild(vehicle_ext.transform.get()); + OSG_FATAL << "Vehicle " << i + 1 << " / " << count << " loaded" << std::endl; std::cout << "Vehicle " << i + 1 << " / " << count << " loaded" << std::endl; } @@ -496,14 +538,17 @@ void TrainExteriorHandler::moveTrain() vehicles_ext[i].next_vehicle = update_data.vehicles[i].next_vehicle; // Model animations update - for (auto it = vehicles_ext[i].anims->begin(); it != vehicles_ext[i].anims->end(); ++it) + for (auto* animation : *vehicles_ext[i].anims) { - ProcAnimation *animation = it.value(); size_t signal_id = animation->getSignalID(); if (signal_id < update_data.vehicles[i].analogSignal.size()) + { animation->setPosition(update_data.vehicles[i].analogSignal[signal_id]); + } else + { animation->setPosition(0.0f); + } } // Sounds update @@ -791,9 +836,9 @@ void TrainExteriorHandler::loadModelAnimations(const std::string &configDir, osgDB::XmlNode *rootNode = cfg.getConfigNode(); - for (auto it = rootNode->children.begin(); it != rootNode->children.end(); ++it) + for (auto child_ref_ptr : rootNode->children) { - osgDB::XmlNode *child = *it; + osgDB::XmlNode *child = child_ref_ptr.get(); if (child->name == "ModelAnimation") { @@ -832,9 +877,9 @@ void TrainExteriorHandler::loadDisplays(const std::string &configDir, osgDB::XmlNode *config_node = displays_cfg.getConfigNode(); - for (auto it = config_node->children.begin(); it != config_node->children.end(); ++it) + for (auto display_node_ref_ptr : config_node->children) { - osgDB::XmlNode *display_node = *it; + osgDB::XmlNode *display_node = display_node_ref_ptr.get(); if (display_node->name == "Display") { @@ -917,9 +962,8 @@ void TrainExteriorHandler::updateDisplays() for (size_t i = 0; i < vehicles_ext.size(); ++i) { - for (auto it = vehicles_ext[i].displays->begin(); it != vehicles_ext[i].displays->end(); ++it) + for (auto* dc : *vehicles_ext[i].displays) { - display_container_t *dc = *it; std::array veh_signals; std::fill(veh_signals.begin(), veh_signals.end(), 0.0f); std::copy(update_data.vehicles[i].analogSignal.begin(), diff --git a/viewer/viewer/src/train-manipulator.cpp b/viewer/viewer/src/train-manipulator.cpp index c53add703..3fc870717 100644 --- a/viewer/viewer/src/train-manipulator.cpp +++ b/viewer/viewer/src/train-manipulator.cpp @@ -22,9 +22,9 @@ osg::Matrixd TrainManipulator::getMatrix() const { osg::Matrixd matrix; - matrix *= osg::Matrixd::rotate(-cp.attitude.x(), osg::Vec3d(1.0, 0.0, 0.0)); - matrix *= osg::Matrixd::rotate(-cp.attitude.z() + cp.is_orient_bwd * osg::PI, osg::Vec3d(0.0, 0.0, 1.0)); - matrix *= osg::Matrixd::translate(cp.position); + matrix *= osg::Matrixd::rotate(-camera_position.attitude.x(), osg::Vec3d(1.0, 0.0, 0.0)); + matrix *= osg::Matrixd::rotate(-camera_position.attitude.z() + camera_position.is_orient_bwd * osg::PI, osg::Vec3d(0.0, 0.0, 1.0)); + matrix *= osg::Matrixd::translate(camera_position.position); return matrix; } diff --git a/viewer/viewer/src/vehicle-loader.cpp b/viewer/viewer/src/vehicle-loader.cpp index 9b7c68fb6..d597db934 100644 --- a/viewer/viewer/src/vehicle-loader.cpp +++ b/viewer/viewer/src/vehicle-loader.cpp @@ -29,7 +29,6 @@ #include #include -#include "model-smooth.h" #include "texture-filtering.h" #include "model-texturing.h" @@ -61,7 +60,7 @@ osg::Node *loadModel(const std::string &modelName, const std::string &textureNam { OSG_FATAL << "ERROR: model " << model_path << " loading failed"; return nullptr; - } + } ModelTextureFilter texfilter; model->accept(texfilter); @@ -77,7 +76,7 @@ osg::Node *loadModel(const std::string &modelName, const std::string &textureNam // Set blend function for model osg::ref_ptr blendFunc = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, - osg::BlendFunc::ONE_MINUS_SRC_ALPHA); + osg::BlendFunc::ONE_MINUS_SRC_ALPHA); ss->setAttributeAndModes(blendFunc.get()); ss->setMode(GL_BLEND, osg::StateAttribute::ON); ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); @@ -99,7 +98,7 @@ osg::Node *loadModel(const std::string &modelName, const std::string &textureNam //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -osg::Group *loadVehicle(const std::string &configDir, const std::string &configName) +osg::Node *loadVehicle(const std::string &configDir, const std::string &configName, osg::Vec3& vehicle_shift) { // Group node for vehicle model loading osg::ref_ptr group = new osg::Group; @@ -130,17 +129,18 @@ osg::Group *loadVehicle(const std::string &configDir, const std::string &configN } } - osg::ref_ptr transShift = new osg::MatrixTransform(osg::Matrix::translate(shift)); + vehicle_shift = shift; + // osg::ref_ptr transShift = new osg::MatrixTransform(osg::Matrix::translate(shift)); osg::ref_ptr model = loadModel(modelName, textureName); - if (model.valid()) - { - transShift->addChild(model.get()); - } + // if (model.valid()) + // { + // transShift->addChild(model.get()); + // } - group->addChild(transShift.get()); + // group->addChild(transShift.get()); - return group.release(); + return model.release(); } //------------------------------------------------------------------------------ @@ -192,7 +192,7 @@ void loadCabine(osg::Group *vehicle, if (cabine_model.valid()) transShift->addChild(cabine_model.get()); - vehicle->addChild(transShift.get()); + vehicle->addChild(transShift.get()); } //------------------------------------------------------------------------------ @@ -226,7 +226,7 @@ float getLength(const std::string &configDir, const std::string &configName) //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -osg::Vec3 getDirverPosition(const std::string &configDir, const std::string &configName) +osg::Vec3 getDriverPosition(const std::string &configDir, const std::string &configName) { osg::Vec3 position(0.9255f, 9.0172f, 3.75f); diff --git a/viewer/zds-route-loader/include/route-path.h b/viewer/zds-route-loader/include/route-path.h index a9f8ed269..5e1769846 100644 --- a/viewer/zds-route-loader/include/route-path.h +++ b/viewer/zds-route-loader/include/route-path.h @@ -17,8 +17,6 @@ #include "abstract-path.h" -#include - #include #include diff --git a/viewer/zds-route-loader/include/scene-loader.h b/viewer/zds-route-loader/include/scene-loader.h index f13aaa5d3..578473401 100644 --- a/viewer/zds-route-loader/include/scene-loader.h +++ b/viewer/zds-route-loader/include/scene-loader.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/viewer/zds-route-loader/include/texture-loader.h b/viewer/zds-route-loader/include/texture-loader.h index a6e2a52d3..f245532a6 100644 --- a/viewer/zds-route-loader/include/texture-loader.h +++ b/viewer/zds-route-loader/include/texture-loader.h @@ -19,7 +19,7 @@ #include #include -#include "model-loader.h" + //------------------------------------------------------------------------------ // diff --git a/viewer/zds-route-loader/include/track.h b/viewer/zds-route-loader/include/track.h index cf5b21a44..0b393056b 100644 --- a/viewer/zds-route-loader/include/track.h +++ b/viewer/zds-route-loader/include/track.h @@ -11,13 +11,13 @@ * \author maisvendoo */ -#ifndef TRACK_H -#define TRACK_H +#ifndef TRACK_H +#define TRACK_H -#include -#include +#include +#include -#include +#include /*! * \struct @@ -28,42 +28,26 @@ //------------------------------------------------------------------------------ struct track_t { - int ordinate; - int voltage; - std::string arrows; - osg::Vec3 begin_point; - osg::Vec3 end_point; - int prev_uid; - int next_uid; - - float length; - osg::Vec3 orth; - osg::Vec3 attitude; - osg::Vec3 right; - float rail_coord; - - track_t() - : ordinate(0) - , voltage(0) - , arrows("") - , begin_point(osg::Vec3()) - , end_point(osg::Vec3()) - , prev_uid(-1) - , next_uid(-2) - , length(0) - , orth(osg::Vec3()) - , attitude(osg::Vec3()) - , right(osg::Vec3()) - , rail_coord(0.0f) + track_t(); - { - - } + int ordinate; + int voltage; + std::string arrows; + osg::Vec3 begin_point; + osg::Vec3 end_point; + int prev_uid; + int next_uid; + + float length; + osg::Vec3 orth; + osg::Vec3 attitude; + osg::Vec3 right; + float rail_coord; }; //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ -typedef std::vector track_data_t; +using track_data_t = std::vector; #endif // TRACK_H diff --git a/viewer/zds-route-loader/src/file-funcs.cpp b/viewer/zds-route-loader/src/file-funcs.cpp index 44aeebd85..b00673dcb 100644 --- a/viewer/zds-route-loader/src/file-funcs.cpp +++ b/viewer/zds-route-loader/src/file-funcs.cpp @@ -12,7 +12,7 @@ std::string getFileName(const std::string &path) std::vector pathElems; osgDB::getPathElements(path, pathElems); - return *(pathElems.end() - 1); + return pathElems.back(); } //------------------------------------------------------------------------------ diff --git a/viewer/zds-route-loader/src/model-loader.cpp b/viewer/zds-route-loader/src/model-loader.cpp index 378da16c9..97ceb3fb0 100644 --- a/viewer/zds-route-loader/src/model-loader.cpp +++ b/viewer/zds-route-loader/src/model-loader.cpp @@ -19,7 +19,6 @@ #include #include "texture-loader.h" -#include "texture-func.h" #include #include diff --git a/viewer/zds-route-loader/src/route-path.cpp b/viewer/zds-route-loader/src/route-path.cpp index 2fd35db8f..fb021ace8 100644 --- a/viewer/zds-route-loader/src/route-path.cpp +++ b/viewer/zds-route-loader/src/route-path.cpp @@ -163,8 +163,8 @@ bool RoutePath::load(std::istream &stream) tmp_data.push_back(track); } - track_data.push_back(*tmp_data.begin()); - length += (*tmp_data.begin()).length; + track_data.push_back(tmp_data.front()); + length += tmp_data.front().length; float rail_coord = 0.0f; diff --git a/viewer/zds-route-loader/src/scene-loader.cpp b/viewer/zds-route-loader/src/scene-loader.cpp index 05e7f4beb..22a1376a7 100644 --- a/viewer/zds-route-loader/src/scene-loader.cpp +++ b/viewer/zds-route-loader/src/scene-loader.cpp @@ -189,7 +189,7 @@ ReadResult SceneLoader::loadObjectRef(std::istream &stream) object.texture_path = tokens[2]; // Заполняем информацию о файле модели - FileSystem &fs = FileSystem::getInstance(); + FileSystem &fs = FileSystem::getInstance(); object.model_path = routeDir + object.model_path; object.texture_path = routeDir + object.texture_path; @@ -222,7 +222,7 @@ ReadResult SceneLoader::loadObjectRef(std::istream &stream) //------------------------------------------------------------------------------ ReadResult SceneLoader::loadObjectMap(std::istream &stream) { - std::string prev_name = ""; + std::string prev_name = ""; while ( !stream.eof() && !stream.fail() ) { diff --git a/viewer/zds-route-loader/src/texture-loader.cpp b/viewer/zds-route-loader/src/texture-loader.cpp index f43361e01..fb86a4cdf 100644 --- a/viewer/zds-route-loader/src/texture-loader.cpp +++ b/viewer/zds-route-loader/src/texture-loader.cpp @@ -14,6 +14,8 @@ #include "texture-loader.h" +#include "model-loader.h" + //------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ diff --git a/viewer/zds-route-loader/src/track.cpp b/viewer/zds-route-loader/src/track.cpp new file mode 100644 index 000000000..a83a54bf2 --- /dev/null +++ b/viewer/zds-route-loader/src/track.cpp @@ -0,0 +1,17 @@ +#include "track.h" + +track_t::track_t() + : ordinate(0) + , voltage(0) + , arrows("") + , begin_point() + , end_point() + , prev_uid(-1) + , next_uid(-2) + , length(0.0f) + , orth() + , attitude() + , right() + , rail_coord(0.0f) +{ +} diff --git a/viewer2/CMakeLists.txt b/viewer2/CMakeLists.txt index b611af008..852abf5cc 100644 --- a/viewer2/CMakeLists.txt +++ b/viewer2/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 3.10) -project(viewer2 LANGUAGES CXX) +set (TARGET viewer2) + +project (${TARGET}) + +set (EXECUTABLE_OUTPUT_PATH "../../bin") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -11,6 +15,19 @@ set(vsgXchange_DIR /home/ksv/Install/lib/cmake/vsgXchange) find_package(vsg REQUIRED) find_package(vsgXchange REQUIRED) -add_executable(viewer2 main.cpp) +file(GLOB ${TARGET}_SOURCES "include/*.h" "src/*.cpp") + +add_executable(${TARGET} ${${TARGET}_SOURCES}) + +target_link_libraries(${TARGET} PRIVATE + vsg::vsg + vsgXchange::vsgXchange + filesystem + network +) -target_link_libraries(viewer2 vsg::vsg vsgXchange::vsgXchange) +target_include_directories(${TARGET} PRIVATE + ../filesystem/include + ../network/include + ./include +) diff --git a/viewer2/include/RouteViewer.h b/viewer2/include/RouteViewer.h new file mode 100644 index 000000000..d2ab78c44 --- /dev/null +++ b/viewer2/include/RouteViewer.h @@ -0,0 +1,21 @@ +#ifndef ROUTE_VIEWER_H +#define ROUTE_VIEWER_H + +#include + +struct settings_t; + +class RouteViewer +{ +public: + RouteViewer(int argc, char* argv[]); + + bool isReady(); + int run(); + +private: + bool init(int argc, char* argv[]); + settings_t loadSettings(const std::string& cfg_path) const; +}; + +#endif // ROUTE_VIEWER_H diff --git a/viewer2/include/settings.h b/viewer2/include/settings.h new file mode 100644 index 000000000..11759e76e --- /dev/null +++ b/viewer2/include/settings.h @@ -0,0 +1,82 @@ +#ifndef VIEWER_SETTINGS_H +#define VIEWER_SETTINGS_H + +#include "tcp-client.h" + +#include + +#include + +struct settings_t +{ + settings_t(); + + tcp_config_t tcp_config; ///< TCP-Client settings + + int vehicles_pos_update_interval; ///< Interval for vehicles positions update, ms + int vehicles_state_update_interval; ///< Interval for vehicles states update, ms + int vehicle_controled_update_interval; ///< Interval for vehicle controlled debug strings update, ms + int client_delay; ///< Client delay for smoothing network's delays + + std::string route_dir_name; ///< Route directory name + + /// Route directory + std::string route_dir_full_path; // Temporary for displays with route map + + int x; ///< Window horizontal position + int y; ///< Window vertical position + int width; ///< Window width + int height; ///< Window height + bool fullscreen; ///< Fullscreen flag + bool vsync; + + double fovy; ///< Vertical view angle + double fovy_min; ///< Vertical view angle min + double fovy_max; ///< Vertical view angle max + + double zNear; + double zFar; + + unsigned int screen_number; ///< Screen number + + std::string name; ///< Client name for server autorization + + bool window_decoration; ///< Set/unset window decorations + bool double_buffer; ///< Set/unset double buffering + bool samples; ///< Set number of anialiasing samples + double persistence; ///< Motion blur persistence + float eye_height; ///< Cabine driver's eye height + int direction; ///< Route motion direction + std::string notify_level; ///< Notify level + float view_distance; ///< View distance + + float ext_cam_init_dist; ///< Initial distance of extrnal camera + float ext_cam_init_height; ///< Initial height of extarnel camera + float ext_cam_init_shift; ///< Inital shift of external camera + float ext_cam_rot_coeff; ///< External camera rotation coefficient + float ext_cam_speed; ///< External camera motion speed + float ext_cam_speed_coeff; ///< External camera speed coeff + float ext_cam_min_dist; ///< External camera minimal distance + float ext_cam_init_angle_H; ///< External camera initial horizontal angle + float ext_cam_init_angle_V; ///< External camera initial vertical angle + + vsg::vec3 free_cam_init_pos; ///< Free camera initial position + float free_cam_rot_coeff; ///< Free camera rotation coeff + float free_cam_speed; ///< Free camera speed + float free_cam_speed_coeff; ///< Free camera speed coeff + double free_cam_fovy_step; ///< Free camera FovY step + + float cabine_cam_rot_coeff; ///< Cabine camera rotation coeff + double cabine_cam_fovy_step; ///< Cabine camera FovY step + float cabine_cam_speed; ///< Cabine camera speed + float cabine_cam_z_min; ///< Cabine camera relative vertical shift + float cabine_cam_z_max; ///< Cabine camera relative vertical shift + + float stat_cam_dist; ///< Static camera shift + float stat_cam_height; ///< Static camera height + float stat_cam_shift; ///< Static camera shift + + unsigned int interval; +}; + +#endif // VIEWER_SETTINGS_H diff --git a/viewer2/main.cpp b/viewer2/main.cpp deleted file mode 100644 index 18b41484b..000000000 --- a/viewer2/main.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char* argv[]) -{ - try - { - vsg::CommandLine arguments(&argc, argv); - - auto options = vsg::Options::create(); - options->fileCache = vsg::getEnv("VSG_FILE_CACHE"); - options->paths = vsg::getEnvPaths("VSG_FILE_PATH"); - - options->add(vsgXchange::all::create()); - - arguments.read(options); - - auto windowTraits = vsg::WindowTraits::create(); - windowTraits->windowTitle = "Viewer2"; - windowTraits->debugLayer = arguments.read({"--debug", "-d"}); - windowTraits->apiDumpLayer = arguments.read({"--api", "-a"}); - windowTraits->synchronizationLayer = arguments.read("--sync"); - } - catch (const vsg::Exception& exception) - { - for (int i = 0; i < argc; ++i) - { - std::cerr << argv[i] << ' '; - } - std::cerr << "\n[Exception] - " << exception.message << " result = " << exception.result << std::endl; - return 1; - } - catch (const std::exception& exception) - { - for (int i = 0; i < argc; ++i) - { - std::cerr << argv[i] << ' '; - } - std::cerr << "\n[Exception] - " << exception.what() << std::endl; - return 1; - } - catch (...) - { - for (int i = 0; i < argc; ++i) - { - std::cerr << argv[i] << ' '; - } - std::cerr << "\n[Exception] - Unknown exception" << std::endl; - return 1; - } - - return 0; -} diff --git a/viewer2/src/RouteViewer.cpp b/viewer2/src/RouteViewer.cpp new file mode 100644 index 000000000..dfc5850e0 --- /dev/null +++ b/viewer2/src/RouteViewer.cpp @@ -0,0 +1,34 @@ +#include "RouteViewer.h" + +#include "filesystem.h" +#include "settings.h" + +RouteViewer::RouteViewer(int argc, char* argv[]) +{ + +} + +bool RouteViewer::isReady() +{ + return true; +} + +int run() +{ + return 0; +} + +bool RouteViewer::init(int argc, char* argv[]) +{ + FileSystem& filesystem = FileSystem::getInstance(); + + + + return true; +} + +settings_t RouteViewer::loadSettings(const std::string& cfg_path) const +{ + settings_t settings; + return settings; +} diff --git a/viewer2/src/main.cpp b/viewer2/src/main.cpp new file mode 100644 index 000000000..7f2c4cebd --- /dev/null +++ b/viewer2/src/main.cpp @@ -0,0 +1,109 @@ +#include +#include + +#include +#include +#include + +int main(int argc, char* argv[]) +{ + try + { + vsg::CommandLine arguments(&argc, argv); + + auto options = vsg::Options::create(); + options->fileCache = vsg::getEnv("VSG_FILE_CACHE"); + options->paths = vsg::getEnvPaths("VSG_FILE_PATH"); + + options->add(vsgXchange::all::create()); + + arguments.read(options); + + auto windowTraits = vsg::WindowTraits::create(); + windowTraits->windowTitle = "Viewer2"; + windowTraits->width = 1600; + windowTraits->height = 900; + + if (arguments.errors()) + { + return arguments.writeErrorMessages(std::cerr); + } + + auto vsgScene = vsg::read_cast("models/lz.vsgt", options); + if (!vsgScene) + { + throw std::runtime_error("Failed to load VSG model"); + } + + auto viewer = vsg::Viewer::create(); + + auto window = vsg::Window::create(windowTraits); + if (!window) + { + throw std::runtime_error("Failed to create VSG window"); + } + + viewer->addWindow(window); + + vsg::ComputeBounds computeBounds; + vsgScene->accept(computeBounds); + vsg::dvec3 center = (computeBounds.bounds.min + computeBounds.bounds.max) * 0.5; + double radius = vsg::length(computeBounds.bounds.max - computeBounds.bounds.min) * 0.6; + double nearFarRatio = 0.0005; + + auto lookAt = vsg::LookAt::create(center + vsg::dvec3(0.0, -radius * 3.5, 0.0), center, vsg::dvec3(0.0, 0.0, 1.0)); + auto perspective = vsg::Perspective::create(30.0, static_cast(window->extent2D().width) / static_cast(window->extent2D().height), nearFarRatio * radius, radius * 4.5); + + auto camera = vsg::Camera::create(perspective, lookAt, vsg::ViewportState::create(window->extent2D())); + + viewer->addEventHandler(vsg::CloseHandler::create(viewer)); + viewer->addEventHandler(vsg::Trackball::create(camera)); + + auto commandGraph = vsg::createCommandGraphForView(window, camera, vsgScene); + viewer->assignRecordAndSubmitTaskAndPresentation({commandGraph}); + viewer->compile(); + + while (viewer->advanceToNextFrame()) + { + viewer->handleEvents(); + viewer->update(); + viewer->recordAndSubmit(); + viewer->present(); + } + } + catch (const vsg::Exception& exception) + { + for (int i = 0; i < argc; ++i) + { + std::cerr << argv[i] << ' '; + } + + std::cerr << "\n[Exception] - " << exception.message << " result = " << exception.result << std::endl; + + return 1; + } + catch (const std::exception& exception) + { + for (int i = 0; i < argc; ++i) + { + std::cerr << argv[i] << ' '; + } + + std::cerr << "\n[Exception] - " << exception.what() << std::endl; + + return 1; + } + catch (...) + { + for (int i = 0; i < argc; ++i) + { + std::cerr << argv[i] << ' '; + } + + std::cerr << "\n[Exception] - Unknown exception" << std::endl; + + return 1; + } + + return 0; +} diff --git a/viewer2/src/settings.cpp b/viewer2/src/settings.cpp new file mode 100644 index 000000000..cf3e2d482 --- /dev/null +++ b/viewer2/src/settings.cpp @@ -0,0 +1,55 @@ +#include "settings.h" + +settings_t::settings_t() + : vehicles_pos_update_interval(70) + , vehicles_state_update_interval(100) + , vehicle_controled_update_interval(70) + , client_delay(100) + , route_dir_name("") + , route_dir_full_path("") + , x(50) + , y(50) + , width(1280) + , height(720) + , fullscreen(false) + , vsync(true) + , fovy(30.0) + , fovy_min(2.0) + , fovy_max(120.0) + , zNear(1.0) + , zFar(1000.0) + , screen_number(0) + , name("viewer") + , window_decoration(true) + , double_buffer(true) + , samples(4) + , persistence(0.05) + , eye_height(3.0f) + , direction(1) + , notify_level("INFO") + , view_distance(1000.0f) + , ext_cam_init_dist(25.0f) + , ext_cam_init_height(3.0f) + , ext_cam_init_shift(0.0f) + , ext_cam_rot_coeff(1.0f) + , ext_cam_speed(5.0f) + , ext_cam_speed_coeff(10.0f) + , ext_cam_min_dist(5.0f) + , ext_cam_init_angle_H(0.0f) + , ext_cam_init_angle_V(0.0f) + , free_cam_init_pos(vsg::vec3(2.5f, 0.0f, 1.75f)) + , free_cam_rot_coeff(1.0f) + , free_cam_speed(5.0f) + , free_cam_speed_coeff(10.0f) + , free_cam_fovy_step(1.0) + , cabine_cam_rot_coeff(1.0f) + , cabine_cam_fovy_step(1.0) + , cabine_cam_speed(5.0f) + , cabine_cam_z_min(-1.0f) + , cabine_cam_z_max(0.5f) + , stat_cam_dist(8.0f) + , stat_cam_height(1.75f) + , stat_cam_shift(150.0f) + , interval(10) +{ +}