pyglet_helper.objects package

Submodules

pyglet_helper.objects.arrow module

class pyglet_helper.objects.arrow.Arrow(fixed_width=False, head_width=0.0, head_length=0.0, shaft_width=0.0, color=<pyglet_helper.util.rgba.Rgb instance>, pos=Vector(0, 0, 0), axis=(1, 0, 0))

Bases: pyglet_helper.objects.primitive.Primitive

A 3D 4-sided arrow, with adjustable head and shaft. By default, pointing along +x, unit length.

Parameters:
  • fixed_width (bool) – if True, the arrow’s head width and length will not be scaled in proportion to its length.
  • head_width (float) – The width of the arrow’s head section.
  • head_length (float) – The length of the arrow’s length section
  • shaft_width (float) – The length of the arrow’s shaft section
  • color (pyglet_helper.util.Rgb) – The arrow’s color.
  • pos (pyglet_helper.util.pos) – The arrow’s position
  • axis (pyglet_helper.util.Vector) – The arrow’s axis direction
center

Calculates the center of the arrow by subtracting the axis off of the position

Returns:The arrow’s center (position+axis)/2
Return type:float
degenerate
Returns:True if the arrow has an effective length of 0
Return type:bool
effective_geometry(gcf)

Initializes these four variables with the effective geometry for the arrow. The resulting geometry is scaled to view space, but oriented and positioned in model space. The only required transforms are reorientation and translation.

Parameters:gcf (float) – The scaling factor
fixed_width
head_length
head_width
init_model(scene)

Add the arrow head and shaft to the scene.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model into.
length
render(scene)

Render the arrow on the current view.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model into.
shaft_width

pyglet_helper.objects.axial module

class pyglet_helper.objects.axial.Axial(axis=Vector(1, 0, 0), radius=1.0, color=<pyglet_helper.util.rgba.Rgb instance>, pos=Vector(0, 0, 0), material=<pyglet_helper.objects.material.Material object>, other=None)

Bases: pyglet_helper.objects.primitive.Primitive

A subclass for all shapes with some radial symmetry around an axis (spheres, cones, etc., ).

Parameters:
  • other (pyglet_helper.objects.Axial) – another axial object to copy properties from (optional)
  • axis (pyglet_helper.util.Vector) – The axis for the orientation of the object.
  • radius (float) – The object’s radius.
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
  • material (pyglet_helper.util.Material) – The object’s material
material_matrix
radius

pyglet_helper.objects.box module

class pyglet_helper.objects.box.Box(width=1.0, height=1.0, length=1.0, color=<pyglet_helper.util.rgba.Rgb instance>, pos=Vector(0, 0, 0))

Bases: pyglet_helper.objects.rectangular.Rectangular

A box object.

Parameters:
  • width (float) – The box’s width.
  • height (float) – The box’s height.
  • length (float) – The box’s length.
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
init_model(scene, skip_right_face=False)

Add the Vertexes and Normals to the compile list.

Parameters:
  • scene (pyglet_helper.objects.View) – The view to render the model to.
  • skip_right_face (bool) – If True, the right face will not be rendered.
render(scene)

Render the box in the view

Parameters:scene (pyglet_helper.objects.View) – The view to render the model into

pyglet_helper.objects.cone module

class pyglet_helper.objects.cone.Cone(radius=1.0, color=<pyglet_helper.util.rgba.Rgb instance>, pos=Vector(0, 0, 0), axis=Vector(1, 0, 0))

Bases: pyglet_helper.objects.axial.Axial

A Cone object

Parameters:
  • radius (float) – The cone’s bottom radius.
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
  • axis (pyglet_helper.util.Vector) – The cone points from the base to the point along the axis.
Returns:

center

Get the center of the object.

Returns:position + axis/2
Return type:float
degenerate
Returns:True if radius == 0 or the length is 0
Return type:bool
init_model(scene)

Add the cone quadrics to the view.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model to.
length
render(scene)

Add the cone to the scene.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model into

pyglet_helper.objects.cylinder module

class pyglet_helper.objects.cylinder.Cylinder(pos=Vector(0, 0, 0), axis=Vector(1, 0, 0), radius=1.0, color=<pyglet_helper.util.rgba.Rgb instance>)

Bases: pyglet_helper.objects.axial.Axial

A Cylinder object.

Parameters:
  • radius (float) – The cylinder’s radius.
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
  • axis (pyglet_helper.util.Vector) – The cone points from the base to the point along the axis.
center
Returns:Position + axis/2
Return type:float
degenerate
init_model(scene)

Add the cylinder quadrics to the view.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model to.
length
render(scene)

Add the cylinder to the view.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model into

pyglet_helper.objects.ellipsoid module

class pyglet_helper.objects.ellipsoid.Ellipsoid(height=1.0, width=1.0, length=1.0, color=<pyglet_helper.util.rgba.Rgb instance>, pos=Vector(0, 0, 0))

