-1

我不知道为什么当我点击任何东西时我总是得到 0 次点击。我已经让主机器人工作了,它对键盘命令的响应很好,但由于某种原因,我似乎无法让它注册一个命中。
一直在尝试遵循本教程:Lighthouse Tutorial
Full Code Here: My Git Repo

int handlePicking(int x, int y)
{
    int hits;

    GLint viewport[4];

    glSelectBuffer(BUFSIZE, selectBuf);
    glRenderMode(GL_SELECT);

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

    glGetIntegerv(GL_VIEWPORT, viewport);
    gluPickMatrix(x, viewport[3] - y, 5, 5, viewport);
    glMatrixMode(GL_MODELVIEW);
    glInitNames();

    // restoring the original projection matrix
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glFlush();

    // returning to normal rendering mode
    hits = glRenderMode(GL_RENDER);

    std::cout << hits << std::endl;

    return -1;
}

void robot()
{
    glInitNames();

    glPushName(ROBOT_HEAD);
    robotHead();
    glPopName();

    glPushName(ROBOT_EYES);
    robotLeftEye();
    robotRightEye();
    glPopName();

    glPushName(ROBOT_BODY);
    robotBody();
    glPopName();

    glPushName(ROBOT_ARMS);
    robotLeftArm();
    robotRightArm();
    glPopName();

    glPushName(ROBOT_LEGS);
    robotLeftLeg();
    robotRightLeg();
    glPopName();
}
4

1 回答 1

0

看起来你没有设置你的视图矩阵(glortho,gluperspective)或渲染你的机器人来挑选。看看以下哪些有效。我相信它会有所帮助,就像它是课程的一部分一样。

GLvoid CGame::Selection(GLvoid)
{
    GLuint  buffer[512];
    GLint   hits;
    GLint   viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);
    glSelectBuffer(512, buffer);
    (GLvoid) glRenderMode(GL_SELECT);
    glInitNames();
    glPushName(0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix((GLdouble) mouse_x, (GLdouble) (viewport[3]-mouse_y-4), 8.0f, 8.0f, viewport);
    gluPerspective(70.0f,(GLfloat)width/(GLfloat)height,0.001f,100.0f);
    glMatrixMode(GL_MODELVIEW);

    renderTargetAnswers(); //YOUR ROBOT() SHOULD GO HERE
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    hits=glRenderMode(GL_RENDER);
    if (hits>0)
    {
        score+=1;
        int choose = buffer[3];
        int depth = buffer[1];
        for (int loop = 1; loop<hits;loop++)
        {
            if (buffer[loop*4+1] < GLuint(depth))
            {
                choose = buffer[loop*4+3];
                depth = buffer[loop*4+1];
            }       
        }
        if (!targetanswers[choose].hit)
        {
            targetanswers[choose].hit=GL_TRUE;
        }
    }
}
于 2014-11-04T05:29:17.037 回答