0

そのため、OpenGL 2 でオブジェクト ピッキングを機能させようとしています。OpenGK 1 では、かなり単純な glpixelColor を使用しました。

光線の始点と終点を示す次のコードがありますか??

Log.i("My POSITION", "x:" + mRenderer.eye.x + " y:" + mRenderer.eye.y + " z:" + mRenderer.eye.z);

float xyzw[] = unproject(x, mRenderer.screenHeight - y, -1.0f);
Log.i("Start of ray", "x:" + xyzw[0] + " y:" + xyzw[1] + " z:" + xyzw[2]);

xyzw = unproject(x, mRenderer.screenHeight - y, 1.0f);
Log.i("End of Ray", "x:" + xyzw[0] + " y:" + xyzw[1] + " z:" + xyzw[2]);

私は次の機能を使用します

public float[] unproject(float rx, float ry, float rz) {
            float[] xyzw = {0, 0, 0, 0};
            int[] viewport = { 0, 0, mRenderer.screenWidth, mRenderer.screenHeight};
            android.opengl.GLU.gluUnProject(rx, ry, rz, mRenderer.mViewMatrix, 0, mRenderer.mProjectionMatrix, 0, viewport, 0, xyzw, 0);
            xyzw[0] /= xyzw[3];
            xyzw[1] /= xyzw[3];
            xyzw[2] /= xyzw[3];
            xyzw[3] = 1;
            return xyzw;
        }

次の出力が得られます

私の位置: x:-1.857801 y:0.0 z:-8.655011 04-21

光線の開始: x:-1.8198236 y:-0.005848203 z:-8.688532 04-21

レイの終わり: x:758.43915 y:-117.07846 z:-679.7136

質問 ある位置で立方体をタップした場合、どうすれば解決できますか? 立方体が 1,1,1 にあるとします。

4

1 に答える 1