Trains 0.3.2 - ZackWilde27/Z3dPy GitHub Wiki
Trains are Z3dPy's terrain system, an easy way to replace the flat floor of HandlePhysics()
Say we had this basic scene involving physics:
z3dpy.AddThing(myCharacter)
z3dpy.ThingSetupPhysics(myCharacter)
while True:
z3dpy.HandlePhysicsFloor([myCharacter], 2)
for tri in z3dpy.Raster():
z3dpy.PgDrawTriFL(tri, screen, pygame)
At the beginning of the script, a train needs to be created and baked.
# Making a 15x15 plane
myTrain = z3dpy.Train(15, 15)
# Setting height at certain locations
myTrain[5][2] = 32.6
myTrain[10][8] = -54.2
# Baking will blur points into smooth hills
# BakeTrain(train, *iPasses, *FStrength, *FAmplitude)
z3dpy.BakeTrain(myTrain)
-
Passes
How many times to repeat the blur (1 time by default)
-
Strength
Strength of the blur (1.0 by default)
-
Amplitude
Used to amplify the final output (1.0 by default)
Now that the train is created, HandlePhysicsFloor() can be replaced with HandlePhysicsTrain()
while True:
z3dpy.HandlePhysicsTrain([myCharacter], myTrain)
for tri in z3dpy.Raster():
z3dpy.PgDrawTriFL(tri, screen, pygame)
It's an invisible floor, meant to be matched to the environment. For debugging, it can be drawn with DebugRaster()
for tri in z3dpy.DebugRaster(myTrain):
if z3dpy.TriGetId(tri) == -1:
z3dpy.PgDrawTriOutl(tri, [1, 0, 0], screen, pygame)
else:
z3dpy.PgDrawTriFL(tri, screen, pygame)