OpenGL,gluUnProject给出-1。#IND

时间:2014-07-27 18:21:08

标签: c++ opengl

我几乎尝试了所有东西,从不同的论坛复制了很多代码,但没有任何作用。什么问题。 我有循环,我从矢量绘制对象。我想创建用户在3D空间中单击的对象。这是我尝试这样做的代码:

if(glfwGetKey( window, GLFW_KEY_F ) == GLFW_PRESS && glfwGetMouseButton(window,     GLFW_MOUSE_BUTTON_LEFT)==GLFW_PRESS && check==false) {
    double x, y;
    glfwGetCursorPos(window, &x, &y);
    double mvmatrix[16];
    double projmatrix[16];
    int viewport[4];
    double dX, dY, dZ, dClickY; // glUnProject uses doubles, but I'm using floats for these     3D vectors
    glGetIntegerv(GL_VIEWPORT, viewport);    
    glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
    glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);
    dClickY = double (1080 - y); // OpenGL renders with (0,0) on bottom, mouse reports with     (0,0) on top
    gluUnProject ((double) x, dClickY, 0.0, mvmatrix, projmatrix, viewport, &dX, &dY, &dZ);
    bricks.push_back(new Cube(0,0,0,1110));
    bricks[bricks.size()-1]->translate(dX, dY, dZ);
    check=true;
}

在该操作之后,dX,dY和dZ为-1。#IND。我做错了什么?

0 个答案:

没有答案