gluUnProject总是返回零 [英] gluUnProject always returns zero

查看:289
本文介绍了gluUnProject总是返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要gluUnProject屏幕坐标转换为世界坐标而现在我只是有工作。当我的应用程序运行时,它准确地告诉我,这是我知道的都存储在我的渲染线程屏幕上的坐标,然后泵出屏幕坐标。不幸的是屏幕坐标似乎的世界坐标和世界坐标保持在零至没有任何效果。

I need gluUnProject to convert screen coordinates to world coordinates and right now I just about have it working. When my app runs it accurately tells me the coordinates on screen which I know are stored in my renderer thread and then pumps out screen coordinates. Unfortunately the screen coordinates seem to have no effect of world coordinates and the world coordinates remain at zero.

下面是我的gluUnProject方法

Here is my gluUnProject method

public void vector3 (GL11 gl){

        int[] viewport = new int[4];
        float[] modelview = new float[16];
        float[] projection = new float[16];
        float winx, winy, winz;
        float[] newcoords = new float[4];

        gl.glGetIntegerv(GL11.GL_VIEWPORT, viewport, 0);
        ((GL11) gl).glGetFloatv(GL11.GL_MODELVIEW_MATRIX, modelview, 0);
        ((GL11) gl).glGetFloatv(GL11.GL_PROJECTION_MATRIX, projection, 0);

        winx = (float)setx;
        winy = (float)viewport[3] - sety;
        winz = 0;

        GLU.gluUnProject(setx, (float)viewport[3] - sety, 0, modelview, 0, projection, 0, viewport, 0, newcoords, 0);
        posx = (int)newcoords[0];
        posy = (int)newcoords[1];
        posz = (int)newcoords[2];



        Log.d(TAG, "x= " + String.valueOf(posx));
        Log.d(TAG, "y= " + String.valueOf(posy));
        Log.d(TAG, "z= " + String.valueOf(posz));
        }

现在我已经搜查,发现这个论坛帖子,他们来到这是使用,而不是getDoublev getFloatv做的,但getDoublev似乎没有结论由GL11支持

Now I've searched and found this forum post and they came to the conclusion that it was to do with using getFloatv instead of getDoublev, but getDoublev does not seem to be supported by GL11

The method glGetDoublev(int, float[], int) is undefined for the type GL11

和也

The method glGetDoublev(int, double[], int) is undefined for the type GL11

应该double和float的事情不管,如果让我怎么去用双打

should the double and float thing matter and if so how do I go about using doubles

感谢您

编辑:

有人告诉我,当太接近远近裁剪平面,所以我设置winz至-5附近时为0,远-10的gluUnproject失败。这对输出没有影响。

I was told that gluUnproject fails when too close to the near far clipping plane so I set winz to -5 when near is 0 and far is -10. This had no effect on the output.

我也记录了newcoords []数组的每一个部分,他们都返回的东西是NaN(非数字)会是这样的算法问题或一些上涨

I also logged each part of the newcoords[] array and they all return something that is NaN (not a number) could this be the problem or something higher up in the algorithm

推荐答案

我猜你是在模拟器上工作吗?它的OpenGL实现是相当越野车,和测试后,我发现它返回所有零以下电话:

I'm guessing you're working on the emulator? Its OpenGL implementation is rather buggy, and after testing I found that it returns all zeroes for the following calls:

gl11.glGetIntegerv(GL11.GL_VIEWPORT, viewport, 0);
gl11.glGetFloatv(GL11.GL_MODELVIEW_MATRIX, modelview, 0);
gl11.glGetFloatv(GL11.GL_PROJECTION_MATRIX, projection, 0);

gluUnProject ()函数需要计算将合并的模型视图投影矩阵的逆,并且由于这些值都是0,逆不存在,并且将包括NaN的。由此产生的 newcoords 向量,则也将NaN所有

The gluUnProject() function needs to calculate the inverse of the combined modelview-projection matrix, and since these are all zeroes, the inverse does not exist and will consist of NaNs. The resulting newcoords vector is therefor also all Nans.

尝试将其与适当的OpenGL实现的设备上,它应该工作。牢记仍然 newcoords分[3] 虽然; - )

Try it on a device with a proper OpenGL implementation, it should work. Keep in mind to still divide by newcoords[3] though ;-)

这篇关于gluUnProject总是返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