Cameras 0.4 - ZackWilde27/Z3dPy GitHub Wiki
z3dpy.Cam(vPos, *scW, *scH)
myCamera = z3dpy.Cam([0.0, 0.0, 0.0])
Properties
-
position
-
rotation
-
nearClip
-
farClip
-
targetThe world location that the camera is looking at
-
up
-
user
Functions
-
GetTargetDir() Returns the direction the camera is facing.
-
SetTargetDir(vector) Sets the direction the camera is facing.
-
SetTargetFP() Sets the target based on rotation, for an easy First-Person camera.
-
GetRightVector() Returns the direction to the right of the camera, based on where it's looking.
-
Chase(vLocation, fSpeed) The camera will take an fSpeed-sized step towards the given location. Returns whether or not it's at the target location.
Targets
Camera rotation is determined by it's target and up vector. The rotation property has no effect, unless you are using SetTargetFP().
If you want a first person camera, use SetTargetFP() or SetTargetDir(normal)
If you want a third person camera, set yourCamera.target directly.
The up vector usually remains the same, but it can also be changed
# Third person camera
myCamera.target = myCharacter.position
# First person camera
# SetTargetDir() takes a normalized vector, in this case, forward along Z
myCamera.SetTargetDir([0, 0, 1])
# For an easier first person camera, I've also added SetTargetFP()
# Uses camera's rotation values to determine target
myCamera.SetTargetFP()
# Should always be up on the Y axis, unless you're doing gravity stuff
myCamera.up = [0, 1, 0]
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
myCamera.position = [1.0, 2.0, 3.0]
# Update Cam Target
myCamera.target = myCharacter.position
# SetInternalCam
z3dpy.SetInternalCam(myCamera)
# Render
for tri in z3dpy.Render():
#...
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
screenSize determines the clipping borders and size of the projected triangles. It should match the screen it's drawing to, but making it smaller can produce a split-screen.
By default it's set to 720p, but can be changed in two ways.
# It can be set when creating a camera
myCamera = zp.Cam([0, 0, 0], 1920, 1080)
# but if you need direct access to it:
zp.screenSize = (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:
myCamera.nearClip = 0.5
myCamera.farClip = 1200
print(myCamera.nearClip)