Esempio n. 1
0
    def test_matrix(self):
        """Test that a texture matrix can produce a proper scale/offset"""
        map = self.atlasManager.add(NumpyAdapter(zeros((64, 64, 4), 'B')))
        matrix = map.matrix()
        assert matrix is not None
        bottom_left = dot(array([0, 0, 0, 1], 'f'), matrix)
        assert allclose(bottom_left, [0, 0, 0, 1]), bottom_left
        top_right = dot(array([1, 1, 0, 1], 'f'), matrix)
        assert allclose(top_right, [.25, .25, 0, 1]), top_right

        map = self.atlasManager.add(NumpyAdapter(zeros((64, 64, 4), 'B')))
        matrix = map.matrix()
        assert matrix is not None
        bottom_left = dot(array([0, 0, 0, 1], 'f'), matrix)
        assert allclose(bottom_left, [.25, 0, 0, 1]), (bottom_left, matrix)
        top_right = dot(array([1, 1, 0, 1], 'f'), matrix)
        assert allclose(top_right, [.5, .25, 0, 1]), (top_right, matrix)

        set = dot(array([[0, 0, 0, 1], [1, 1, 0, 1]], 'f'), matrix)
        assert allclose(set, [[.25, 0, 0, 1], [.5, .25, 0, 1]]), (set, matrix)
Esempio n. 2
0
    def _partialSphere(cls, latsteps, longsteps):
        """Create a partial-sphere data-set for latsteps and longsteps
        
        returns (coordarray, indexarray)
        """
        ystep = len(longsteps)
        zstep = len(latsteps)
        xstep = 1
        coords = zeros((zstep, ystep, 8), 'f')
        coords[:, :, 0] = sin(longsteps)
        coords[:, :, 1] = cos(latsteps).reshape((-1, 1))
        coords[:, :, 2] = cos(longsteps)
        coords[:, :, 3] = longsteps / (2 * pi)
        coords[:, :, 4] = latsteps.reshape((-1, 1)) / pi

        # now scale by sin of y's
        scale = sin(latsteps).reshape((-1, 1))
        coords[:, :, 0] *= scale
        coords[:, :, 2] *= scale
        coords[:, :, 5:8] = coords[:, :, 0:3]  # normals

        indices = mesh_indices(zstep, ystep)

        # now optimize/simplify the data-set...
        new_indices = []

        for (i, iSet) in enumerate(indices):
            angle = latsteps[i]
            nextAngle = latsteps[i + 1]
            if allclose(angle % (pi * 2), 0):
                iSet = iSet.reshape((-1, 3))[::2]
            elif allclose(nextAngle % (pi), 0):
                iSet = iSet.reshape((-1, 3))[1::2]
            else:
                iSet = iSet.reshape((-1, 3))
            new_indices.append(iSet)
        indices = concatenate(new_indices)
        return coords.reshape((-1, 8)), indices.reshape((-1, ))
Esempio n. 3
0
 def transform( self, mode=None, translate=1, scale=1, rotate=1 ):
     ''' Perform the actual alteration of the current matrix '''
     if translate and any(self.translation):
         x,y = self.translation
         glTranslatef(x,y,0)
     if (rotate or scale) and any(self.center):
         cx,cy = self.center
         glTranslatef(cx,cy,0)
     if rotate and self.rotation:
         glRotatef( self.rotation * RADTODEG, 0,0,1)
     if scale and not allclose(self.scale, NULLSCALE):
         sx,sy = self.scale
         glScalef( sx,sy,1.0 )
     if (rotate or scale) and any(self.center):
         glTranslatef( -cx,-cy,0)
Esempio n. 4
0
 def transform( self, mode=None, translate=1, scale=1, rotate=1 ):
     ''' Perform the actual alteration of the current matrix '''
     if translate and any(self.translation):
         x,y = self.translation
         glTranslatef(x,y,0)
     if (rotate or scale) and any(self.center):
         cx,cy = self.center
         glTranslatef(cx,cy,0)
     if rotate and self.rotation:
         glRotatef( self.rotation * RADTODEG, 0,0,1)
     if scale and not allclose(self.scale, NULLSCALE):
         sx,sy = self.scale
         glScalef( sx,sy,1.0 )
     if (rotate or scale) and any(self.center):
         glTranslatef( -cx,-cy,0)
Esempio n. 5
0
 def test_from_config(self):
     cfg = ConfigParser.ConfigParser()
     cfg.read(sample_ini)
     cd = ContextDefinition.fromConfig(cfg)
     assert arrays.allclose(cd.size, [600, 600]), cd.size
     assert cd.title == "Test Context", cd.title
     assert cd.doubleBuffer == False, cd.doubleBuffer
     assert cd.depthBuffer == 16, cd.depthBuffer
     assert cd.accumulationBuffer == 16
     assert cd.stencilBuffer == 16
     assert cd.rgb == False
     assert cd.alpha == False
     assert cd.multisampleBuffer == 16
     assert cd.multisampleSamples == 4
     assert cd.stereo == 23