-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 に答える