Ejemplo n.º 1
0
    def translate(self, translation, inplace=True):
        tmatrix = self.get_translation_matrix(translation, False)
        matrix = trans.concatenate_matrices(self.matrix, tmatrix)

        if inplace:
            self.matrix = matrix
            return self

        else:
            return Matrix(matrix)
Ejemplo n.º 2
0
    def rotate(self, rotation, inplace=True):
        rmatrix = self.get_rotation_matrix(rotation, False)
        matrix = trans.concatenate_matrices(self.matrix, rmatrix)

        if inplace:
            self.matrix = matrix
            return self

        else:
            return Matrix(matrix)
Ejemplo n.º 3
0
    def multiply(self, matrix, inplace=False):

        matrix = self._ensure_matrix(matrix)
        matrix = trans.concatenate_matrices(self.matrix, matrix.matrix)

        if inplace:
            self.matrix = matrix
            return self

        else:
            matrix = Matrix(matrix)
            return matrix
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        '''
        Signature:
        *) Matrix
        *) translation, [rotation]
        *) (translation, rotation)
        *) tuple of 16 floats (row-major)
        *) list of 4 lists of 4 floats each (four rows)
        *) <no arguments> (unity matrix)
        '''
        translation = (0, 0, 0)
        rotation = (0, 0, 0)

        if args and isinstance(args[0], Matrix):
            self.matrix = args[0].matrix
            return

        if len(args) == 1:
            if len(args[0]) == 16:
                #TODO tuple of 16 floats (row-major)
                pass
            elif len(args[0]) == 4:
                self.matrix = args[0]
                return
            elif len(args[0]) == 3:
                translation = args[0]
            elif len(args[0]) == 2:
                translation, rotation = args[0]

        elif len(args) == 2:
            translation, rotation = args

        elif len(args) == 0:
            # Unity matrix
            pass

        else:
            raise Exception('invalid args: *args=%s, **kwargs=%s' %
                                    (args, kwargs))

        translation = kwargs.get('translation', translation)
        translation = trans.translation_matrix(translation)
        rotation = kwargs.get('rotation', rotation)
        rotation = self.get_rotation_matrix(rotation)

        self.matrix = trans.concatenate_matrices(translation, rotation)