Exemplo n.º 1
0
    def get_translation_matrix(self, translation, wrap=True):
        matrix = trans.translation_matrix(translation)

        if wrap:
            return Matrix(matrix)
        else:
            return matrix
Exemplo n.º 2
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)