English 中文(简体)
JOGL——glu.glu Un Project总会返回 iii
原标题:JOGL - glu.gluUnProject always returning 0.0

I m目前试图研究如何从JOGL那里获得世界坐标,当时只有返回x =0.0, y=0.0和z=0.0,而我没有点。 我做了什么错误?

 public double[] getMousePosition(int x, int y){

    int viewport[] = new int[4];
    double modelview[] = new double[16];
    double projection[] = new double[16];
    float winX, winY, winZ;
    float posX, posY, posZ;
    double wcoord[] = new double[4];

    gl.glGetDoublev( GL2.GL_MODELVIEW_MATRIX, modelview, 0 );
    gl.glGetDoublev( GL2.GL_PROJECTION_MATRIX, projection, 0 );
    gl.glGetIntegerv( GL2.GL_VIEWPORT, viewport, 0 );

    winX = (float)x;
    winY = (float)viewport[3] - (float)y;

    float[] depth = new float[1];
    // gl.glReadPixels(winX, winY, 1, 1, gl.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, depth);

    boolean test =  glu.gluUnProject( winX, winY, 0.0, modelview, 0, projection, 0, viewport, 0, wcoord, 0);

    System.out.println("x: " + wcoord[0] +"y: "+wcoord[1]+" worked? "+test);
    System.out.println(modelview[0]);
    return wcoord;
}

EDIT: 不用说,我注意到了这一glu。 glu 无项目回报的是一种风.,因此,我给它留下了一个叫作假的蓝色的测试。

EDIT2 - I ve 添加了另一条解答词——系统外面,印数(湿度为0.0);

感谢您的帮助

James

最佳回答

最后,我找到了发生这种情况的原因,但我却指出,我拿着眼光照亮GetIntegerv(GL2.GL_VIEWPORT,查看port, 0 );用这个方法。 看来,如果你这样做的话,那么,除了一套零点之外,还不会再回来。

感谢您的建议

问题回答

可能的原因之一:你同时对模型调查矩阵和预测矩阵进行回馈?

glu Un Project(S)正在与我方合作,我做的是:

1) Only when the view-port size and/or the "camera" are updated: grab the viewport and the projection-matrix.
I.E. You should be after a gl.glMatrixMode(GL.GL_PROJECTION)

2) Each "frame": grab the model-view matrix.
I.E. You should be after a gl.glMatrixMode(GL.GL_MODELVIEW)

3) 然后是:将3个阵列转至“不项目”。

glu Unproject(glu Unproject)将永远退还TRIUE(0,0)和窗口坐标(0,0),如果你试图找到的3D点远远落后于最近的剪辑(通常也落后于卡马拉立场)。 在对矩阵进行查询和浏览信息后,你可能不得不人工进行计算。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签