<s> from gameobjects . util import format_number <EOL> from gameobjects . vector3 import Vector3 <EOL> from math import sin , cos , tan , sqrt , pi , radians <EOL> class Matrix44Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , description ) : <EOL> Exception . __init__ ( self ) <EOL> self . code = code <EOL> self . description = description <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . description , self . code ) <EOL> class Row ( tuple ) : <EOL> """<STR_LIT>""" <EOL> _type_error = "<STR_LIT>" <EOL> def __add__ ( self , rhs ) : <EOL> try : <EOL> return rhs . __radd__ ( self [ : rhs . _gameobjects_vector ] ) <EOL> except AttributeError : <EOL> raise TypeError ( self . _type_error ) <EOL> def __sub__ ( self , rhs ) : <EOL> try : <EOL> return rhs . __sub__ ( self [ : rhs . _gameobjects_vector ] ) <EOL> except AttributeError : <EOL> raise TypeError ( self . _type_error ) <EOL> def __mul__ ( self , rhs ) : <EOL> try : <EOL> return rhs . __mul__ ( self [ : rhs . _gameobjects_vector ] ) <EOL> except AttributeError : <EOL> raise TypeError ( self . _type_error ) <EOL> def __div__ ( self , rhs ) : <EOL> try : <EOL> return rhs . __div__ ( self [ : rhs . _gameobjects_vector ] ) <EOL> except AttributeError : <EOL> raise TypeError ( self . _type_error ) <EOL> def as_vec3 ( self ) : <EOL> """<STR_LIT>""" <EOL> return Vector3 . _from_float_sequence ( self ) <EOL> class Matrix44 ( object ) : <EOL> _identity = ( ( <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> ) , <EOL> ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> ) ) <EOL> __slots__ = ( '<STR_LIT>' , ) <EOL> def __init__ ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if not args : <EOL> self . _m = [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return <EOL> elif len ( args ) == <NUM_LIT:4> : <EOL> self . _m = [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> row_0 , row_1 , row_2 , row_3 = self . _setters <EOL> r1 , r2 , r3 , r4 = args <EOL> row_0 ( self , r1 ) <EOL> row_1 ( self , r2 ) <EOL> row_2 ( self , r3 ) <EOL> row_3 ( self , r4 ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % len ( args ) ) <EOL> def _get_row_0 ( self ) : <EOL> return Row ( self . _m [ <NUM_LIT:0> : <NUM_LIT:4> ] ) <EOL> def _get_row_1 ( self ) : <EOL> return Row ( self . _m [ <NUM_LIT:4> : <NUM_LIT:8> ] ) <EOL> def _get_row_2 ( self ) : <EOL> return Row ( self . _m [ <NUM_LIT:8> : <NUM_LIT:12> ] ) <EOL> def _get_row_3 ( self ) : <EOL> return Row ( self . _m [ <NUM_LIT:12> : <NUM_LIT:16> ] ) <EOL> def _set_row_0 ( self , values ) : <EOL> values = tuple ( values ) [ : <NUM_LIT:4> ] <EOL> self . _m [ <NUM_LIT:0> : len ( values ) ] = list ( map ( float , values ) ) <EOL> def _set_row_1 ( self , values ) : <EOL> values = tuple ( values ) [ : <NUM_LIT:4> ] <EOL> self . _m [ <NUM_LIT:4> : <NUM_LIT:4> + len ( values ) ] = list ( map ( float , values ) ) <EOL> def _set_row_2 ( self , values ) : <EOL> values = tuple ( values ) [ : <NUM_LIT:4> ] <EOL> self . _m [ <NUM_LIT:8> : <NUM_LIT:8> + len ( values ) ] = list ( map ( float , values ) ) <EOL> def _set_row_3 ( self , values ) : <EOL> values = tuple ( values ) [ : <NUM_LIT:4> ] <EOL> self . _m [ <NUM_LIT:12> : <NUM_LIT:12> + len ( values ) ] = list ( map ( float , values ) ) <EOL> _getters = ( _get_row_0 , _get_row_1 , _get_row_2 , _get_row_3 ) <EOL> _setters = ( _set_row_0 , _set_row_1 , _set_row_2 , _set_row_3 ) <EOL> _row0 = property ( _get_row_0 , _set_row_0 , None , "<STR_LIT>" ) <EOL> _row1 = property ( _get_row_1 , _set_row_1 , None , "<STR_LIT>" ) <EOL> _row2 = property ( _get_row_2 , _set_row_2 , None , "<STR_LIT>" ) <EOL> _row3 = property ( _get_row_3 , _set_row_3 , None , "<STR_LIT>" ) <EOL> x_axis = _row0 <EOL> right = _row0 <EOL> y_axis = _row1 <EOL> up = _row1 <EOL> z_axis = _row2 <EOL> forward = _row2 <EOL> translate = _row3 <EOL> def to_opengl ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _m [ : ] <EOL> def set ( self , row1 , row2 , row3 , row4 ) : <EOL> """<STR_LIT>""" <EOL> set_row_0 , set_row_1 , set_row_2 , set_row_3 = self . _setters <EOL> set_row_0 ( self , row1 ) <EOL> set_row_1 ( self , row2 ) <EOL> set_row_2 ( self , row3 ) <EOL> set_row_3 ( self , row4 ) <EOL> def get_row ( self , row_no ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _getters [ row_no ] ( self ) <EOL> except IndexError : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def from_iter ( cls , iterable ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> m . _m = list ( map ( float , iterable ) ) <EOL> if len ( m . _m ) != <NUM_LIT:16> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return m <EOL> @ classmethod <EOL> def clone ( cls , copy_Matrix44 ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> m . _m = copy_Matrix44 . _m [ : ] <EOL> return m <EOL> @ classmethod <EOL> def blank ( cls ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> m . _m = [ <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , ] <EOL> return m <EOL> @ classmethod <EOL> def identity ( cls ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> m . _m = [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return m <EOL> @ classmethod <EOL> def scale ( cls , scale_x , scale_y = None , scale_z = None ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_scale ( scale_x , scale_y , scale_z ) <EOL> @ classmethod <EOL> def translation ( cls , x , y , z ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_translation ( x , y , z ) <EOL> @ classmethod <EOL> def x_rotation ( cls , angle ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_x_rotation ( angle ) <EOL> @ classmethod <EOL> def y_rotation ( cls , angle ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_y_rotation ( angle ) <EOL> @ classmethod <EOL> def z_rotation ( cls , angle ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_z_rotation ( angle ) <EOL> @ classmethod <EOL> def rotation_about_axis ( cls , axis , angle ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_rotation_about_axis ( axis , angle ) <EOL> @ classmethod <EOL> def xyz_rotation ( cls , angle_x , angle_y , angle_z ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_xyz_rotation ( angle_x , angle_y , angle_z ) <EOL> @ classmethod <EOL> def perspective_projection ( cls , left , right , top , bottom , near , far ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_perspective_projection ( left , <EOL> right , <EOL> top , <EOL> bottom , <EOL> near , <EOL> far ) <EOL> @ classmethod <EOL> def perspective_projection_fov ( cls , fov , aspect , near , far ) : <EOL> """<STR_LIT>""" <EOL> m = cls . __new__ ( cls , object ) <EOL> return m . make_perspective_projection_fov ( fov , aspect , near , far ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> cols = [ list ( map ( format_number , col ) ) for col in self . columns ( ) ] <EOL> def decimal_pos ( n ) : <EOL> if '<STR_LIT:.>' in n : <EOL> return n . index ( '<STR_LIT:.>' ) <EOL> return len ( n ) <EOL> for col_no , col in enumerate ( cols [ : ] ) : <EOL> decimal = max ( decimal_pos ( format_number ( c ) ) for c in col ) <EOL> cols [ col_no ] = [ "<STR_LIT:U+0020>" * ( decimal - decimal_pos ( c ) ) + c for c in col ] <EOL> max_col_lengths = [ max ( len ( c ) for c in col ) for col in cols ] <EOL> rows = [ [ ] , [ ] , [ ] , [ ] ] <EOL> for row_no in range ( <NUM_LIT:4> ) : <EOL> for col_no in range ( <NUM_LIT:4> ) : <EOL> v = cols [ col_no ] [ row_no ] <EOL> rows [ row_no ] . append ( v . ljust ( max_col_lengths [ col_no ] ) ) <EOL> rows = [ "<STR_LIT:U+0020>" . join ( row ) . rstrip ( ) for row in rows ] <EOL> return "<STR_LIT:\n>" . join ( "<STR_LIT>" % row for row in rows ) <EOL> return str ( cols ) <EOL> def __repr__ ( self ) : <EOL> def format_row ( row ) : <EOL> return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( format_number ( value ) for value in row ) <EOL> return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( format_row ( row ) for row in self . rows ( ) ) <EOL> def __hash__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return hash ( tuple ( self . _m ) ) <EOL> def __setitem__ ( self , coord , value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> row , col = coord <EOL> self . _m [ row * <NUM_LIT:4> + col ] = <NUM_LIT:1.0> * value <EOL> except IndexError : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> except TypeError : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def __getitem__ ( self , coord ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> row , col = coord <EOL> return self . _m [ row * <NUM_LIT:4> + col ] <EOL> except IndexError : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> except TypeError : <EOL> raise TypeError ( "<STR_LIT>" "<STR_LIT>" ) <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return iter ( self . _m [ : ] ) <EOL> def __neg__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get_inverse ( ) <EOL> def __mul__ ( self , rhs ) : <EOL> """<STR_LIT>""" <EOL> m1_0 , m1_1 , m1_2 , m1_3 , m1_4 , m1_5 , m1_6 , m1_7 , m1_8 , m1_9 , m1_10 , m1_11 , m1_12 , m1_13 , m1_14 , m1_15 = self . _m <EOL> m2_0 , m2_1 , m2_2 , m2_3 , m2_4 , m2_5 , m2_6 , m2_7 , m2_8 , m2_9 , m2_10 , m2_11 , m2_12 , m2_13 , m2_14 , m2_15 = rhs . _m <EOL> retm = [ m2_0 * m1_0 + m2_1 * m1_4 + m2_2 * m1_8 + m2_3 * m1_12 , <EOL> m2_0 * m1_1 + m2_1 * m1_5 + m2_2 * m1_9 + m2_3 * m1_13 , <EOL> m2_0 * m1_2 + m2_1 * m1_6 + m2_2 * m1_10 + m2_3 * m1_14 , <EOL> m2_0 * m1_3 + m2_1 * m1_7 + m2_2 * m1_11 + m2_3 * m1_15 , <EOL> m2_4 * m1_0 + m2_5 * m1_4 + m2_6 * m1_8 + m2_7 * m1_12 , <EOL> m2_4 * m1_1 + m2_5 * m1_5 + m2_6 * m1_9 + m2_7 * m1_13 , <EOL> m2_4 * m1_2 + m2_5 * m1_6 + m2_6 * m1_10 + m2_7 * m1_14 , <EOL> m2_4 * m1_3 + m2_5 * m1_7 + m2_6 * m1_11 + m2_7 * m1_15 , <EOL> m2_8 * m1_0 + m2_9 * m1_4 + m2_10 * m1_8 + m2_11 * m1_12 , <EOL> m2_8 * m1_1 + m2_9 * m1_5 + m2_10 * m1_9 + m2_11 * m1_13 , <EOL> m2_8 * m1_2 + m2_9 * m1_6 + m2_10 * m1_10 + m2_11 * m1_14 , <EOL> m2_8 * m1_3 + m2_9 * m1_7 + m2_10 * m1_11 + m2_11 * m1_15 , <EOL> m2_12 * m1_0 + m2_13 * m1_4 + m2_14 * m1_8 + m2_15 * m1_12 , <EOL> m2_12 * m1_1 + m2_13 * m1_5 + m2_14 * m1_9 + m2_15 * m1_13 , <EOL> m2_12 * m1_2 + m2_13 * m1_6 + m2_14 * m1_10 + m2_15 * m1_14 , <EOL> m2_12 * m1_3 + m2_13 * m1_7 + m2_14 * m1_11 + m2_15 * m1_15 ] <EOL> ret = self . __new__ ( self . __class__ , object ) <EOL> ret . _m = retm <EOL> return ret <EOL> def __imul__ ( self , rhs ) : <EOL> """<STR_LIT>""" <EOL> m1_0 , m1_1 , m1_2 , m1_3 , m1_4 , m1_5 , m1_6 , m1_7 , m1_8 , m1_9 , m1_10 , m1_11 , m1_12 , m1_13 , m1_14 , m1_15 = self . _m <EOL> m2_0 , m2_1 , m2_2 , m2_3 , m2_4 , m2_5 , m2_6 , m2_7 , m2_8 , m2_9 , m2_10 , m2_11 , m2_12 , m2_13 , m2_14 , m2_15 = rhs . _m <EOL> self . _m = [ m2_0 * m1_0 + m2_1 * m1_4 + m2_2 * m1_8 + m2_3 * m1_12 , <EOL> m2_0 * m1_1 + m2_1 * m1_5 + m2_2 * m1_9 + m2_3 * m1_13 , <EOL> m2_0 * m1_2 + m2_1 * m1_6 + m2_2 * m1_10 + m2_3 * m1_14 , <EOL> m2_0 * m1_3 + m2_1 * m1_7 + m2_2 * m1_11 + m2_3 * m1_15 , <EOL> m2_4 * m1_0 + m2_5 * m1_4 + m2_6 * m1_8 + m2_7 * m1_12 , <EOL> m2_4 * m1_1 + m2_5 * m1_5 + m2_6 * m1_9 + m2_7 * m1_13 , <EOL> m2_4 * m1_2 + m2_5 * m1_6 + m2_6 * m1_10 + m2_7 * m1_14 , <EOL> m2_4 * m1_3 + m2_5 * m1_7 + m2_6 * m1_11 + m2_7 * m1_15 , <EOL> m2_8 * m1_0 + m2_9 * m1_4 + m2_10 * m1_8 + m2_11 * m1_12 , <EOL> m2_8 * m1_1 + m2_9 * m1_5 + m2_10 * m1_9 + m2_11 * m1_13 , <EOL> m2_8 * m1_2 + m2_9 * m1_6 + m2_10 * m1_10 + m2_11 * m1_14 , <EOL> m2_8 * m1_3 + m2_9 * m1_7 + m2_10 * m1_11 + m2_11 * m1_15 , <EOL> m2_12 * m1_0 + m2_13 * m1_4 + m2_14 * m1_8 + m2_15 * m1_12 , <EOL> m2_12 * m1_1 + m2_13 * m1_5 + m2_14 * m1_9 + m2_15 * m1_13 , <EOL> m2_12 * m1_2 + m2_13 * m1_6 + m2_14 * m1_10 + m2_15 * m1_14 , <EOL> m2_12 * m1_3 + m2_13 * m1_7 + m2_14 * m1_11 + m2_15 * m1_15 ] <EOL> return self <EOL> def fast_mul ( self , rhs ) : <EOL> """<STR_LIT>""" <EOL> m1_0 , m1_1 , m1_2 , m1_3 , m1_4 , m1_5 , m1_6 , m1_7 , m1_8 , m1_9 , m1_10 , m1_11 , m1_12 , m1_13 , m1_14 , m1_15 = self . _m <EOL> m2_0 , m2_1 , m2_2 , m2_3 , m2_4 , m2_5 , m2_6 , m2_7 , m2_8 , m2_9 , m2_10 , m2_11 , m2_12 , m2_13 , m2_14 , m2_15 = rhs . _m <EOL> self . _m = [ m2_0 * m1_0 + m2_1 * m1_4 + m2_2 * m1_8 , <EOL> m2_0 * m1_1 + m2_1 * m1_5 + m2_2 * m1_9 , <EOL> m2_0 * m1_2 + m2_1 * m1_6 + m2_2 * m1_10 , <EOL> <NUM_LIT:0.0> , <EOL> m2_4 * m1_0 + m2_5 * m1_4 + m2_6 * m1_8 , <EOL> m2_4 * m1_1 + m2_5 * m1_5 + m2_6 * m1_9 , <EOL> m2_4 * m1_2 + m2_5 * m1_6 + m2_6 * m1_10 , <EOL> <NUM_LIT:0.0> , <EOL> m2_8 * m1_0 + m2_9 * m1_4 + m2_10 * m1_8 , <EOL> m2_8 * m1_1 + m2_9 * m1_5 + m2_10 * m1_9 , <EOL> m2_8 * m1_2 + m2_9 * m1_6 + m2_10 * m1_10 , <EOL> <NUM_LIT:0.0> , <EOL> m2_12 * m1_0 + m2_13 * m1_4 + m2_14 * m1_8 + m1_12 , <EOL> m2_12 * m1_1 + m2_13 * m1_5 + m2_14 * m1_9 + m1_13 , <EOL> m2_12 * m1_2 + m2_13 * m1_6 + m2_14 * m1_10 + m1_14 , <EOL> <NUM_LIT:1.0> ] <EOL> return self <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . clone ( self ) <EOL> __copy__ = copy <EOL> def components ( self ) : <EOL> """<STR_LIT>""" <EOL> return iter ( self . _m [ : ] ) <EOL> def transposed_components ( self ) : <EOL> """<STR_LIT>""" <EOL> m00 , m01 , m02 , m03 , m10 , m11 , m12 , m13 , m20 , m21 , m22 , m23 , m30 , m31 , m32 , m33 = self . _m <EOL> return iter ( ( m00 , m10 , m20 , m30 , <EOL> m01 , m11 , m21 , m31 , <EOL> m02 , m12 , m22 , m32 , <EOL> m03 , m13 , m23 , m33 ) ) <EOL> def rows ( self ) : <EOL> """<STR_LIT>""" <EOL> m = self . _m <EOL> return iter ( ( tuple ( m [ <NUM_LIT:0> : <NUM_LIT:4> ] ) , <EOL> tuple ( m [ <NUM_LIT:4> : <NUM_LIT:8> ] ) , <EOL> tuple ( m [ <NUM_LIT:8> : <NUM_LIT:12> ] ) , <EOL> tuple ( m [ <NUM_LIT:12> : <NUM_LIT:16> ] ) ) ) <EOL> def columns ( self ) : <EOL> """<STR_LIT>""" <EOL> col = self . get_column <EOL> return iter ( ( col ( <NUM_LIT:0> ) , col ( <NUM_LIT:1> ) , col ( <NUM_LIT:2> ) , col ( <NUM_LIT:3> ) ) ) <EOL> def get_row_vec3 ( self , row_no ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> r = row_no * <NUM_LIT:4> <EOL> x , y , z = self . _m [ r : r + <NUM_LIT:3> ] <EOL> return Vector3 . from_floats ( x , y , z ) <EOL> except IndexError : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> def get_column ( self , col_no ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> m = self . _m <EOL> return ( m [ col_no ] , <EOL> m [ col_no + <NUM_LIT:4> ] , <EOL> m [ col_no + <NUM_LIT:8> ] , <EOL> m [ col_no + <NUM_LIT:12> ] ) <EOL> except IndexError : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> def set_row ( self , row_no , row ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _setters [ row_no ] ( self , row ) <EOL> except IndexError : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> def set_column ( self , col_no , col ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> col_iter = iter ( col ) <EOL> m = self . _m <EOL> a , b , c , d = col <EOL> m [ col_no ] = float ( a ) <EOL> m [ col_no + <NUM_LIT:4> ] = float ( b ) <EOL> m [ col_no + <NUM_LIT:8> ] = float ( c ) <EOL> m [ col_no + <NUM_LIT:12> ] = float ( d ) <EOL> except IndexError : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> def transform_vec3 ( self , v ) : <EOL> """<STR_LIT>""" <EOL> m = self . _m <EOL> x , y , z = v <EOL> return Vector3 . from_floats ( x * m [ <NUM_LIT:0> ] + y * m [ <NUM_LIT:4> ] + z * m [ <NUM_LIT:8> ] + m [ <NUM_LIT:12> ] , <EOL> x * m [ <NUM_LIT:1> ] + y * m [ <NUM_LIT:5> ] + z * m [ <NUM_LIT:9> ] + m [ <NUM_LIT> ] , <EOL> x * m [ <NUM_LIT:2> ] + y * m [ <NUM_LIT:6> ] + z * m [ <NUM_LIT:10> ] + m [ <NUM_LIT> ] ) <EOL> def transform ( self , v ) : <EOL> """<STR_LIT>""" <EOL> m = self . _m <EOL> x , y , z = v <EOL> return ( x * m [ <NUM_LIT:0> ] + y * m [ <NUM_LIT:4> ] + z * m [ <NUM_LIT:8> ] + m [ <NUM_LIT:12> ] , <EOL> x * m [ <NUM_LIT:1> ] + y * m [ <NUM_LIT:5> ] + z * m [ <NUM_LIT:9> ] + m [ <NUM_LIT> ] , <EOL> x * m [ <NUM_LIT:2> ] + y * m [ <NUM_LIT:6> ] + z * m [ <NUM_LIT:10> ] + m [ <NUM_LIT> ] ) <EOL> def transform4 ( self , v ) : <EOL> """<STR_LIT>""" <EOL> m = self . _m <EOL> x , y , z , w = v <EOL> return ( x * m [ <NUM_LIT:0> ] + y * m [ <NUM_LIT:4> ] + z * m [ <NUM_LIT:8> ] + w * m [ <NUM_LIT:12> ] , <EOL> x * m [ <NUM_LIT:1> ] + y * m [ <NUM_LIT:5> ] + z * m [ <NUM_LIT:9> ] + w * m [ <NUM_LIT> ] , <EOL> x * m [ <NUM_LIT:2> ] + y * m [ <NUM_LIT:6> ] + z * m [ <NUM_LIT:10> ] + w * m [ <NUM_LIT> ] ) <EOL> def transform_sequence ( self , points ) : <EOL> m_0 , m_1 , m_2 , m_3 , m_4 , m_5 , m_6 , m_7 , m_8 , m_9 , m_10 , m_11 , m_12 , m_13 , m_14 , m_15 = self . _m <EOL> return [ ( x * m_0 + y * m_4 + z * m_8 + m_12 , <EOL> x * m_1 + y * m_5 + z * m_9 + m_13 , <EOL> x * m_2 + y * m_6 + z * m_10 + m_14 ) <EOL> for x , y , z in points ] <EOL> def transform_sequence_vec3 ( self , points ) : <EOL> m_0 , m_1 , m_2 , m_3 , m_4 , m_5 , m_6 , m_7 , m_8 , m_9 , m_10 , m_11 , m_12 , m_13 , m_14 , m_15 = self . _m <EOL> return [ Vector3 . from_floats <EOL> ( x * m_0 + y * m_4 + z * m_8 + m_12 , <EOL> x * m_1 + y * m_5 + z * m_9 + m_13 , <EOL> x * m_2 + y * m_6 + z * m_10 + m_14 ) <EOL> for x , y , z in points ] <EOL> def iter_transform_vec3 ( self , points ) : <EOL> """<STR_LIT>""" <EOL> m_0 , m_1 , m_2 , m_3 , m_4 , m_5 , m_6 , m_7 , m_8 , m_9 , m_10 , m_11 , m_12 , m_13 , m_14 , m_15 = self . _m <EOL> for x , y , z in points : <EOL> yield Vector3 . from_floats ( x * m_0 + y * m_4 + z * m_8 + m_12 , <EOL> x * m_1 + y * m_5 + z * m_9 + m_13 , <EOL> x * m_2 + y * m_6 + z * m_10 + m_14 ) <EOL> def iter_transform ( self , points ) : <EOL> """<STR_LIT>""" <EOL> m_0 , m_1 , m_2 , m_3 , m_4 , m_5 , m_6 , m_7 , m_8 , m_9 , m_10 , m_11 , m_12 , m_13 , m_14 , m_15 = self . _m <EOL> for x , y , z in points : <EOL> yield ( x * m_0 + y * m_4 + z * m_8 + m_12 , <EOL> x * m_1 + y * m_5 + z * m_9 + m_13 , <EOL> x * m_2 + y * m_6 + z * m_10 + m_14 ) <EOL> iter_transform3 = iter_transform <EOL> def iter_transform4 ( self , points ) : <EOL> """<STR_LIT>""" <EOL> m_0 , m_1 , m_2 , m_3 , m_4 , m_5 , m_6 , m_7 , m_8 , m_9 , m_10 , m_11 , m_12 , m_13 , m_14 , m_15 = self . _m <EOL> for x , y , z , w in points : <EOL> yield ( x * m_0 + y * m_4 + z * m_8 + w * m_12 , <EOL> x * m_1 + y * m_5 + z * m_9 + w * m_13 , <EOL> x * m_2 + y * m_6 + z * m_10 + w * m_14 ) <EOL> def rotate_vec3 ( self , v ) : <EOL> """<STR_LIT>""" <EOL> m = self . _m <EOL> x , y , z = v <EOL> return Vector3 . from_floats ( x * m [ <NUM_LIT:0> ] + y * m [ <NUM_LIT:4> ] + z * m [ <NUM_LIT:8> ] , <EOL> x * m [ <NUM_LIT:1> ] + y * m [ <NUM_LIT:5> ] + z * m [ <NUM_LIT:9> ] , <EOL> x * m [ <NUM_LIT:2> ] + y * m [ <NUM_LIT:6> ] + z * m [ <NUM_LIT:10> ] ) <EOL> def rotate ( self , v ) : <EOL> """<STR_LIT>""" <EOL> m = self . _m <EOL> x , y , z = v <EOL> return ( x * m [ <NUM_LIT:0> ] + y * m [ <NUM_LIT:4> ] + z * m [ <NUM_LIT:8> ] , <EOL> x * m [ <NUM_LIT:1> ] + y * m [ <NUM_LIT:5> ] + z * m [ <NUM_LIT:9> ] , <EOL> x * m [ <NUM_LIT:2> ] + y * m [ <NUM_LIT:6> ] + z * m [ <NUM_LIT:10> ] ) <EOL> def inverse_transform ( self , v ) : <EOL> """<STR_LIT>""" <EOL> return self . get_inverse ( ) . transform ( v ) <EOL> def make_identity ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _m = [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return self <EOL> def make_copy ( self , other ) : <EOL> """<STR_LIT>""" <EOL> self . _m = other . _m [ : ] <EOL> return self <EOL> def make_scale ( self , scale_x , scale_y = None , scale_z = None ) : <EOL> """<STR_LIT>""" <EOL> if scale_y is None : <EOL> scale_y = scale_x <EOL> if scale_z is None : <EOL> scale_z = scale_x <EOL> self . _m = [ float ( scale_x ) , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , float ( scale_y ) , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , float ( scale_z ) , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return self <EOL> def make_translation ( self , x , y , z ) : <EOL> """<STR_LIT>""" <EOL> self . _m = [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <EOL> float ( x ) , float ( y ) , float ( z ) , <NUM_LIT:1.> ] <EOL> return self <EOL> def make_x_rotation ( self , angle ) : <EOL> """<STR_LIT>""" <EOL> cos_a = cos ( angle ) <EOL> sin_a = sin ( angle ) <EOL> self . _m = [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , cos_a , sin_a , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , - sin_a , cos_a , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return self <EOL> def make_y_rotation ( self , angle ) : <EOL> """<STR_LIT>""" <EOL> cos_a = cos ( angle ) <EOL> sin_a = sin ( angle ) <EOL> self . _m = [ cos_a , <NUM_LIT:0.> , - sin_a , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> sin_a , <NUM_LIT:0.> , cos_a , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return self <EOL> def make_z_rotation ( self , angle ) : <EOL> """<STR_LIT>""" <EOL> cos_a = cos ( angle ) <EOL> sin_a = sin ( angle ) <EOL> self . _m = [ cos_a , sin_a , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> - sin_a , cos_a , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return self <EOL> def make_rotation_about_axis ( self , axis , angle ) : <EOL> """<STR_LIT>""" <EOL> c = cos ( angle ) <EOL> s = sin ( angle ) <EOL> omc = <NUM_LIT:1.> - c <EOL> x , y , z = axis <EOL> self . _m = [ x * x * omc + c , y * x * omc + z * s , x * z * omc - y * s , <NUM_LIT:0.> , <EOL> x * y * omc - z * s , y * y * omc + c , y * z * omc + x * s , <NUM_LIT:0.> , <EOL> x * z * omc + y * s , y * z * omc - x * s , z * z * omc + c , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return self <EOL> def make_xyz_rotation ( self , angle_x , angle_y , angle_z ) : <EOL> """<STR_LIT>""" <EOL> cx = cos ( angle_x ) <EOL> sx = sin ( angle_x ) <EOL> cy = cos ( angle_y ) <EOL> sy = sin ( angle_y ) <EOL> cz = cos ( angle_z ) <EOL> sz = sin ( angle_z ) <EOL> sxsy = sx * sy <EOL> cxsy = cx * sy <EOL> self . _m = [ cy * cz , sxsy * cz + cx * sz , - cxsy * cz + sx * sz , <NUM_LIT:0.> , <EOL> - cy * sz , - sxsy * sz + cx * cz , cxsy * sz + sx * cz , <NUM_LIT:0.> , <EOL> sy , - sx * cy , cx * cy , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:1.> ] <EOL> return self <EOL> def make_perspective_projection ( self , left , right , top , bottom , near , far ) : <EOL> """<STR_LIT>""" <EOL> self . _m = [ ( <NUM_LIT> * near ) / ( right - left ) , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> <NUM_LIT:0.> , ( <NUM_LIT> * near ) / ( top - bottom ) , <NUM_LIT:0.> , <NUM_LIT:0.> , <EOL> ( right + left ) / ( right - left ) , ( top + bottom ) / ( top - bottom ) , - ( ( far + near ) / ( far - near ) ) , - <NUM_LIT:1.> , <EOL> <NUM_LIT:0.> , <NUM_LIT:0.> , - ( ( <NUM_LIT> * far * near ) / ( far - near ) ) , <NUM_LIT:0.> ] <EOL> return self <EOL> def make_perspective_projection_fov ( self , fov , aspect , near , far ) : <EOL> """<STR_LIT>""" <EOL> assert fov < pi , "<STR_LIT>" "<STR_LIT>" <EOL> range = near * tan ( fov / <NUM_LIT> ) ; <EOL> left = - range * aspect <EOL> right = range * aspect <EOL> bottom = - range <EOL> top = range <EOL> self . make_perspective_projection ( left , right , bottom , top , near , far ) <EOL> return self <EOL> def transpose ( self ) : <EOL> """<STR_LIT>""" <EOL> m00 , m01 , m02 , m03 , m10 , m11 , m12 , m13 , m20 , m21 , m22 , m23 , m30 , m31 , m32 , m33 = self . _m <EOL> self . _m = [ m00 , m10 , m20 , m30 , <EOL> m01 , m11 , m21 , m31 , <EOL> m02 , m12 , m22 , m32 , <EOL> m03 , m13 , m23 , m33 ] <EOL> def get_transpose ( self ) : <EOL> """<STR_LIT>""" <EOL> m00 , m01 , m02 , m03 , m10 , m11 , m12 , m13 , m20 , m21 , m22 , m23 , m30 , m31 , m32 , m33 = self . _m <EOL> ret = self . __new__ ( self . __class__ , object ) <EOL> ret . _m = [ m00 , m10 , m20 , m30 , <EOL> m01 , m11 , m21 , m31 , <EOL> m02 , m12 , m22 , m32 , <EOL> m03 , m13 , m23 , m33 ] <EOL> return ret <EOL> def get_inverse_rot_trans ( self ) : <EOL> """<STR_LIT>""" <EOL> ret = self . copy ( ) <EOL> m = ret . _m <EOL> i0 , i1 , i2 , i3 , i4 , i5 , i6 , i7 , i8 , i9 , i10 , i11 , i12 , i13 , i14 , i15 = self . _m <EOL> m [ <NUM_LIT:1> ] = i4 <EOL> m [ <NUM_LIT:4> ] = i1 <EOL> m [ <NUM_LIT:2> ] = i8 <EOL> m [ <NUM_LIT:8> ] = i2 <EOL> m [ <NUM_LIT:6> ] = i9 <EOL> m [ <NUM_LIT:9> ] = i6 <EOL> m [ <NUM_LIT:12> ] = ( m [ <NUM_LIT:0> ] * - i12 + <EOL> m [ <NUM_LIT:4> ] * - i13 + <EOL> m [ <NUM_LIT:8> ] * - i14 ) <EOL> m [ <NUM_LIT> ] = ( m [ <NUM_LIT:1> ] * - i12 + <EOL> m [ <NUM_LIT:5> ] * - i13 + <EOL> m [ <NUM_LIT:9> ] * - i14 ) <EOL> m [ <NUM_LIT> ] = ( m [ <NUM_LIT:2> ] * - i12 + <EOL> m [ <NUM_LIT:6> ] * - i13 + <EOL> m [ <NUM_LIT:10> ] * - i14 ) <EOL> return ret <EOL> def get_inverse ( self ) : <EOL> """<STR_LIT>""" <EOL> ret = self . __new__ ( self . __class__ , object ) <EOL> i = self . _m <EOL> i0 , i1 , i2 , i3 , i4 , i5 , i6 , i7 , i8 , i9 , i10 , i11 , i12 , i13 , i14 , i15 = i <EOL> negpos = [ <NUM_LIT:0.> , <NUM_LIT:0.> ] <EOL> temp = i0 * i5 * i10 <EOL> negpos [ temp > <NUM_LIT:0.> ] += temp <EOL> temp = i1 * i6 * i8 <EOL> negpos [ temp > <NUM_LIT:0.> ] += temp <EOL> temp = i2 * i4 * i9 <EOL> negpos [ temp > <NUM_LIT:0.> ] += temp <EOL> temp = - i2 * i5 * i8 <EOL> negpos [ temp > <NUM_LIT:0.> ] += temp <EOL> temp = - i1 * i4 * i10 <EOL> negpos [ temp > <NUM_LIT:0.> ] += temp <EOL> temp = - i0 * i6 * i9 <EOL> negpos [ temp > <NUM_LIT:0.> ] += temp <EOL> det_1 = negpos [ <NUM_LIT:0> ] + negpos [ <NUM_LIT:1> ] <EOL> if ( det_1 == <NUM_LIT:0.> ) or ( abs ( det_1 / ( negpos [ <NUM_LIT:1> ] - negpos [ <NUM_LIT:0> ] ) ) < ( <NUM_LIT> * <NUM_LIT> ) ) : <EOL> raise Matrix44Error ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> det_1 = <NUM_LIT:1.> / det_1 <EOL> ret . _m = [ ( i5 * i10 - i6 * i9 ) * det_1 , <EOL> - ( i1 * i10 - i2 * i9 ) * det_1 , <EOL> ( i1 * i6 - i2 * i5 ) * det_1 , <EOL> <NUM_LIT:0.0> , <EOL> - ( i4 * i10 - i6 * i8 ) * det_1 , <EOL> ( i0 * i10 - i2 * i8 ) * det_1 , <EOL> - ( i0 * i6 - i2 * i4 ) * det_1 , <EOL> <NUM_LIT:0.0> , <EOL> ( i4 * i9 - i5 * i8 ) * det_1 , <EOL> - ( i0 * i9 - i1 * i8 ) * det_1 , <EOL> ( i0 * i5 - i1 * i4 ) * det_1 , <EOL> <NUM_LIT:0.0> , <EOL> <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> ] <EOL> m = ret . _m <EOL> m [ <NUM_LIT:12> ] = - ( i12 * m [ <NUM_LIT:0> ] + i13 * m [ <NUM_LIT:4> ] + i14 * m [ <NUM_LIT:8> ] ) <EOL> m [ <NUM_LIT> ] = - ( i12 * m [ <NUM_LIT:1> ] + i13 * m [ <NUM_LIT:5> ] + i14 * m [ <NUM_LIT:9> ] ) <EOL> m [ <NUM_LIT> ] = - ( i12 * m [ <NUM_LIT:2> ] + i13 * m [ <NUM_LIT:6> ] + i14 * m [ <NUM_LIT:10> ] ) <EOL> return ret <EOL> def invert ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _m [ : ] = self . get_inverse ( ) . _m <EOL> def move ( self , forward = None , right = None , up = None ) : <EOL> """<STR_LIT>""" <EOL> if forward is not None : <EOL> self . translate = Vector3 ( self . translate ) + Vector3 ( self . forward ) * forward <EOL> if right is not None : <EOL> self . translate = Vector3 ( self . translate ) + Vector3 ( self . right ) * right <EOL> if up is not None : <EOL> self . translate = Vector3 ( self . translate ) + Vector3 ( self . up ) * up <EOL> def test ( ) : <EOL> m = Matrix44 . xyz_rotation ( radians ( <NUM_LIT> ) , radians ( <NUM_LIT:20> ) , radians ( <NUM_LIT:0> ) ) <EOL> print ( m . right ) <EOL> print ( m . right . as_vec3 ( ) ) <EOL> n = m . copy ( ) <EOL> r = Matrix44 . z_rotation ( radians ( <NUM_LIT:32> ) ) <EOL> m *= r <EOL> print ( m ) <EOL> n . fast_mul ( r ) <EOL> print ( n ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( m . get_transpose ( ) ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( m . get_row ( <NUM_LIT:2> ) ) <EOL> m . transpose ( ) <EOL> print ( m ) <EOL> print ( ) <EOL> m . translate = ( m . translate [ : <NUM_LIT:3> ] ) + Vector3 ( <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:30> ) <EOL> print ( m ) <EOL> print ( ) <EOL> v = ( <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ) <EOL> print ( v ) <EOL> vt = m . transform ( v ) <EOL> print ( vt ) <EOL> vit = m . get_inverse ( ) . transform ( vt ) <EOL> print ( vit ) <EOL> print ( m . inverse_transform ( vt ) ) <EOL> m [ <NUM_LIT:1> , <NUM_LIT:2> ] = <NUM_LIT> <EOL> print ( ) <EOL> print ( m . x_axis ) <EOL> print ( m . translate ) <EOL> m . translate = ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> print ( m ) <EOL> identity = Matrix44 ( ) <EOL> print ( identity ) <EOL> identity [ <NUM_LIT:3> , <NUM_LIT:1> ] = <NUM_LIT> <EOL> print ( identity ) <EOL> print ( eval ( repr ( identity ) ) ) <EOL> print ( m ) <EOL> print ( m . translate + Vector3 ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> print ( m ) <EOL> m . translate = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test ( ) </s>
