Returns the three-dimensional X, Y, Z position in model space.
1def setup(): 2 py5.size(500, 500, py5.P3D) 3 py5.no_fill() 4 5 6def draw(): 7 py5.background(0) 8 9 py5.push_matrix() 10 # start at the middle of the screen 11 py5.translate(py5.width//2, py5.height//2, -200) 12 # some random rotation to make things interesting 13 py5.rotate_y(1.0) # yrot) 14 py5.rotate_z(2.0) # zrot) 15 # rotate in X a little more each frame 16 py5.rotate_x(py5.frame_count/100.0) 17 # offset from_ center 18 py5.translate(0, 150, 0) 19 20 # draw a white box outline at (0, 0, 0) 21 py5.stroke(255) 22 py5.box(50) 23 24 # the box was drawn at (0, 0, 0), store that location 25 x = py5.model_x(0, 0, 0) 26 y = py5.model_y(0, 0, 0) 27 z = py5.model_z(0, 0, 0) 28 # clear out all the transformations 29 py5.pop_matrix() 30 31 # draw another box at the same (x, y, z) coordinate as the other 32 py5.push_matrix() 33 py5.translate(x, y, z) 34 py5.stroke(255, 0, 0) 35 py5.box(50) 36 py5.pop_matrix()
Returns the three-dimensional X, Y, Z position in model space. This returns the X value for a given coordinate based on the current set of transformations (scale, rotate, translate, etc.) The X value can be used to place an object in space relative to the location of the original point once the transformations are no longer in use.
In the example, the
model_x(), model_y(), and model_z() functions record the location of a box in space after being placed using a series of translate and rotate commands. After pop_matrix() is called, those transformations no longer apply, but the (x, y, z) coordinate returned by the model functions is used to place another box in the same location.
Underlying Processing method: modelX
model_x(x: float, y: float, z: float, /) -> float
x: float - 3D x-coordinate to be mapped
y: float - 3D y-coordinate to be mapped
z: float - 3D z-coordinate to be mapped
Updated on November 12, 2021 11:30:58am UTC