zoukankan      html  css  js  c++  java
  • opengl 鼠标拾取

    代码
    void GLWidget::HitGet(QPoint pos)
    {
    GLuint NameBuffer[
    27];
    GLint viewport[
    4];
    GLint hits;

    glGetIntegerv (GL_VIEWPORT, viewport);
    glSelectBuffer(
    27,NameBuffer);
    glRenderMode(GL_SELECT);

    glInitNames();
    glPushName(
    0);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    gluPickMatrix((GLdouble)pos.x(),(GLdouble)(viewport[
    3]-pos.y()),5,5,viewport);
    glOrtho(
    0, 600, 0, 600, 4.0, 15.0);
    qDebug()
    <<"viewport"<<viewport[0]<<" "<<pos<<(GLdouble)pos.x()<<viewport[3]-(GLdouble)(pos.y());
    glMatrixMode(GL_MODELVIEW);
    for(int i=0;i<10;i++){
    glLoadName(i);
    Data::nodes[i].Draw();
    }


    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    hits
    =glRenderMode(GL_RENDER);
    qDebug()
    <<hits;
    if(hits>0)
    {
    qDebug()
    <<NameBuffer[0]<<NameBuffer[1]<<NameBuffer[3];
    }
    }
    代码

    void GLWidget::MousePick(QPoint pos)
    {
    #ifndef SIZE
    #define SIZE 30
    GLuint NameBuffer[SIZE];
    //名称缓存
    GLint viewport[4]; //视点
    GLint hits;

    //设置选择模式参数
    glSelectBuffer(SIZE,NameBuffer);
    glGetIntegerv (GL_VIEWPORT, viewport);
    glMatrixMode(GL_PROJECTION);
    glRenderMode(GL_SELECT);

    //保存矩阵
    glPushMatrix();
    glLoadIdentity();

    //拾取对象
    gluPickMatrix((GLdouble)pos.x(),(GLdouble)(viewport[3]-pos.y()),5,5,viewport);
    glOrtho(
    0, 600, 0, 600, 4.0, 15.0);
    glMatrixMode(GL_MODELVIEW);
    glInitNames();
    glPushName(
    0);
    Paint(GL_SELECT);
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();
    hits
    =glRenderMode(GL_RENDER);
    qDebug()
    <<hits;
    if(hits>0)
    {
    qDebug()
    <<NameBuffer[0]<<NameBuffer[1]<<NameBuffer[2]<<NameBuffer[3]<<NameBuffer[4]<<NameBuffer[5];
    }

    #endif
    }
  • 相关阅读:
    对两个有序数组进行合并
    连续子数组的最大和问题
    设计模式的学习
    Android基础总结(12)——XML和JSON解析
    Android基础总结(8)——服务
    x64 Assembly Tutorial 1 : Getting into x64 ASM from C++
    C# IL 指令集
    Unity3D教程宝典之地形
    Unity3D 动态改变地形 Unity3D Dynamic Change Terrain
    C#中String.format用法详解
  • 原文地址:https://www.cnblogs.com/dabaopku/p/1698804.html
Copyright © 2011-2022 走看看