Translate the coordinate system.
The transform methods are used to position objects in your application. You can translate along a particular axis (x,y,z) or along an arbitrary axis. See the examples section below for usage.
Be sure to wrap translate
calls with pushMatrix()
and popMatrix()
to restore
the environment to its original state. Otherwise, all subsequent rendering calls
will be translated as well.
See the coordinate system tutorial for more information.
syntax
translateX(tx) translateY(ty) translateZ(tz) translate(dist, dir)
parameters
tx | amount of translation in the x-axis |
ty | amount of translation in the y-axis |
tz | amount of translation in the z-axis |
dist | amount of translation in arbitrary direction |
dir | direction of translation |
examples
cube translated along the x-axis
def display(): lighting(False) color(white) cube(3.0) translateX(4.0) color(green) cube(3.0)
cube translated along the y-axis
def display(): lighting(False) color(white) cube(3.0) translateY(4.0) color(green) cube(3.0)
cube translated along the z-axis
def display(): lighting(False) color(white) cube(3.0) translateZ(4.0) color(green) cube(3.0)
drawing multiple cubes at random positions
The following code can be simplified by using batch_mode rendering. This example is for illustration purposes only.
def init(): num_cubes = 20 Global.positions = list(random_vertex_generator(num_cubes, -10.0, 10.0)) def display(): lighting(False) for pos in Global.positions: pushMatrix() translate(pos) cube(3.0) popMatrix()