JOGL-glu.gluUnProject总是返回0.0 [英] JOGL - glu.gluUnProject always returning 0.0
问题描述
我目前正在尝试找出如何从JOGL获取世界坐标的方法-不管我在哪里单击,它现在仅返回x = 0.0,y = 0.0和z = 0.0.我在做什么错了?
I'm currently trying to work out how to get world coordinates from JOGL - at the moment it only returns x = 0.0, y= 0.0 and z = 0.0 no matter where I click. What am I doing wrong?
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;
}
:忘记提及我注意到glu.gluUnproject返回一个布尔值,因此我将其分配给一个名为test的布尔值,该布尔值返回false.
EDIT :: Forgot to mention that I noticed that glu.gluUnproject returns a boolean so I assigned it to a boolean called test which returns false.
EDIT2 ::我添加了另一个调试语句-System.out.println(modelview [0]);并且还返回0.0
EDIT2 :: I've added another debug statement - System.out.println(modelview[0]); and is also returning 0.0
谢谢您的帮助
詹姆斯
推荐答案
我终于找到了发生这种情况的原因,事实证明我在拉gl.glGetIntegerv(GL2.GL_VIEWPORT,viewport,0);在此之前的一种方法中.看来,如果执行此操作,则下一个调用它的方法将只返回一组零而不会返回任何结果!
I've finally found the reason why this was happening, it turns out that I was pulling gl.glGetIntegerv( GL2.GL_VIEWPORT, viewport, 0 ); in a method before this one. It seems that if you do this the next method to call it will be returned nothing but a set of zeros!
感谢您的建议
这篇关于JOGL-glu.gluUnProject总是返回0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!