gillcup_graphics.transformation

Transformation objects

The Transformation interface is implemented by several classes that have used whenever info about graphics objects’ position, scale, rotation, etc. are needed.

A graphic object’s transform method takes a Transformation object and calls its translate, scale, rotate or premultiply methods. While premultiply is the most general, the other methods are more straightforward to use and often much faster.

For drawing, a GlTransformation object, which will update the OpenGL state directly, is passed to the method. For hit tests and mouse events, a PointTransformation is used.

Each transformation object implements a stack modeled on the OpenGL matrix stack: any state can be saved with push, and the last-pushed state restored with pop. The state context manager simplifies working with the stack.

class gillcup_graphics.transformation.BaseTransformation[source]

Base for all transformations: contains common functionality

Transformations are based on a 3D affine transformation matrix (a 4x4 matrix where the last column is [0 0 0 1])

state

Context manager wrapping push() and pop()

push()[source]

Push the matrix state: the corresponding pop() will return here

You probably want to use state instead.

pop()[source]

Restore matrix saved by the corresponding push() call

reset()[source]

Reset the matrix to identity

translate(x=0, y=0, z=0)[source]

Change the transformatin to represent moving an object

The object is moved, without rotating, along the vector [x y z].

rotate(angle, x=0, y=0, z=1)[source]

Change the transformatin to represent rotating an object

The object is rotated angle degrees along the axis specified by the vector [x y z]. This must be an unit vector (i.e. x² + y² + z² = 1)

scale(x=1, y=1, z=1)[source]

Change the transformatin to represent scaling an object

The object is rotated angle degrees along the axis specified by the vector [x y z]. This must be an unit vector (i.e. x² + y² + z² = 1)

premultiply(values)[source]

Premultiply the given matrix to self, in situ

Parameters:values – An iterable of 16 matrix elements in row-major (C) order
class gillcup_graphics.transformation.GlTransformation[source]

OpenGL implementation: affects the OpenGL state directly

class gillcup_graphics.transformation.PointTransformation(x, y, z)[source]

Transformation for a single point

The point attribute corresponds to the vector given to the constructor transformed by whatever transformation was applied to this object.

class gillcup_graphics.transformation.MatrixTransformation[source]

A Transformation with a full, queryable result matrix.

__len__()[source]

Return 16, the size of the matrix.

__getitem__(item)[source]

Get a number from the matrix. Supports (x, y) pairs, or single ints.

Note that __len__ and __getitem__ are one variant of the iteration protocol: MatrixTransformation supports iter() as well.

transform_point(x=0, y=0, z=0)[source]

Return the given vector multiplied by this matrix

Returns a 3-element iterable