コード例 #1
0
ファイル: glfLabels.py プロジェクト: lisarosalina/App
    def prepareBillboardAndNormalForAllTextLines(self):
        if self.billboard:
            m = self.GetMatrix()
            m = Numeric.reshape(m, (16, ))
            rot = glCleanRotMat(m)  #much faster than self.Decompose4x4(m)

            if self.includeCameraRotationInBillboard:
                # this permit billboarding even if the camera is not in the Z axis
                lCameraTransformation = self.viewer.currentCamera.GetMatrix()
                lCameraTransformation = Numeric.reshape(
                    lCameraTransformation, (16, ))
                lCameraRotation = glCleanRotMat(
                    lCameraTransformation
                )  #much faster than self.Decompose4x4(m)
                lCameraRotation = Numeric.transpose(lCameraRotation)
                rot = Numeric.dot(lCameraRotation, rot)

            rot = Numeric.reshape(rot, (16, ))
            self.billboardRotation = rot.astype('f')
        else:
            c = self.vertexSet.vertices.array
            n = self.vertexSet.normals.array
            lenn = len(n)
            if lenn > 0 and lenn != len(c):
                lMat = rotax.rotVectToVect(n[0], (0, 0, 1))
                self.orientation = [
                    lMat[0][0], lMat[0][1], lMat[0][2], lMat[0][3], lMat[1][0],
                    lMat[1][1], lMat[1][2], lMat[1][3], lMat[2][0], lMat[2][1],
                    lMat[2][2], lMat[2][3], lMat[3][0], lMat[3][1], lMat[3][2],
                    lMat[3][3]
                ]
コード例 #2
0
ファイル: Transformable.py プロジェクト: lisarosalina/App
    def ConcatRotation(self, matrix, redo=1):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Apply the rotation matrix to the object [matrix.shape==(16,)]"""
	
	if self.redirectXform: obj = self.redirectXform
	else: obj = self
        obj._modified = True
	GL.glPushMatrix()
	GL.glLoadIdentity()
	GL.glMultMatrixf(obj.Ri)#.astype('f'))
	GL.glMultMatrixf(matrix)
	GL.glMultMatrixf(obj.R)#.astype('f'))
	GL.glMultMatrixf(obj.rotation)

	m = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f')
        obj.rotation = glCleanRotMat(m).astype('f')
	obj.rotation.shape = (16, )
	GL.glPopMatrix()
        for o in self.copyXform: o.ConcatRotation(matrix)

        ## This code made rotation very slow because it would rebuild the
        ## master dpyList in cases where it was not needed
##         if redo and not self.immediateRendering:
##             vi = self.viewer
##             print 'faga'
##             vi.deleteOpenglList()
           
        vi = self.viewer
        if vi.activeClippingPlanes > 0 or vi.activeScissor > 0 or \
          (vi.currentObject!=vi.rootObject and not \
           vi.redirectTransformToRoot) and redo and \
           not self.immediateRendering:
            vi.deleteOpenglList()
コード例 #3
0
ファイル: Clip.py プロジェクト: lisarosalina/App
    def FrameTransform(self, camera=None):
        """Build the R an RI, the object's frame transformation and inverse"""

        GL.glPushMatrix()
        self.Si = Numeric.ones((3, ))
        GL.glLoadIdentity()
        m = Numeric.reshape(self.object.rotation, (4, 4))
        upd = Numeric.reshape(Numeric.transpose(m), (16, ))
        GL.glMultMatrixf(self.object.Ri)
        GL.glMultMatrixf(upd)
        GL.glMultMatrixf(self.object.MatrixRotInv)
        self.Si = self.Si * self.object.Si / (self.object.scale *
                                              self.object.MatrixScale)

        self.Ri = Numeric.array(GL.glGetDoublev(
            GL.GL_MODELVIEW_MATRIX)).astype('f')
        GL.glPopMatrix()
        #self.Ri = Numeric.reshape(glCleanRotMat(self.Ri), (4,4) )
        self.Ri = glCleanRotMat(self.Ri)
        self.R = Numeric.reshape(Numeric.transpose(self.Ri),
                                 (16, )).astype('f')
        self.Ri = Numeric.reshape(self.Ri, (16, )).astype('f')

        if self.redirectXform: self.redirectXform.FrameTransform(camera)
        for o in self.copyXform:
            o.FrameTransform(camera)
コード例 #4
0
    def ConcatRotationDir(self, matrix):
	"""Rotate a directional light"""

        self._modified = True
