Ejemplo n.º 1
0
 def test_scale_transform(self):
     T = matrix.scale_transform(1, 2, 3)
     R = np.array([
         [1, 0, 0, 0],
         [0, 2, 0, 0],
         [0, 0, 3, 0],
         [0, 0, 0, 1]
         ])
     self.assertTrue(np.array_equal(T, R))
Ejemplo n.º 2
0
    def reset_view(self):
        self.viewport = (
            0,
            0,
            int(builtins.width * builtins.pixel_x_density),
            int(builtins.height * builtins.pixel_y_density),
        )
        self.texture_viewport = (
            0,
            0,
            builtins.width,
            builtins.height,
        )

        gloo.set_viewport(*self.viewport)  # pylint: disable=no-member

        cz = (builtins.height / 2) / math.tan(math.radians(30))
        self.projection_matrix = matrix.perspective_matrix(
            math.radians(60),
            builtins.width / builtins.height,
            0.1 * cz,
            10 * cz
        )
        self.modelview_matrix = matrix.translation_matrix(-builtins.width / 2,
                                                          builtins.height / 2,
                                                          -cz)
        self.modelview_matrix = self.modelview_matrix.dot(
            matrix.scale_transform(1, -1, 1))

        self.transform_matrix = np.identity(4)

        self.default_prog['modelview'] = self.modelview_matrix.T.flatten()
        self.default_prog['projection'] = self.projection_matrix.T.flatten()

        self.texture_prog['modelview'] = self.modelview_matrix.T.flatten()
        self.texture_prog['projection'] = self.projection_matrix.T.flatten()

        self.line_prog = Program(src_line.vert, src_line.frag)

        self.line_prog['modelview'] = self.modelview_matrix.T.flatten()
        self.line_prog['projection'] = self.projection_matrix.T.flatten()
        self.line_prog["height"] = builtins.height

        self.fbuffer_tex_front = Texture2D(
            (builtins.height, builtins.width, 3))
        self.fbuffer_tex_back = Texture2D((builtins.height, builtins.width, 3))

        for buf in [self.fbuffer_tex_front, self.fbuffer_tex_back]:
            self.fbuffer.color_buffer = buf
            with self.fbuffer:
                self.clear()
Ejemplo n.º 3
0
    def scale(self, sx, sy=None, sz=None):
        """Scale the shape by the given factor.

        :param sx: scale factor along the x-axis.
        :type sx: float

        :param sy: scale factor along the y-axis (defaults to None)
        :type sy: float

        :param sz: scale factor along the z-axis (defaults to None)
        :type sz: float

        :returns: The transformation matrix used to appy the
            transformation.
        :rtype: np.ndarray

        """
        if sy is None and sz is None:
            sy = sx
            sz = sx
        elif sz is None:
            sz = 1
        tmat = matrix.scale_transform(sx, sy, sz)
        return tmat