2011/08/04

再びgluUnProjectについて

gluUnProjectに関して間違いがあった.


gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, mvmatrix, 0);
gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projmatrix, 0);
が上手く動いていない模様.
gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, mvmatrix, 0);
gl.glGetFloatv(GL2.GL_PROJECTION_MATRIX, projmatrix, 0);

などと,glGetFloatv()に変更して,glUnProjectを使うと,window座標をworld座標へ変換できる.


つまり

    int viewport[] = new int[4];
    float projmatrix[] = new float[16];
    float mvmatrix[] = new float[16];
    gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0);
    gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, mvmatrix, 0);
    gl.glGetFloatv(GL2.GL_PROJECTION_MATRIX, projmatrix, 0);

    float[] wcoord=new float[4];
    float winx = wx;
    float winy = viewport[3] -wy -1; //note viewport[3] is height of window in pixels
    float winz = wz;

    boolean isGet=glu.gluUnProject(winx,winy,winz,
                                   mvmatrix,0,
                                   projmatrix,0,
                                   viewport,0,
                                   wcoord,0);

ということ.

0 件のコメント: