Cameras - ZackWilde27/Z3dPy GitHub Wiki

z3dpy.Cam(vPos, *scW, *scH)

myCamera = z3dpy.Cam([0.0, 0.0, 0.0])

Camera rotation is determined by it's target and up vector. The rot parameter has no effect, unless you are using SetTargetFP().

Targets

If you want a first person camera, use CamSetTargetFP(camera) or CamSetTargetDir(camera, normal)

If you want a third person camera, use CamSetTargetLoc(camera, vector)

Up vector normally remains the same, but it can also be changed

# Third person camera

z3dpy.CamSetTargetLoc(myCamera, z3dpy.ThingGetPos(myCharacter))

# First person camera

# SetTargetVector() takes a normalized vector, in this case, forward along Z
z3dpy.CamSetTargetDir(myCamera, [0, 0, 1])

# For an easier first person camera, I've also added SetTargetFP()
# Uses camera's rotation values to determine target
z3dpy.CamSetTargetFP(myCamera)

You'll need to update the target per frame if the camera's going to move, or it'll continue looking at the same spot.

I'd recommend something like this:

while True:
    # Update Cam Position
    z3dpy.CamSetPos(myCamera, [1.0, 2.0, 3.0])

    # Update Cam Target
    z3dpy.CamSetTarget(myCamera, z3dpy.ThingGetPos(myCharacter))

    # SetInternalCam
    z3dpy.SetInternalCam(myCamera)

    # Raster
    for tri in z3dpy.Raster():
        #...

FOV / Aspect Ratio

FOV and aspect ratio are handled by constants. To change either of these, use FindHowVars(), then SetHowVars():

# by default, FOV is 90, and aspect ratio is 16:9

# For an FOV of 75
z3dpy.FindHowVars(75)

# For an FOV of 60 and aspect ratio of 21:9
z3dpy.FindHowVars(60, 9/21)

# For an FOV of 90 and aspect ratio of 4:3
z3dpy.FindHowVars(90, 3/4)

# If it's a strange resolution, you can just use raw height and width
z3dpy.FindHowVars(90, 1080/1920)

# This may take some time depending on your machine,
# so take note of the results and skip it
z3dpy.SetHowVars(0.7330638661047614, 1.3032245935576736)

Screen Size

By default, the screen size is 720p, but it can be changed like so

zp.screenSize = (1920, 1080)

It can also be changed through optional parameters when creating a camera, for backwards compatibility.

myCamera = zp.Cam([0, 0, 0], 1920, 1080)

Other

By default, the near clipping distance is 0.1, and the far clipping distance is 1500, but these can all be changed:

z3dpy.CamSetNCl(myCamera, 0.5)
z3dpy.CamSetFCl(myCamera, 1200)

print(z3dpy.CamGetNCl(myCamera))