Classes OOP - ZackWilde27/Z3dPy GitHub Wiki

OOP Objects

Docs for function version can be found here

z3dpy.Vector(x, y, z)

Standard 3 point vector, could also be used as RGB

Components: x, y, z

# Vector(x, y, z)
myVector = z3dpy.Vector(22, 34, 58)

print(myVector.y)
# result: 34

z3dpy.Vector4(x, y, z, w)

Vector with a W component for matrix math.

Components: x, y, z, w

# Vector4(x, y, z, w)
myVector4 = z3dpy.Vector4(0, 1, 2, 3)

print(myVector4.z + myVector4.w)
# result 5

z3dpy.Triangle(point1, point2, point3)

A triangle is made up of 3 vectors

Components: p1, p2, p3, normal, lighting, colour, wpos, id

# Triangle(v1, v2, v3)
myTriangle = z3dpy.Triangle(myVector, myOtherVector, myThirdVector)

print(myTriangle.normal.x)

z3dpy.Mesh(triangles, x, y, z)

A mesh is composed of a list of triangles, and has it's own x, y, and z

Components: tris, pos, rot, colour, id

# Mesh(triangleList, x, y, z)
# Ain't nobody got time to write it manually, just use the LoadMesh() function
# LoadMesh(filename, x, y, z)
myMesh = z3dpy.LoadMesh("engine/mesh/plane.obj", 0, 0, 0)
myMesh.rot.x += 5
myMesh.colour = z3dpy.Vector(255, 0, 0)

z3dpy.Thing(meshes, x, y, z)

A Thing is what you would typically refer to as an object, it can have multiple meshes and supports collisions. For a single mesh, simply put it in a list with [myMesh]

Since meshes have their own pos and rot, think of it like a global and relative transform.

Components: meshes, pos, rot, id, hitbox, physics

# Thing(meshList, x, y, z)
myThing = z3dpy.Thing([myMesh, myOtherMesh], 3, 8, 7)
myThing.rot.y = 90
print(myThing.pos.x)
# result: 3

z3dpy.Hitbox(type, id, radius, height)

A hitbox, given to Things for collisions.

Components: bbR, bbH, collisionType, collisionId, hitbox

bbR is hitbox radius, bbH is hitbox height.

Only things with the same collisionId will check for collisions

For collisionType: 0 = sphere, 1 = cylinder, 2 = cube.

hitbox is the visual mesh that is drawn to the screen with DebugRasterThings()

Use SetCollisionParams() to change the visual hitbox to match the new settings.

myCharacter.hitbox = z3dpy.Hitbox(2, 0, 1, 1)

myCharacter.hitbox.SetCollisionParams(1, 2, 5, 5)

z3dpy.PhysicsBody(mass, friction)

Physics body, given to Things for simulating physics

Components: velocity, acceleration, mass, friction

Velocity is how far a Thing moves per frame

Acceleration is how much velocity increases each frame

Mass is how much force an object exerts when colliding

Friction is how quickly velocity falls off

myCharacter.physics = z3dpy.PhysicsBody(5, 0.2)

myCharacter.physics.velocity.y = -12

z3dpy.Camera(x, y, z, width, height, screenWidth, screenHeight, fov, nearClip, farClip)

Camera object for rendering triangles.

Components: x, y, z, roll, pitch, yaw, fov, scrH, scrW, scrHh, scrWh, nc, fc, target, forward, up, theta, tan, a

switch = True
# Camera(x, y, z, screenWidth, screenHeight)
myCamera = z3dpy.Camera(0, 0, 0, 1280, 720)
myOtherCamera = z3dpy.Camera(15, 5, 0, 1280, 720)

myCamera.target = myOtherCamera.pos
myOtherCamera.target = myCamera.pos

if switch:
    cameraToUse = myCamera
else:
    cameraToUse = myOtherCamera