如何在处理中检索 2D/3D 形状的顶点坐标?

How to retrieve vertex coordinates of a 2D/3D shape in processing?

我在 Processing 中有一个 3D 旋转的形状 space。我想在物理 2D space 中打印出形状的当前坐标。这是代码:

x = 0
y = 0
z = 0
sqr = 0

def setup():
    size(600, 600, P3D)
    frameRate(24)
    lights()


def draw():
    background('#5099ff')
    global x, y, z, sqr
    translate(300, 300)

    pushMatrix()
    rotateY(mouseX/(20*PI))
    rotateX(-mouseY/(20*PI))


    box(100)
    popMatrix()

    translate(0, -200)
    rectMode(CENTER)
    noFill()
    sqr += .1
    rotateY(sqr)
    rotateZ(sqr)
    rect(0, 0, 100, 100)

在任何瞬间,虽然正方形有自己的 3D 坐标,我可以计算,但我如何获得 canvas 上的物理像素位置?

听起来您正在寻找 screenX()screenY() 函数?

来自the reference

Takes a three-dimensional X, Y, Z position and returns the X value for where it will appear on a (two-dimensional) screen.

要换一种方式,将屏幕坐标转换为 3D space,您可以使用 modelX()modelY()modelZ() 函数。

可以在 the reference 中找到更多信息。