##  	matrix = Numeric.reshape( matrix, (4,4) )
##  	newdir = Numeric.dot( self.direction, matrix )
	GL.glPushMatrix()
	GL.glLoadIdentity()
	GL.glMultMatrixf(self.Ri)
	GL.glMultMatrixf(matrix)
	GL.glMultMatrixf(self.R)
        mat = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f')
        #mat = glCleanRotMat(mat).astype('f')
        n = glCleanRotMat(mat).astype('f')
	GL.glPopMatrix()
        #n = Numeric.reshape(mat, (4,4))
  	newdir = Numeric.dot( self.direction, n )
	self.Set(direction = newdir)
	for o in self.copyXform: o.ConcatRotationDir(matrix)
コード例 #5
0
ファイル: Transformable.py プロジェクト: lisarosalina/App
    def FrameTransform(self, camera=None):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Build the R an RI, the object's frame transformation and inverse"""

	GL.glPushMatrix()
	self.Si = Numeric.ones( (3, ) )
	GL.glLoadIdentity()
	if hasattr(self, 'parent'):
            if self.inheritXform:
                parent = self.parent
                while (parent):
                    m = Numeric.reshape( parent.rotation, (4,4) )
                    upd = Numeric.reshape( Numeric.transpose(m), (16, ) )
                    GL.glMultMatrixf(upd)                
                    GL.glMultMatrixf(parent.MatrixRotInv)                
                    self.Si = self.Si / parent.scale
                    self.Si = self.Si / parent.MatrixScale
                    # we have to test here because we need to take into
                    # account the first parent that does not inherit while
                    # building R and Ri
                    if not parent.inheritXform:
                        break
                    parent = parent.parent


	if camera:
	    m = Numeric.reshape( camera.rotation, (4,4) )
	    upd = Numeric.reshape( Numeric.transpose(m), (16, ) )
	    GL.glMultMatrixf(upd)
            self.Si = self.Si / camera.scale

	self.Ri = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f')
	GL.glPopMatrix()
	self.Ri = glCleanRotMat(self.Ri).astype('f')
        self.Ri.shape = (4,4)
	self.R = Numeric.reshape( Numeric.transpose(self.Ri), (16, ) ).astype('f')
	self.Ri.shape = (16, )

	if self.redirectXform: self.redirectXform.FrameTransform(camera)
	for o in self.copyXform: o.FrameTransform(camera)
コード例 #6
0
ファイル: Transformable.py プロジェクト: lisarosalina/App
 def Decompose4x4(self, matrix, cleanup=True):
     if __debug__:
      if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
     """ takes a matrix in shape (16,) in OpenGL form (sequential values go
     down columns) and decomposes it into its rotation (shape (16,)),
     translation (shape (3,)), and scale (shape (3,)) """
     m = matrix
     transl = Numeric.array((m[12], m[13], m[14]), 'f')
     scale0 = Numeric.sqrt(m[0]*m[0]+m[4]*m[4]+m[8]*m[8])
     scale1 = Numeric.sqrt(m[1]*m[1]+m[5]*m[5]+m[9]*m[9])
     scale2 = Numeric.sqrt(m[2]*m[2]+m[6]*m[6]+m[10]*m[10])
     scale = Numeric.array((scale0,scale1,scale2)).astype('f')
     mat = Numeric.reshape(m, (4,4))
     rot = Numeric.identity(4).astype('f')
     rot[:3,:3] = mat[:3,:3].astype('f')
     rot[:,0] = (rot[:,0]/scale0).astype('f')
     rot[:,1] = (rot[:,1]/scale1).astype('f')
     rot[:,2] = (rot[:,2]/scale2).astype('f')
     if cleanup:
         rot = glCleanRotMat(rot.ravel())
     rot.shape = (16,)
     #rot1 = rot.astype('f')
     return rot, transl, scale
コード例 #7
0
ファイル: Clip.py プロジェクト: MolecularFlipbook/FlipbookApp
    def FrameTransform(self, camera=None):
	"""Build the R an RI, the object's frame transformation and inverse"""

	GL.glPushMatrix()
	self.Si = Numeric.ones( (3, ) )
	GL.glLoadIdentity()
	m = Numeric.reshape( self.object.rotation, (4,4) )
	upd = Numeric.reshape( Numeric.transpose(m), (16, ) )
	GL.glMultMatrixf(self.object.Ri)
	GL.glMultMatrixf(upd)
        GL.glMultMatrixf(self.object.MatrixRotInv)
        self.Si = self.Si * self.object.Si / (self.object.scale *
                                              self.object.MatrixScale)

	self.Ri = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f')
	GL.glPopMatrix()
	#self.Ri = Numeric.reshape(glCleanRotMat(self.Ri), (4,4) )
        self.Ri = glCleanRotMat(self.Ri)
	self.R = Numeric.reshape( Numeric.transpose(self.Ri), (16, ) ).astype('f')
	self.Ri = Numeric.reshape(self.Ri, (16, )).astype('f')

	if self.redirectXform: self.redirectXform.FrameTransform(camera)
	for o in self.copyXform: o.FrameTransform(camera)