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.
-
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)
-
-
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.