105 lines
2.8 KiB
C++
105 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "entities/SceneComponent.h"
|
|
|
|
#include <osg/Geometry>
|
|
#include <osg/LineWidth>
|
|
#include <osg/Vec4>
|
|
#include <deque>
|
|
|
|
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();
|
|
void DirtyGeometry();
|
|
void TrimOverflowPoints();
|
|
void RebuildRenderGeometry();
|
|
|
|
private:
|
|
osg::ref_ptr<osg::Geode> geode_;
|
|
osg::ref_ptr<osg::Geometry> geometry_;
|
|
osg::ref_ptr<osg::Vec3Array> vertices_;
|
|
osg::ref_ptr<osg::Vec3Array> renderVertices_;
|
|
osg::ref_ptr<osg::Vec4Array> colors_;
|
|
osg::ref_ptr<osg::DrawArrays> drawArrays_;
|
|
osg::ref_ptr<osg::LineWidth> lineWidthState_;
|
|
|
|
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<double> sampleTimes_;
|
|
};
|