#pragma once #include "entities/SceneComponent.h" #include #include #include #include #include class TrajectoryTraceComponent : public SceneComponent { Q_OBJECT public: explicit TrajectoryTraceComponent(SceneComponent* parent = nullptr); ~TrajectoryTraceComponent(); static std::string GetTypeName(); std::string GetSelfTypeName() const override { return TrajectoryTraceComponent::GetTypeName(); } bool SetAttribute(const char* name, const char* value) override; bool SaveAttribute(tinyxml2::XMLElement* element) override; void Begin() override; void Update(double dt) override; void AddToRender() override; void SetColor(const osg::Vec4& color); const osg::Vec4& GetColor() const; void SetLineWidth(float width); float GetLineWidth() const; void SetSampleInterval(double interval); double GetSampleInterval() const; void SetMinMoveDistance(double distance); double GetMinMoveDistance() const; void SetMaxPoints(int maxPoints); int GetMaxPoints() const; void SetTailDuration(double duration); double GetTailDuration() const; void SetTraceVisible(bool visible); bool IsTraceVisible() const; void SetDashed(bool dashed); bool IsDashed() const; void SetDashLength(double length); double GetDashLength() const; void SetGapLength(double length); double GetGapLength() const; void SetDashScrollSpeed(double speed); double GetDashScrollSpeed() const; void ClearTrace(); private: void InitializeGeometry(); void EnsureAttachedToScene(); bool AppendPoint(const osg::Vec3d& geoPoint); bool UpdateTailPoint(const osg::Vec3d& geoPoint); bool ConvertGeoPointToWorld(const osg::Vec3d& geoPoint, osg::Vec3d& worldPoint) const; void AttachTraceToScene(); void TrimExpiredPoints(); void UpdateStyle(); private: osg::ref_ptr geode_; osg::ref_ptr geometry_; osg::ref_ptr vertices_; osg::ref_ptr colors_; osg::ref_ptr drawArrays_; osg::ref_ptr lineWidthState_; osg::ref_ptr lineStippleState_; osg::Vec4 color_{1.0f, 0.8f, 0.1f, 1.0f}; float lineWidth_{2.0f}; double sampleInterval_{0.1}; double minMoveDistance_{1.0}; int maxPoints_{5000}; double tailDuration_{30.0}; bool traceVisible_{true}; bool dashed_{false}; double dashLength_{150.0}; double gapLength_{100.0}; double dashScrollSpeed_{0.0}; double sampleAccum_{0.0}; double elapsedTime_{0.0}; osg::Vec3d lastSamplePos_{0.0, 0.0, 0.0}; bool hasLastSample_{false}; bool attachedToScene_{false}; std::deque sampleTimes_; };