3

The following is the code that I used to draw a circle by getting the touch position from the screen and calculating the radius from the origin to the touch point and passing to the renderer to draw the circle.

public boolean onTouchEvent(MotionEvent e) {
    float ex=0, ey=0;
    switch (e.getAction()) {
        case MotionEvent.ACTION_DOWN:
            ex = (e.getX()/(getWidth()/2))-1;
            ey = 1-(e.getY()/(getHeight()/2));
             dist = (float) (Math.sqrt(Math.pow(ex, 2)+Math.pow(ey, 2)));
    }
   mRenderer.radius = dist;
    requestRender();
    return true;
}

But I am getting the circle drawn at a radius lesser compared to the touch point I give for radius. i.e. the output doesn't coincide with the touch event. I want to know is there any Touch Scale Factor for arriving the touch posistion and how to employ it in the code ?

4

1 回答 1

1

那是因为您需要考虑投影和视图矩阵,正如 5agado 指出的那样。

为此,您可以使用 Ray Picking:它基本上包括从屏幕中的触摸点跟踪光线到您的场景。在您的情况下,您需要计算此射线与绘图表面的交点。

你可以看看这个那个

于 2013-04-30T07:54:43.150 回答