OSGEarth绘制Geometry:画线(一)

本文介绍如何在OSGEarth中实现鼠标交互绘制线条功能。包括两点间绘制黄色实线以及最近点击点与鼠标移动点间的红色虚线。代码分别在drawline.h和drawline.cpp中实现,强调了无需将功能作为成员,可按需新建实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在OSGEarth中绘制线,首先考虑osgEarth::Annotation::FeatureNode
功能描述如下:
1. 鼠标两次点击的点之间连线,为黄色的实线;
2. 最近一次点击的点和鼠标move到的点之间连线,为红色的虚线。
代码如下:drawline.h

class DrawLine : public HandleAdapter
{
public:
    DrawLine(GraphicsView* view);
    ~DrawLine();

protected:
    // 只需要经纬度
    virtual void slotPicked(osg::Vec3d pos);
    virtual void slotMoveing(osg::Vec3d pos);
    virtual void slotRightHandle();

private:
    // 实线的style,Node
    osgEarth::Symbology::Style m_lineStyle;
    osgEarth::Features::Feature* m_pFeature;
    osgEarth::Annotation::FeatureNode* m_pFeatureNode;

    // 虚线的style,Node
    osgEarth::Symbology::Style m_stippleLineStyle;
    osgEarth::Features::Feature* m_pStippleFeature;
    osgEarth::Annotation::FeatureNode* m_pStippleFeatureNode;

    std::vector<osg::Vec3d> m_vecPoint;
};

功能实现如下:drawline.cpp

DrawLine::DrawLine(GraphicsView* view)
: HandleAdapter(view)
{
    m_pFeature = NULL;
    m_pFeatu
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值