PyGLy

Pure Python OpenGL framework

Concepts

Transform Spaces

See also

Transform Spaces

Co-ordinate Systems

World Space

The World Space co-ordinate system is the global co-ordinate system in which all objects are located.

When using World Space, we are describing objects in terms of the global origin.

See also

Inertial Space

Local Space

Local Space co-ordinate systems are relative to another object.

Using Local Space simplify the management and upkeep of 3D objects because we can specify them relative to another object.

Example

Image you have two 3D objects: a Soldier object, and a Gun object.

The Soldier and Gun are placed using co-ordinates in World Space.

If the Soldier picks the gun up, how do we keep the Gun positioned on the Soldier’s body?

We can use World Space co-ordinates to place the Gun. To do this we need to know the Soldier’s position and the position relative to the Soldier to place the gun. If the Soldier moves, we must re-calculate this value.

Or we could position the Gun using a Local Space co-ordinate system relative to the Soldier. Using this, we only need to know the position relative to the Soldier to place the gun. If the Soldier moves, we don’t need to re-calculate anything because the Gun is relative to the Soldier and will move with it.

Transforms

Manipulation of 3D spaces is performed through the use of Transform classes. These provide access to common functions related to translation and orientation of objects in 3D space.

PyGLy provides two types of Transform classes: Transform, and WorldTransform. These objects differ in the co-ordinate systems the functions manipulate.

The Transform class implements Local Space manipulations. Modifications done using the Transform class are performed with no understanding of World Space. When used outside of a hierarchy, the Transform space is relative to World Space. When used inside a hierarchy, the Transform space is relative to the parent’s Local Space.

The WorldTransform class implements World Space manipulations. A WorldTransform object is linked to a Transform object. Modifications done using the WorldTransform class are performed in World Space. This can be used to set absolute positioning of an object despite it’s parent’s transform.

The WorldTransform class implements the TreeNode class which adds the concept of a hierarchy. WorldTransforms can be joined together in a Parent - Child tree (1 parent maximum). This enables the inheritance of parent transforms.

Usage of WorldTransform or Transform objects is not mutually exclusive. Modifications performed on the WorldTransform or the linked Transform object are propagated to each other.

Transform Spaces

Each Transform class exposes two co-ordinate spaces, Object Space, and Inertial Space.

When using Object Space, the X,Y and Z axis inherit the orientation from the Object. As the Object’s orientation changes, the X,Y and Z axis presented by functions change accordingly.

When using Inertial Space, the X,Y and Z axis remain fixed regardless of the Object’s orientation.

Object Space

The Object Space co-ordinate system’s axis are fixed to the object’s orientation. As the object is rotated, the Object Space axis will change with the object.

_images/transform_object_space.png

Object Transform Space.

See also

Object Space

Inertial Space

The Inertial Space co-ordinate system orientation is relative to it’s parent orientation. When there is no parent, the co-ordinate system is the same as the global World Space. The Inertial Space axis does not change when the object is rotated.

_images/transform_inertial_space.png

Inertial Transform Space

See also

Inertial Space

API

OpenGL functions

Common Functions

Common Utilities

Legacy

Viewport

Viewport

Ratio Viewport

See also

Module pygly.gl Documentation of the pygly.gl module. Contains viewport controls.

View Matrices

View Matrix

Perspective View Matrix

Orthogonal View Matrix

Monkey Patch

Transform Spaces

Object Space

Inertial Space

Transform Systems

Transform

World Transform

Tree

Tree Node

Tree Leaf

class pygly.tree_leaf.TreeLeaf[source]

Base class for Tree Leaf objects.

Supports a single parent. Cannot have children.

__init__()[source]

Creates a tree leaf object.

parent

The current parent of the node or None if there isn’t one.

This is an @property decorated method which allows retrieval and assignment of the scale value.

predecessors()[source]

Returns successive parents of the node.

Generator function that allows iteration up the tree.

Scene Graph

Scene Node

Camera Node

Render Node

Render Callback Node

See also

Class pygly.render_node.RenderNode
Documentation of the pygly.render_node.RenderNode class, the parent of this class.

Rendering

OpenGL

Shaders

Buffers

class pygly.vertex_array.VertexArray[source]

Wraps OpenGL Vertex Array Objects.

Provides wrappers around standard functions and higher level wrappers with PyGLy.BufferRegion interfaces.

Example:

vs = Shader( GL_VERTEX_SHADER, shader_source['vert'] )
fs = Shader( GL_FRAGMENT_SHADER, shader_source['frag'] )
shader = ShaderProgram( vs, fs )

# a basic triangle
vertices = numpy.array(
    [
        #  X    Y    Z          R    G    B
        (( 0.0, 1.0, 0.0),     (1.0, 0.0, 0.0)),
        ((-2.0,-1.0, 0.0),     (0.0, 1.0, 0.0)),
        (( 2.0,-1.0, 0.0),     (0.0, 0.0, 1.0)),
        ],
    dtype = [
        ('position','float32',(3,)),
        ('colour','float32',(3,))
        ]
    )
buffer = DtypeVertexBuffer(
    vertices.dtype,
    GL_ARRAY_BUFFER,
    GL_STATIC_DRAW,
    data = vertices
    )

vao = VertexArray()

vao.bind()
buffer.bind()
buffer.set_attribute_pointer_dtype( shader, 'in_position', 'position' )
buffer.set_attribute_pointer_dtype( shader, 'in_colour', 'colour' )
buffer.unbind()
vao.unbind()

Warning

This is an OpenGL Core function (>=3.0) and should not be called for Legacy profile applications (<=2.1).

__init__()[source]
bind()[source]
handle
unbind()[source]

Texturing

Sorting

Weak Method Reference

Provides an implementation of a WeakMethodReference for weak references to functions and methods.

The standard weakref module in Python cannot store references to non-bound functions and should not be used to perform this task.

Code borrowed from the following places: http://code.activestate.com/recipes/81253/ http://stackoverflow.com/questions/3942303/how-does-a-python-set-check-if-two-objects-are-equal-what-methods-does-an-o

class pygly.weak_method_reference.WeakMethodReference(function=None)[source]

Provides the ability to store a weak pointer to class members on top of the existing weakref functionality provided by python.

This class also provides comparison operators to allow proper usage in containers such as set([]).

The ability to change the weak reference is not supported to prevent mutability. This is important for container support as the object hash would change after storing it.

__init__(function=None)[source]

Initialises the weak reference with a function or class method.

Args:
function: The object to store a weak reference to. This can be a class, object, method or function.
is_alive()[source]

Check if the referenced object is valid.

The equivalent to ‘not is_dead()’ Make a positive method call because double negatives suck

is_dead()[source]

Check if the referenced object is invalid.

Returns:
True if the referenced callable was a bound method and the instance no longer exists. Otherwise, return False.

Indices and tables