Exemplo n.º 1
0
    def create_perspective_projection_matrix_from_bounds_vector4(self):
        def apply_test(m, point, inside):
            p = matrix44.apply_to_vector(m, point)
            if p[3] == 0.:
                self.assertFalse(inside)

            # the values are now in clip space from (-1.,-1.,-1.) -> (1.,1.,1.)
            # to be inside = all(-1. < value < 1.)
            self.assertTrue(inside == (np.amax(np.absolute(p[:3])) <= 1.), (inside, point, p))

        m = matrix44.create_perspective_projection_matrix_from_bounds(-1.,1.,-1.,1.,1.,10.)

        # +Z
        apply_test(m, np.array((0.,0.,0.,1.)), False)
        apply_test(m, np.array((0.,0.,1.,1.)), False)
        # -Z but outside near, far
        apply_test(m, np.array((0.,0.,-.5,1.)), False)
        apply_test(m, np.array((0.,0.,-11.,1.)), False)
        apply_test(m, np.array((0.,0.,1.,1.)), False)
        # Valid
        apply_test(m, np.array((0.,0.,-10.,1.)), True)
        apply_test(m, np.array((0.,0.,-1.,1.)), True)
        apply_test(m, np.array((0.,0.,-2.,1.)), True)
        apply_test(m, np.array((0.,0.,-9.,1.)), True)
        apply_test(m, np.array((-1.,-1.,-1.,1.)), True)
        apply_test(m, np.array((-1.,-1.,-10.,1.)), True)
        apply_test(m, np.array((1.,1.,-1.,1.)), True)
        apply_test(m, np.array((1.,1.,-10.,1.)), True)
        # Outside left, right, top, bottom
        apply_test(m, np.array((1.1,1.1,-1.,1.)), False)
        apply_test(m, np.array((-1.1,-1.1,-1.,1.)), False)
        apply_test(m, np.array((1.1,1.1,-10.,1.)), False)
        apply_test(m, np.array((-1.1,-1.1,-10.,1.)), False)
Exemplo n.º 2
0
    def create_perspective_projection_matrix_from_bounds_vector4(self):
        def apply_test(m, point, inside):
            p = matrix44.apply_to_vector(m, point)
            if p[3] == 0.:
                self.assertFalse(inside)

            # the values are now in clip space from (-1.,-1.,-1.) -> (1.,1.,1.)
            # to be inside = all(-1. < value < 1.)
            self.assertTrue(inside == (np.amax(np.absolute(p[:3])) <= 1.),
                            (inside, point, p))

        m = matrix44.create_perspective_projection_matrix_from_bounds(
            -1., 1., -1., 1., 1., 10.)

        # +Z
        apply_test(m, np.array((0., 0., 0., 1.)), False)
        apply_test(m, np.array((0., 0., 1., 1.)), False)
        # -Z but outside near, far
        apply_test(m, np.array((0., 0., -.5, 1.)), False)
        apply_test(m, np.array((0., 0., -11., 1.)), False)
        apply_test(m, np.array((0., 0., 1., 1.)), False)
        # Valid
        apply_test(m, np.array((0., 0., -10., 1.)), True)
        apply_test(m, np.array((0., 0., -1., 1.)), True)
        apply_test(m, np.array((0., 0., -2., 1.)), True)
        apply_test(m, np.array((0., 0., -9., 1.)), True)
        apply_test(m, np.array((-1., -1., -1., 1.)), True)
        apply_test(m, np.array((-1., -1., -10., 1.)), True)
        apply_test(m, np.array((1., 1., -1., 1.)), True)
        apply_test(m, np.array((1., 1., -10., 1.)), True)
        # Outside left, right, top, bottom
        apply_test(m, np.array((1.1, 1.1, -1., 1.)), False)
        apply_test(m, np.array((-1.1, -1.1, -1., 1.)), False)
        apply_test(m, np.array((1.1, 1.1, -10., 1.)), False)
        apply_test(m, np.array((-1.1, -1.1, -10., 1.)), False)