Skip to content

VideojogosLusofona/PyXYZ-Samples

Repository files navigation

PyXYZ

PyXYZ (pronounced pyxies) is a a simple 3D wireframe engine for education, entirely programmed in Python, using only PyGame, NumPy and NumPy-Quaternion.

It is an object-oriented engine, with the main design focus on simplicity and ease of learning and extension, and has very little functionality out-of-the-box: it allows for the programmer to visualize a 3D scene using a virtual camera.

alt text

This repository has some some sample applications for the engine.

The engine can be retrieved from https://github.com/VideojogosLusofona/PyXYZ, and the documentation can be read on https://videojogoslusofona.github.io/PyXYZ/.

Sample applications

All the sample applications implement an application loop. A window is open, the content is displayed there, and the user can quit by pressing the ESC quit or closing the window.

To run the samples, the "pyxyz" directory needs to be copied from the engine repository to the directory where the samples reside. The structure should become similar to this:

+ Root
  + pyxyz
  | | camera.py
  | | ....
  | | vector3.py
  | sample_cubefall.py
  | ...
  | sample_terrain.py

All the dependencies (PyGame, NumPy, NumPy-Quaternion) should also be installed (see https://github.com/VideojogosLusofona/PyXYZ for instructions).

Then, the Python interpreter can be invoked to run any sample, for example:

python3 sample_sphere.py

Note that the Python interpreter can have different command names in different OS's (py, python, python3).

Sphere (sample_sphere.py)

alt text

The simplest sample, it just creates a red sphere on the center of the viewport and rotates it slowly.

Hierachy (sample_hierarchy.py)

alt text

This application demonstrates the use of hierarchies. Hierarchies can be created by adding objects as children of other objects. The PRS of child objects will be considered to be in local space (the space of the parent).

Cube fall (sample_cubefall.py)

alt text

In this application, cubes are spawned on top of the screen and fall down with gravity. This demonstrates one way of creating/destroing objects through the life cycle of the application.

It also shows the use of creating classes derived from Object3d (use of hierarchy-based extension instead of component-based)

Terrain (sample_terrain.py)

alt text

This application generates a terrain based on a 2-octave Perlin noise, colors the generated polygons based on height and slope, and rotates the terrain in front of the camera.

This makes use of a helper 2d perlin generator that's part of PyXYZ.

Missile Game (sample_game.py)

alt text

This is a sort of incomplete game: the player can shoot some missiles using the mouse, and it demonstrates user input and a more complex application loop. It also shows functionality like creating a mesh from different parts, converting a mouse position into a ray, sphere/sphere collision detection, target tracking and a rudimentary screen flash effect. The game is not complete, since it doesn’t have win/lose condition

Licenses

All code in this repo is made available through the MIT license.

About

Samples for the PyXYZ engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages