peng3d.world
- World, Terrain and Actor management¶
-
class
peng3d.world.
World
(peng)[source]¶ World containing terrain, actors, cameras and views.
See the docs about
Camera()
,WorldView()
,Actor()
for more information about each class.This class does not draw anything, see
StaticWorld()
for drawing simple terrain.-
addActor
(actor)[source]¶ Adds the given actor to the internal registry.
Note that this actors
uuid
attribute must be unique, else it will override any actors previously registered with its UUID.
-
addCamera
(camera)[source]¶ Add the camera to the internal registry.
Each camera name must be unique, or else only the most recent version will be used. This behavior should not be relied on because some objects may cache objects.
Additionally, only instances of
Camera()
may be used, everything else raises aTypeError
.
-
addView
(view)[source]¶ Adds the supplied
WorldView()
object to the internal registry.The same restrictions as for cameras apply, e.g. no duplicate names.
Additionally, only instances of
WorldView()
may be used, everything else raises aTypeError
.
-
-
class
peng3d.world.
StaticWorld
(peng, quads, colors)[source]¶ Subclass of
StaticWorld()
, allows for semi-static terrain to be rendered.This class is not suitable for highly complex or user-modifiable terrain.
quads
is a list of 3d vertices, e.g. a single quad may be[-1,-1,-1, 1,-1,-1, 1,-1,1, -1,-1,1]
, which represents a rectangle of size 2x2 centered around 0,0. It should also be noted that all quads have to be in a single list.colors
is a list of RGB Colors in a similar format toquads
but with colors instead. Note that there must be a color for every vertex in the vertex list. Every color is an integer between 0 and 255 using the internal pyglet schemec3B/static
.You can modify the terrain via the
terrain
attribute, note that it is a pyglet vertex list, and not a python list.
-
class
peng3d.world.
WorldView
(world, name, cam)[source]¶ Object representing a view on the world.
A
WorldView()
object references a camera and has a name.cam
is a valid camera name known to the world object supplied.-
cam
¶ Property for getting the currently active camera.
Always equals
self.cameras[self.activeCamera]
.
Fake event handler called by
Layer.on_menu_enter()
when the containing menu is entered.
Fake event handler, same as
on_menu_enter()
but for exiting menus instead.
-
pos
¶ Property for accessing the current position of the active camera.
The value of this property will always be a list of length 3.
This property can also be written to.
-
rot
¶ Property for accessing the current rotation of the active camera.
This property can also be written to.
-
setActiveCamera
(name)[source]¶ Sets the active camera.
This method also calls the
Camera.on_activate()
event handler if the camera is not already active.
-
-
class
peng3d.world.
WorldViewMouseRotatable
(world, name, cam)[source]¶ Subclass of
WorldView()
that is rotatable using the user.Moving the mouse cursor left or right will rotate the attached camera horizontally and moving the mouse cursor up or down will rotate the camera vertically.
By default, each pixel traveled changes the angle in degrees by 0.15, though this can be changed via the
controls.mouse.sensitivity
config value.-
on_key_press
(symbol, modifiers)[source]¶ Keyboard event handler handling only the escape key.
If an escape key press is detected, mouse exclusivity is toggled via
PengWindow.toggle_exclusivity()
.
Fake event handler, same as
WorldView.on_menu_enter()
but forces mouse exclusivity.
Fake event handler, same as
WorldView.on_menu_exit()
but force-disables mouse exclusivity.
-
on_mouse_drag
(x, y, dx, dy, buttons, modifiers)[source]¶ Handler used to still enable mouse movement while a button is pressed.
-
on_mouse_motion
(x, y, dx, dy)[source]¶ Handles mouse motion and rotates the attached camera accordingly.
For more information about how to customize mouse movement, see the class documentation here
WorldViewMouseRotatable()
.
-