Bases: pyglet_helper.objects.sphere.Sphere

An Ellipsoid object

Parameters:
  • width (float) – The ellipsoid’s width.
  • height (float) – The ellipsoid’s height.
  • length (float) – The ellipsoid’s length.
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
degenerate()
height
length
scale
size
width

pyglet_helper.objects.light module

class pyglet_helper.objects.light.Light(color=<pyglet_helper.util.rgba.Rgb instance>, specular=(0.5, 0.5, 1, 0.5), diffuse=(1, 1, 1, 1), position=(1, 0.5, 1, 0))

Bases: pyglet_helper.objects.renderable.Renderable

A light object

Parameters:
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • specular (array_like) – The color of the specular reflections on the objects in the scene.
  • diffuse – The color of the diffuse reflections of the objects in the scene.
  • position (array_like) – The object’s position.
center
get_vertex(gcf)
is_light
material
render(v)

Add the light to the scene. :param scene: The view to render the model into :type scene: pyglet_helper.objects.View

rgb

pyglet_helper.objects.material module

class pyglet_helper.objects.material.Material(translucent=False, shader_program=None)

Bases: object

A Material object, used for storing and handling shader programs.

Parameters:
  • translucent (bool) –
  • shader_program (str) – The GLSL (Graphics library shader language) code to be executed).
Returns:

get_shader_program()
shader
textures
translucent

pyglet_helper.objects.primitive module

class pyglet_helper.objects.primitive.Primitive(axis=Vector(1, 0, 0), up=Vector(0, 1, 0), pos=Vector(0, 0, 0), make_trail=False, trail_initialized=False, obj_initialized=False, color=<pyglet_helper.util.rgba.Rgb instance>, material=<pyglet_helper.objects.material.Material object>, other=None)

Bases: pyglet_helper.objects.renderable.Renderable

A base class for all geometric shapes.

Parameters:
  • axis (pyglet_helper.util.Vector) – The orientation to use when drawing.
  • up (pyglet_helper.util.Vector) – A vector that points to the current up direction in the view.
  • pos (pyglet_helper.util.Vector) – The object’s position.
  • make_trail (bool) – If True, the position of the primitive object will be tracked over time.
  • trail_initialized (bool) – If True, the trail, meaning the list of tracked positions over time, has been initialized
  • obj_initialized (bool) – If True, the object has been initialized
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • material (pyglet_helper.util.Material) – The object’s material
  • other (pyglet_helper.objects.Primitive) – another object to copy properties from (optional)
axis
blue
center
green
is_light
make_trail
model_world_transform(world_scale=0.0, object_scale=Vector(1, 1, 1))

Performs scale, rotation, translation, and world scale (gcf) transforms in that order.

Parameters:
  • world_scale (float) – The global scaling factor.
  • object_scale (pyglet_helper.util.Vector) – The scaling to applied to this specific object
Return type:

pyglet_helper.util.Tmatrix

Returns:

Returns a tmatrix that performs reorientation of the object from model orientation to world (and view) orientation.

pos
primitive_object
red
rotate(angle, axis, origin)

Rotate the primitive’s axis by angle about a specified axis at a specified origin.

Parameters:
  • angle (float) – the angle to rotate by, in radians
  • axis (pyglet_helper.util.Vector) – The axis to rotate around.
  • origin (pyglet_helper.util.Vector) – The center of the axis of rotation.
typeid
up
x
y
z
pyglet_helper.objects.primitive.trail_update(obj)

A function for keeping track of the change in a primitive object’s position.

Parameters:obj (pyglet_helper.objects.Primitive) – the primitive object to track.

pyglet_helper.objects.pyramid module

class pyglet_helper.objects.pyramid.Pyramid(pos=Vector(0, 0, 0), width=1.0, height=1.0, length=1.0, color=<pyglet_helper.util.rgba.Rgb instance>)

Bases: pyglet_helper.objects.rectangular.Rectangular

A Pyramid Object

Parameters:
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
  • width (float) – The pyramid’s width.
  • height (float) – The pyramid’s height.
  • length (float) – The pyramid’s length.
Returns:

center
init_model(scene)

Add the pyramid normals and vertices to the View

Parameters:scene (pyglet_helper.objects.View) – The view to render the model to.
material_matrix
render(scene)

Add a pyramid to the view.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model into

pyglet_helper.objects.rectangular module

class pyglet_helper.objects.rectangular.Rectangular(other=None, pos=Vector(0, 0, 0), width=1.0, height=1.0, length=1.0, color=<pyglet_helper.util.rgba.Rgb instance>)

Bases: pyglet_helper.objects.primitive.Primitive

A base class for rectangular-like objects (such as the box or pyramid)

