[QGLViewer]3D场景鼠标点击位置

重载鼠标事件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void AxMapControl::mousePressEvent(QMouseEvent* e)
{
    switch(currentTool)
    {
        case AX_DRAW_DIRECTION:
            {
                if (e->button() == Qt::LeftButton)
                {
                    QPoint screenPt=e->pos();
                    qglviewer::Vec orig1, dir1;
                    camera()->convertClickToLine(screenPt, orig1, dir1);
                    double valueZ=0;
                    double a = ( valueZ- orig1.z) / dir1.z;
                    Pnt.z = valueZ;
                    Pnt.x = orig1.x + dir1.x * a;
                    Pnt.y = orig1.y + dir1.y * a;
                    //QMessageBox::information(this, "PickPoint",   QString::number(Pnt.x) + "," + QString::number(Pnt.y));
                }
                break;
            }
             
    }
    QGLViewer::mousePressEvent(e);
}

 重载绘制方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
void AxMapControl::draw()
{
        if (pimpl->points.size()>0)
        {
            QMutexLocker locker(&pimpl->mutex_);
            glColor3f(255/255.0, 69/255.0, 0.0);
            draw_3d_points(pimpl->points);
        }
        if (pimpl->pointCloudOneFrame.size()>0)
        {
            QMutexLocker locker(&pimpl->mutex_);
            glColor3f(255/255.0, 69/255.0, 0.0);
            for (vector<Point3ds>::const_iterator it = pimpl->pointCloudOneFrame.begin();it != pimpl->pointCloudOneFrame.end(); ++it)
            {
                const Point3ds& p = *it;
                if (p.size()>0)
                {
                    draw_3d_points(p);
                }
                 
            }
        }
        if (!glImg.isNull())
        {
            glNormal3f(0.0, 0.0, 1.0);
            glBegin(GL_QUADS);
            glTexCoord2f(0.0,   1.0-v_max);
            glVertex2f(-u_max*ratio,-v_max);
            glTexCoord2f(0.0,   1.0);      
            glVertex2f(-u_max*ratio, v_max);
            glTexCoord2f(u_max, 1.0);      
            glVertex2f( u_max*ratio, v_max);
            glTexCoord2f(u_max, 1.0-v_max);
            glVertex2f( u_max*ratio,-v_max);
            glEnd();
        }
 
        if (currentTool==AX_DRAW_DIRECTION)
        {
            glBegin(GL_LINES);
            glColor3f(255/255.0, 0/255.0, 0.0);
            glVertex3fv(currentPose);
            glVertex3fv(Pnt);
            glEnd();
        }

 效果:

posted @   太一吾鱼水  阅读(570)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程
历史上的今天:
2016-05-10 Hausdorff distance
点击右上角即可分享
微信分享提示