1

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) {

    }
}
4

0 に答える 0