处理 - ScreenToWorldCoordinate 函数?

Processing - ScreenToWorldCoordinate function?

我正在处理一个带有 Processing 的项目,该项目需要能够确定鼠标是否在圆圈内。因此,我需要获取圆的位置和鼠标的位置。但是,圆的位置已经使用translatescale等矩阵函数进行了修改。例如:

float circle_x;
float circle_y;
float circle_radius;

void setup() {
    circle_x = 10.0;
    circle_y = 17.0;
    circle_radius = 15.0;
}

void draw() {
    pushMatrix();

    /* ... arbitrary number of calls to modify the matrix ... */
    translate(THING, THING);
    scale(THING);
    translate(THING);
    /* ... */

    /* draw the circle */
    ellipse(circle_x, circle_y, circle_radius, circle_radius);

    /* now I want to detect whether or not my mouse is inside of the 
       circle.  In order to do that, I need to modify the coordinates
       of the mouse in the same fashion as circle_x and circle_y.  I'm
       hoping to do something like this: */
    float world_x = screenToWorld_X(mouseX);
    float world_y = screenToWorld_Y(mouseY);

    /* ... check if [world_x, world_y] is inside the circle ... */


    popMatrix();

}

在处理中有什么方法可以做到这一点吗?我正在查看文档,但似乎找不到任何功能。如果没有,我该如何实现我的目标?

谢谢。

查看 the reference 坐标 部分。

具体来说,您正在查找 modelX()modelY() 函数。或者您可以使用 screenX()screenY() 函数进行相反的操作,将您的世界坐标转换为屏幕坐标。