Parameters:
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
  • width (float) – The object’s width.
  • height (float) – The object’s height.
  • length (float) – The object’s length.
apply_transform(scene)

Scale the object to the correct height, width and length

Parameters:scene (pyglet_helper.objects.View) – the object’s current view
height
length
size
width

pyglet_helper.objects.renderable module

class pyglet_helper.objects.renderable.Renderable(color=<pyglet_helper.util.rgba.Rgb instance>, mat=<pyglet_helper.objects.material.Material object>, opacity=1.0, visible=False)

Bases: object

A base class for all geometric shapes and lights.

Parameters:
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • material (pyglet_helper.util.Material) – The object’s material
  • opacity (float) – The transparency value of the object
  • visible (bool) – If True, the object will be rendered on the screen
material
translucent
class pyglet_helper.objects.renderable.View(gcf=1.0, view_width=800, view_height=600, anaglyph=False, coloranaglyph=False, forward_changed=False, gcf_changed=False, lod_adjust=0, tan_hfov_x=0, tan_hfov_y=0, enable_shaders=True, background_color=<pyglet_helper.util.rgba.Rgb instance>)

Bases: object

A class for handling the environment in which all objects are rendered

Parameters:
  • gcf (float) – The global scaling factor, a coefficient applied to all objects in the view
  • view_width (int) – The width of the viewport in pixels.
  • view_height (int) – The height of the viewport in pixels.
  • anaglyph (bool) – If True, the scene will be rendered in anaglyph stereo mode.
  • coloranaglyph (bool) – If True, the scene will be rendered in coloranaglyph stereo mode.
  • forward_changed (bool) – True if the forward vector changed since the last rending operation.
  • gcf_changed (bool) – True if the global scaling factor changed since the last render cycle.
  • lod_adjust (int) – The level-of-detail.
  • tan_hfov_x (int) – The tangent of half the horizontal field of view.
  • tan_hfov_y (int) – The tangent of half the vertical field of view.
  • enable_shaders (bool) – If True, shader programs will be allowed
  • background_color (pyglet_helper.util.Rgb) – The scene’s background color
draw_lights()

Render the lights in the scene

pixel_coverage(pos, radius)

Compute the apparent diameter, in pixels, of a circle that is parallel to the screen, with a center at pos, and some radius. If pos is behind the camera, it will return negative.

Parameters:
  • pos (pyglet_helper.util.Vector) – The position in the view to examine
  • radius (float) – The radius of coverage to examine
Returns:

The diameter in pixels.

Return type:

float

setup()

Does some one-time OpenGL setup.

pyglet_helper.objects.ring module

class pyglet_helper.objects.ring.Ring(thickness=0.0, radius=1.0, color=<pyglet_helper.util.rgba.Rgb instance>, pos=Vector(0, 0, 0), axis=Vector(1, 0, 0))

Bases: pyglet_helper.objects.axial.Axial

A Ring object

Parameters:
  • thickness (float) – The ring’s thickness.
  • radius (float) – The ring’s radius.
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
  • axis (pyglet_helper.util.Vector) – The cone points from the base to the point along the axis.
degenerate
material_matrix
render(scene)

Add a ring to the view.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model into
thickness
pyglet_helper.objects.ring.clamp(lower, value, upper)

Restrict a value to be between a lower value and upper value. Used to restrict the number of polygons in the ring object

Parameters:
  • lower (float or int) – the lowest possible value of value
  • value (float or int) – the value to check
  • upper (float or int) – the largest possible value of value
Return type:

float or int

Returns:

the restricted value

pyglet_helper.objects.sphere module

class pyglet_helper.objects.sphere.Sphere(color=<pyglet_helper.util.rgba.Rgb instance>, pos=Vector(0, 0, 0), radius=1.0, material=<pyglet_helper.objects.material.Material object>, other=None)

Bases: pyglet_helper.objects.axial.Axial

A Sphere object

Parameters:
  • radius (float) – The sphere’s radius.
  • color (pyglet_helper.util.Rgb) – The object’s color.
  • pos (pyglet_helper.util.Vector) – The object’s position.
  • axis (pyglet_helper.util.Vector) – The cone points from the base to the point along the axis.
  • material (pyglet_helper.util.Material) – The object’s material
  • other (pyglet_helper.objects.Sphere) – another sphere object to copy properties from (optional)
degenerate

Returns true if this object should not be drawn. Conditions are: zero radius, or visible is false. (overridden by the ellipsoid class).

init_model(scene)

Add the sphere quadrics to the View

Parameters:scene (pyglet_helper.objects.View) – The view to render the model to.
material_matrix
render(geometry)

Add the sphere to the view.

Parameters:scene (pyglet_helper.objects.View) – The view to render the model into
scale

Exposed for the benefit of the ellipsoid object, which overrides it. The default is to use <radius, radius, radius> for the scale.

Module contents