Package gameobjects :: Module matrix44 :: Class Matrix44
[hide private]
[frames] | no frames]

Class Matrix44

source code


Instance Methods [hide private]
 
__init__(self, *args)
If no parameteres are given, the Matrix44 is initialised to identity.
source code
 
_get_row_0(self) source code
 
_get_row_1(self) source code
 
_get_row_2(self) source code
 
_get_row_3(self) source code
 
_set_row_0(self, values) source code
 
_set_row_1(self, values) source code
 
_set_row_2(self, values) source code
 
_set_row_3(self, values) source code
 
to_opengl(self)
Converts the matrix in to a list of values, suitable for using with glLoadMatrix*
source code
 
set(self, row1, row2, row3, row4)
Sets all four rows of the matrix,
source code
 
get_row(self, row_no)
Gets a row of the matrix as a tuple
source code
 
__str__(self)
'Pretty' formatting of the Matrix44.
source code
 
__repr__(self)
repr(x)
source code
 
__hash__(self)
Allows matrices to be used as keys in a dictionary.
source code
 
__setitem__(self, coord, value)
Sets an individual element in the Matrix44.
source code
 
__getitem__(self, coord)
Gets an individual element in the Matrix44.
source code
 
__iter__(self)
Iterates over all 16 values in the Matrix44.
source code
 
__neg__(self)
Returns the inverse of the matrix.
source code
 
__mul__(self, rhs)
Returns the result of multiplying this Matrix44 by another, called by the * (multiply) operator.
source code
 
__imul__(self, rhs)
Multiplies this Matrix44 by another, called by the *= operator.
source code
 
fast_mul(self, rhs)
Multiplies this matrix by another.
source code
 
copy(self)
Returns a copy of this matrix.
source code
 
__copy__(self)
Returns a copy of this matrix.
source code
 
components(self)
Returns an iterator for the components in the Matrix44.
source code
 
transposed_components(self)
Returns an iterator for the components in the Matrix44 in transposed order.
source code
 
rows(self)
Returns an iterator for the rows in the Matrix44 (yields 4 tuples of 4 values).
source code
 
columns(self)
Returns an iterator for the columns in the Matrix44 (yields 4 tuples of 4 values).
source code
 
get_row_vec3(self, row_no)
Returns a Vector3 for a given row.
source code
 
get_column(self, col_no)
Returns a column as a tuple of 4 values.
source code
 
set_row(self, row_no, row)
Sets the values in a row.
source code
 
set_column(self, col_no, col)
Sets the values in a column.
source code
 
transform_vec3(self, v)
Transforms a vector and returns the result as a Vector3.
source code
 
transform(self, v)
Transforms a Vector3 and returns the result as a tuple.
source code
 
transform4(self, v)
Transforms a 4d vector and returns the result as a tuple.
source code
 
transform_sequence(self, points) source code
 
transform_sequence_vec3(self, points) source code
 
iter_transform_vec3(self, points)
Transforms a sequence of points, and yields the result as Vector3s
source code
 
iter_transform(self, points)
Transforms a sequence of points and yields the result as tuples.
source code
 
iter_transform3(self, points)
Transforms a sequence of points and yields the result as tuples.
source code
 
iter_transform4(self, points)
Transforms a sequence of points and yields the result as tuples.
source code
 
rotate_vec3(self, v)
Rotates a Vector3 and returns the result.
source code
 
rotate(self, v)
Rotates a Vector3 and returns the result as a tuple The translation part of the Matrix44 is ignored.
source code
 
inverse_transform(self, v)
Inverse trasforms a Vector3 and returns the result.
source code
 
make_identity(self)
Makes an identity Matrix44.
source code
 
make_copy(self, other)
Makes a copy of another Matrix44.
source code
 
make_scale(self, scale_x, scale_y=None, scale_z=None)
Makes a scale Matrix44.
source code
 
make_translation(self, x, y, z)
Makes a translation Matrix44.
source code
 
make_x_rotation(self, angle)
Makes a rotation Matrix44 around the x axis.
source code
 
