Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何检测我是否点击了GL10对象_Android_Opengl Es_Augmented Reality_Andar - Fatal编程技术网

Android 如何检测我是否点击了GL10对象

Android 如何检测我是否点击了GL10对象,android,opengl-es,augmented-reality,andar,Android,Opengl Es,Augmented Reality,Andar,我正在画一个简单的三角形,用AndAR显示在屏幕上。现在我想做一个简单的互动。我的意思是,当点击绘制的对象时,我想显示一个Toast。我已经实现了onTouchEvent,所以我可以得到点击屏幕位置的XY坐标。现在我需要检查这个点是否在我的2D三角形的区域内。我怎样才能得到三角形各点的坐标?三角形“粘贴”到标记上,并在识别标记时绘制,因此坐标会根据视角实时更改。这是最大的问题。有什么想法吗 public class Triangle extends ARObject implements Bas

我正在画一个简单的三角形,用AndAR显示在屏幕上。现在我想做一个简单的互动。我的意思是,当点击绘制的对象时,我想显示一个
Toast
。我已经实现了onTouchEvent,所以我可以得到点击屏幕位置的XY坐标。现在我需要检查这个点是否在我的2D三角形的区域内。我怎样才能得到三角形各点的坐标?三角形“粘贴”到标记上,并在识别标记时绘制,因此坐标会根据视角实时更改。这是最大的问题。有什么想法吗

public class Triangle extends ARObject implements BasicShape {

    private final FloatBuffer vertexBuffer;

    // number of coordinates per vertex in this array
    static final int COORDS_PER_VERTEX = 3;
    static float triangleCoords[] = {
            // in counterclockwise order:
            25.0f,  25.622008459f, 25.0f,// top
            -25.5f, -25.311004243f, 25.0f,// bottom left
            25.5f, -25.311004243f, 25.0f // bottom right
    };

    float color[] = { 1f, 0f, 0f, 0.0f };

    /**
     * Sets up the drawing object data for use in an OpenGL ES context.
     */
    public Triangle(String name, String patternName, double markerWidth, double[] markerCenter) {
        super(name, patternName, markerWidth, markerCenter);
        // initialize vertex byte buffer for shape coordinates
        ByteBuffer bb = ByteBuffer.allocateDirect(
                // (number of coordinate values * 4 bytes per float)
                triangleCoords.length * 4);
        // use the device hardware's native byte order
        bb.order(ByteOrder.nativeOrder());

        // create a floating point buffer from the ByteBuffer
        vertexBuffer = bb.asFloatBuffer();
        // add the coordinates to the FloatBuffer
        vertexBuffer.put(triangleCoords);
        // set the buffer to read the first coordinate
        vertexBuffer.position(0);
    }

    /**
     * Encapsulates the OpenGL ES instructions for drawing this shape.
     *
     * @param gl - The OpenGL ES context in which to draw this shape.
     */
    @Override
    public void draw(GL10 gl) {
        super.draw(gl);
        // Since this shape uses vertex arrays, enable them
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

        // draw the shape
        gl.glColor4f(       // set color:
                color[0], color[1],
                color[2], color[3]);
        gl.glVertexPointer( // point to vertex data:
                COORDS_PER_VERTEX,
                GL10.GL_FLOAT, 0, vertexBuffer);
        gl.glDrawArrays(    // draw shape:
                GL10.GL_TRIANGLES, 0,
                triangleCoords.length / COORDS_PER_VERTEX);
        gl.glTranslatef(0.0f, 0.0f, 12.5f);

        // Disable vertex array drawing to avoid
        // conflicts with shapes that don't use it
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    }

    @Override
    public void init(GL10 gl10) {

    }
}