Cogl.MatrixStack¶
- Subclasses:
None
Methods¶
- Inherited:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
None
Fields¶
None
Class Details¶
- class Cogl.MatrixStack¶
- Bases:
- Abstract:
No
Tracks your current position within a hierarchy and lets you build up a graph of transformations as you traverse through a hierarchy such as a scenegraph.
A
Cogl.MatrixStack
always maintains a reference to a single transformation at any point in time, representing the transformation at the current position in the hierarchy. You can get a reference to the current transformation by callingCogl.MatrixStack.get_entry
().When a
Cogl.MatrixStack
is first created withCogl.MatrixStack.new
() then it is conceptually positioned at the root of your hierarchy and the current transformation simply represents an identity transformation.As you traverse your object hierarchy (your scenegraph) then you should call
Cogl.MatrixStack.push
() whenever you move down one level and callCogl.MatrixStack.pop
() whenever you move back up one level towards the root.At any time you can apply a set of operations, such as “rotate”, “scale”, “translate” on top of the current transformation of a
Cogl.MatrixStack
using functions such asCogl.MatrixStack.rotate
(),Cogl.MatrixStack.scale
() andCogl.MatrixStack.translate
(). These operations will derive a new current transformation and will never affect a transformation that you have referenced usingCogl.MatrixStack.get_entry
().Internally applying operations to a
Cogl.MatrixStack
builds up a graph ofCogl.MatrixEntry
structures which each represent a single immutable transform.- classmethod new(ctx)¶
- Parameters:
ctx (
Cogl.Context
) – ACogl.Context
- Returns:
A newly allocated
Cogl.MatrixStack
- Return type:
Allocates a new
Cogl.MatrixStack
that can be used to build up transformations relating to objects in a scenegraph like hierarchy. (See the description ofCogl.MatrixStack
andCogl.MatrixEntry
for more details of what a matrix stack is best suited for)When a
Cogl.MatrixStack
is first allocated it is conceptually positioned at the root of your scenegraph hierarchy. As you traverse your scenegraph then you should callCogl.MatrixStack.push
() whenever you move down a level andCogl.MatrixStack.pop
() whenever you move back up a level towards the root.Once you have allocated a
Cogl.MatrixStack
you can get a reference to the current transformation for the current position in the hierarchy by callingCogl.MatrixStack.get_entry
().Once you have allocated a
Cogl.MatrixStack
you can apply operations such as rotate, scale and translate to modify the current transform for the current position in the hierarchy by callingCogl.MatrixStack.rotate
(),Cogl.MatrixStack.scale
() andCogl.MatrixStack.translate
().
- frustum(left, right, bottom, top, z_near, z_far)¶
- Parameters:
left (
float
) – X position of the left clipping plane where it intersects the near clipping planeright (
float
) – X position of the right clipping plane where it intersects the near clipping planebottom (
float
) – Y position of the bottom clipping plane where it intersects the near clipping planetop (
float
) – Y position of the top clipping plane where it intersects the near clipping planez_near (
float
) – The distance to the near clipping plane (Must be positive)z_far (
float
) – The distance to the far clipping plane (Must be positive)
Replaces the current matrix with a perspective matrix for a given viewing frustum defined by 4 side clip planes that all cross through the origin and 2 near and far clip planes.
- get()¶
- Returns:
A direct pointer to the current transform or
None
and in that case matrix will be initialized with the value of the current transform.- matrix:
The potential destination for the current matrix
- Return type:
(
Cogl.Matrix
, matrix:Cogl.Matrix
)
Resolves the current self transform into a
Cogl.Matrix
by combining the operations that have been applied to build up the current transform.There are two possible ways that this function may return its result depending on whether the stack is able to directly point to an internal
Cogl.Matrix
or whether the result needs to be composed of multiple operations.If an internal matrix contains the required result then this function will directly return a pointer to that matrix, otherwise if the function returns
None
then matrix will be initialized to match the current transform of self.matrix will be left untouched if a direct pointer is returned.
- get_entry()¶
- Returns:
A pointer to the
Cogl.MatrixEntry
representing the current matrix stack transform.- Return type:
Gets a reference to the current transform represented by a
Cogl.MatrixEntry
pointer.The transform represented by a
Cogl.MatrixEntry
is immutable.Cogl.MatrixEntry
s are reference counted usingCogl.MatrixEntry.ref
() andCogl.MatrixEntry.unref
() and you should callCogl.MatrixEntry.unref
() when you are finished with and entry you get viaCogl.MatrixStack.get_entry
().
- get_inverse()¶
- Returns:
True
if the inverse was successfully calculated orFalse
for degenerate transformations that can’t be inverted (in this case the inverse matrix will simply be initialized with the identity matrix)- inverse:
The destination for a 4x4 inverse transformation matrix
- Return type:
(
int
, inverse:Cogl.Matrix
)
Gets the inverse transform of the current matrix and uses it to initialize a new
Cogl.Matrix
.
- load_identity()¶
Resets the current matrix to the identity matrix.
- multiply(matrix)¶
- Parameters:
matrix (
Cogl.Matrix
) – the matrix to multiply with the current model-view
Multiplies the current matrix by the given matrix.
- orthographic(x_1, y_1, x_2, y_2, near, far)¶
- Parameters:
x_1 (
float
) – The x coordinate for the first vertical clipping planey_1 (
float
) – The y coordinate for the first horizontal clipping planex_2 (
float
) – The x coordinate for the second vertical clipping planey_2 (
float
) – The y coordinate for the second horizontal clipping planenear (
float
) – The distance to the near clipping plane (will be negative if the plane is behind the viewer)far (
float
) – The distance to the far clipping plane (will be negative if the plane is behind the viewer)
Replaces the current matrix with an orthographic projection matrix.
- perspective(fov_y, aspect, z_near, z_far)¶
- Parameters:
Replaces the current matrix with a perspective matrix based on the provided values.
You should be careful not to have too great a z_far / z_near ratio since that will reduce the effectiveness of depth testing since there wont be enough precision to identify the depth of objects near to each other.
- pop()¶
Restores the previous transform that was last saved by calling
Cogl.MatrixStack.push
().This is usually called while traversing a scenegraph whenever you return up one level in the graph towards the root node.
- push()¶
Saves the current transform and starts a new transform that derives from the current transform.
This is usually called while traversing a scenegraph whenever you traverse one level deeper.
Cogl.MatrixStack.pop
() can then be called when going back up one layer to restore the previous transform of an ancestor.
- rotate(angle, x, y, z)¶
- Parameters:
Multiplies the current matrix by one that rotates the around the axis-vector specified by x, y and z. The rotation follows the right-hand thumb rule so for example rotating by 10 degrees about the axis-vector (0, 0, 1) causes a small counter-clockwise rotation.
- rotate_euler(euler)¶
- Parameters:
euler (
Cogl.Euler
) – ACogl.Euler
Multiplies the current matrix by one that rotates according to the rotation described by euler.
- rotate_quaternion(quaternion)¶
- Parameters:
quaternion (
Cogl.Quaternion
) – ACogl.Quaternion
Multiplies the current matrix by one that rotates according to the rotation described by quaternion.
- scale(x, y, z)¶
- Parameters:
Multiplies the current matrix by one that scales the x, y and z axes by the given values.
- set(matrix)¶
- Parameters:
matrix (
Cogl.Matrix
) – ACogl.Matrix
replace the current matrix value with
Replaces the current self matrix value with the value of matrix. This effectively discards any other operations that were applied since the last time
Cogl.MatrixStack.push
() was called or since the stack was initialized.