make_y_rotation(self, angle)
Makes a rotation Matrix44 around the y axis.
source code
 
make_z_rotation(self, angle)
Makes a rotation Matrix44 around the z axis.
source code
 
make_rotation_about_axis(self, axis, angle)
Makes a rotation Matrix44 around an axis.
source code
 
make_xyz_rotation(self, angle_x, angle_y, angle_z)
Makes a rotation Matrix44 about 3 axis.
source code
 
make_perspective_projection(self, left, right, top, bottom, near, far)
Makes a perspective projection Matrix44.
source code
 
make_perspective_projection_fov(self, fov, aspect, near, far)
Creates a Matrix44 that projects points in to 2d space
source code
 
transpose(self)
Swaps the rows for columns.
source code
 
get_transpose(self)
Returns a Matrix44 that is a copy of this, but with rows and columns swapped.
source code
 
get_inverse_rot_trans(self)
Returns the inverse of a Matrix44 with only rotation and translation.
source code
 
get_inverse(self)
Returns the inverse (matrix with the opposite effect) of this matrix.
source code
 
invert(self)
Inverts this matrix.
source code
 
move(self, forward=None, right=None, up=None)
Changes the translation according to a direction vector.
source code

Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Methods [hide private]
 
from_iter(cls, iterable)
Creates a Matrix44 from an iterable of 16 values.
source code
 
clone(cls, copy_Matrix44)
Creates a Matrix44 that is a copy of another.
source code
 
blank(cls)
Creates a blank Matrix44 (with no information).
source code
 
identity(cls)
Creates and identity Matrix44.
source code
 
scale(cls, scale_x, scale_y=None, scale_z=None)
Creates a scale Matrix44.
source code
 
translation(cls, x, y, z)
Creates a translation Matrix44 to (x, y, z).
source code
 
x_rotation(cls, angle)
Creates a Matrix44 that does a rotation about the x axis.
source code
 
y_rotation(cls, angle)
Creates a Matrix44 that does a rotation about the y axis.
source code
 
z_rotation(cls, angle)
Creates a Matrix44 that does a rotation about the z axis.
source code
 
rotation_about_axis(cls, axis, angle)
Creates a Matrix44 that does a rotation about an axis.
source code
 
xyz_rotation(cls, angle_x, angle_y, angle_z)
Creates a Matrix44 that does a rotation about each axis.
source code
 
perspective_projection(cls, left, right, top, bottom, near, far)
Creates a Matrix44 that projects points in to 2d space.
source code
 
perspective_projection_fov(cls, fov, aspect, near, far)
Creates a Matrix44 that projects points in to 2d space
source code
Class Variables [hide private]
  _identity = ((1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (0.0,...
  _getters = _get_row_0, _get_row_1, _get_row_2, _get_row_3
  _setters = _set_row_0, _set_row_1, _set_row_2, _set_row_3
Properties [hide private]
  _row0
Row 0
  _row1
Row 1
  _row2
Row 2
  _row3
Row 3
  x_axis
Row 0
  right
Row 0
  y_axis
Row 1
  up
Row 1
  z_axis
Row 2
  forward
Row 2
  translate
Row 3
  _m

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args)
(Constructor)

source code 
If no parameteres are given, the Matrix44 is initialised to identity. If 1 parameter is given it should be an iterable with the 16 components of the matrix. If 4 parameters are given they should be 4 sequences of up to 4 values. Missing values in each row are padded out with values from the identity matix (so you can use Vector3's or tuples of 3 values).
Overrides: object.__init__

set(self, row1, row2, row3, row4)

source code 
Sets all four rows of the matrix,
Parameters:
  • row1 (sequence) - First row
  • row2 (sequence) - Second row
  • row3 (sequence) - Third row
  • row4 (sequence) - Fourth row
Returns:
None

get_row(self, row_no)

source code 

Gets a row of the matrix as a tuple

row_no -- Index of row

blank(cls)
Class Method

source code 
Creates a blank Matrix44 (with no information). This is rarely required, you may want to use an identity Matrix44, see Matrix44.identity()

scale(cls, scale_x, scale_y=None, scale_z=None)
Class Method

source code 
Creates a scale Matrix44. If one parameter is given the scale is uniform, if three parameters are give the scale is different (potentialy) on each x axis.

translation(cls, x, y, z)
Class Method

source code 

Creates a translation Matrix44 to (x, y, z).

x -- X Coordinate y -- Y Coordinate z -- Z Coordinate

x_rotation(cls, angle)
Class Method

source code 

Creates a Matrix44 that does a rotation about the x axis.

angle -- Angle of rotation (in radians)

y_rotation(cls, angle)
Class Method

source code 

Creates a Matrix44 that does a rotation about the y axis.

angle -- Angle of rotation (in radians)

z_rotation(cls, angle)
Class Method

source code 

Creates a Matrix44 that does a rotation about the z axis.

angle -- Angle of rotation (in radians)

rotation_about_axis(cls, axis, angle)
Class Method

source code 

Creates a Matrix44 that does a rotation about an axis.

axis -- A vector of the axis angle -- Angle of rotation

xyz_rotation(cls, angle_x, angle_y, angle_z)
Class Method

source code 

Creates a Matrix44 that does a rotation about each axis.

angle_x -- Angle of rotation, about x angle_y -- Angle of rotation, about y angle_z -- Angle of rotation, about z

perspective_projection(cls, left, right, top, bottom, near, far)
Class Method

source code 

Creates a Matrix44 that projects points in to 2d space.

left -- Coordinate of left of screen right -- Coordination of right of screen top -- Coordination of the top of the screen bottom -- Coordination of the borrom of the screen near -- Coordination of the near clipping plane far -- Coordinate of the far clipping plane

perspective_projection_fov(cls, fov, aspect, near, far)
Class Method

source code 

Creates a Matrix44 that projects points in to 2d space

fov -- The field of view (in radians) aspect -- The aspect ratio of the screen (width / height) near -- Coordinate of the near clipping plane far -- Coordinate of the far clipping plane

__str__(self)
(Informal representation operator)

source code 
'Pretty' formatting of the Matrix44.
Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: object.__repr__
(inherited documentation)

__hash__(self)
(Hashing function)

source code 
Allows matrices to be used as keys in a dictionary.
Overrides: object.__hash__

__setitem__(self, coord, value)
(Index assignment operator)

source code 

Sets an individual element in the Matrix44. coord is a tuple of (row, column)

eg. Matrix44[2,3] = 3.

__getitem__(self, coord)
(Indexing operator)

source code 

Gets an individual element in the Matrix44. coord is a tuple of (row, column)

eg. print Matrix44[2,3]

fast_mul(self, rhs)

source code 

Multiplies this matrix by another. Assumes that both matrices have a right column of (0, 0, 0, 1). This is true for matrices composed of rotations, translations and scales. fast_mul is approximately 25% quicker than the *= operator.

rhs -- A matrix

components(self)

source code 
Returns an iterator for the components in the Matrix44. ie returns all 16 values.

get_row_vec3(self, row_no)

source code 

Returns a Vector3 for a given row.

row_no -- The row index

get_column(self, col_no)

source code 

Returns a column as a tuple of 4 values.

col_no -- The column index

set_row(self, row_no, row)

source code 

Sets the values in a row.

row_no -- The index of the row row -- An container containing the new values

set_column(self, col_no, col)

source code 

Sets the values in a column.

col_no -- The index of the column col -- An sequence of 4 values

transform_vec3(self, v)

source code 

Transforms a vector and returns the result as a Vector3.

v -- Vector to transform

transform(self, v)

source code 

Transforms a Vector3 and returns the result as a tuple.

v -- Vector to transform

transform4(self, v)

source code 

Transforms a 4d vector and returns the result as a tuple.

v -- Vector to transform

iter_transform_vec3(self, points)

source code 

Transforms a sequence of points, and yields the result as Vector3s

points -- A sequence of vectors

iter_transform(self, points)

source code 

Transforms a sequence of points and yields the result as tuples.

points -- A sequence of vectors

iter_transform3(self, points)

source code 

Transforms a sequence of points and yields the result as tuples.

points -- A sequence of vectors

iter_transform4(self, points)

source code 

Transforms a sequence of points and yields the result as tuples.

points -- A sequence of vectors

rotate_vec3(self, v)

source code 

Rotates a Vector3 and returns the result. The translation part of the Matrix44 is ignored.

v -- Vector to rotate

rotate(self, v)

source code 

Rotates a Vector3 and returns the result as a tuple The translation part of the Matrix44 is ignored.

v -- Vector to rotate

inverse_transform(self, v)

source code 

Inverse trasforms a Vector3 and returns the result. Warning: This is expensive, pre-calculate an inverse Matrix44 if you can.

v -- Vector to transform

make_scale(self, scale_x, scale_y=None, scale_z=None)

source code 

Makes a scale Matrix44.

If the scale_y and scale_z parameters are not given they default to the same as scale_x.

make_rotation_about_axis(self, axis, angle)

source code 

Makes a rotation Matrix44 around an axis.

axis -- An iterable containing the axis (three values) angle -- The angle to rotate (in radians)

make_perspective_projection(self, left, right, top, bottom, near, far)

source code 

Makes a perspective projection Matrix44.

left -- Coordinate of left of screen right -- Coordination of right of screen top -- Coordination of the top of the screen bottom -- Coordination of the borrom of the screen near -- Coordination of the near clipping plane far -- Coordinate of the far clipping plane

make_perspective_projection_fov(self, fov, aspect, near, far)

source code 

Creates a Matrix44 that projects points in to 2d space

fov -- The field of view (in radians) aspect -- The aspect ratio of the screen (width / height) near -- Coordinate of the near clipping plane far -- Coordinate of the far clipping plane

get_inverse_rot_trans(self)

source code 
Returns the inverse of a Matrix44 with only rotation and translation. This is faster than the general get_inverse method.

move(self, forward=None, right=None, up=None)

source code 

Changes the translation according to a direction vector. To move in opposite directions (i.e back, left and down), first negate the vector.

forward -- Units to move in the 'forward' direction right -- Units to move in the 'right' direction up -- Units to move in the 'up' direction

Class Variable Details [hide private]

_identity

Value:
((1.0, 0.0, 0.0, 0.0),
 (0.0, 1.0, 0.0, 0.0),
 (0.0, 0.0, 1.0, 0.0),
 (0.0, 0.0, 0.0, 1.0))

Property Details [hide private]

_row0

Row 0
Get Method:
gameobjects.matrix44.Matrix44._get_row_0(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_0(self, values)

_row1

Row 1
Get Method:
gameobjects.matrix44.Matrix44._get_row_1(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_1(self, values)

_row2

Row 2
Get Method:
gameobjects.matrix44.Matrix44._get_row_2(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_2(self, values)

_row3

Row 3
Get Method:
gameobjects.matrix44.Matrix44._get_row_3(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_3(self, values)

x_axis

Row 0
Get Method:
gameobjects.matrix44.Matrix44._get_row_0(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_0(self, values)

right

Row 0
Get Method:
gameobjects.matrix44.Matrix44._get_row_0(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_0(self, values)

y_axis

Row 1
Get Method:
gameobjects.matrix44.Matrix44._get_row_1(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_1(self, values)

up

Row 1
Get Method:
gameobjects.matrix44.Matrix44._get_row_1(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_1(self, values)

z_axis

Row 2
Get Method:
gameobjects.matrix44.Matrix44._get_row_2(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_2(self, values)

forward

Row 2
Get Method:
gameobjects.matrix44.Matrix44._get_row_2(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_2(self, values)

translate

Row 3
Get Method:
gameobjects.matrix44.Matrix44._get_row_3(self)
Set Method:
gameobjects.matrix44.Matrix44._set_row_3(self, values)