def trRasterPos3f(self, x, y, z): """ Replacement for glRastePos3f() which avoids the problem with invalid raster pos. """ if self.CurrentTile < 0: # not doing tile rendering right now. Let OpenGL do this. GL.glRasterPos3f(float(x), float(y), float(z)) else: # Get modelview, projection and viewport modelview = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) proj = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = [0, 0, self.CurrentTileWidth, self.CurrentTileHeight]
def trRasterPos3f(self, x, y, z): """ Replacement for glRastePos3f() which avoids the problem with invalid raster pos. """ if self.CurrentTile<0: # not doing tile rendering right now. Let OpenGL do this. GL.glRasterPos3f(float(x), float(y), float(z)) else: # Get modelview, projection and viewport modelview = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) proj = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = [0, 0, self.CurrentTileWidth, self.CurrentTileHeight]
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()
def GetMatrix(self, root=None, instance=None, scale=True, transpose=True): if __debug__: if hasattr(DejaVu, 'functionName'): DejaVu.functionName() """Returns the matrix by which this object is transformed scale = False: returns the rotation and translation. no scaling info included Used to save the transformed geom --> coords --> new pdb file instance is a list of integer instance indices for all parents """ if root is None: root = self.viewer.rootObject if instance is None: instance = [0] p = self.parent while p: instance.append(0) p = p.parent GL.glPushMatrix() GL.glLoadIdentity() #print 'GetMatrix', instance self.BuildMat(self, root, scale, instance) #GL.glMultMatrixf(self.instanceMatricesFortran[instanceList[0]]]) m = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f') GL.glPopMatrix() if Numeric.alltrue(m==Numeric.zeros(16).astype('f')): # this happens when Pmv has no GUI m = Numeric.identity(4) if transpose: return Numeric.transpose(Numeric.reshape(m, (4,4))) else: return Numeric.reshape(m, (4,4))
def _loopGeomsRec(self, obj): """ recursive method """ GL.glPushMatrix() # we discard root object transformation: if obj is not obj.viewer.rootObject: if hasattr(obj, 'MakeMat'): obj.MakeMat() obj.VRML2CreatedPROTOForThisGeom = 0 # flag used in vrml2 doit() for i in range(len(obj.instanceMatricesFortran)): GL.glPushMatrix() GL.glMultMatrixf(obj.instanceMatricesFortran[i]) obj.instanceMatricesFortranIndex = i # flag used in stl and vrml2 doit() matrix = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) self.NodeRepr(obj, matrix) for child in obj.children: if child.visible: self._loopGeomsRec(child) GL.glPopMatrix() GL.glPopMatrix() # Restore the matrix del obj.instanceMatricesFortranIndex # clean up object del obj.VRML2CreatedPROTOForThisGeom
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)
def ConcatRotationRelative(self, matrix): if __debug__: if hasattr(DejaVu, 'functionName'): DejaVu.functionName() """Apply the rotation matrix to the object (matrix.shape ==(16,) Unlike ConcatRotation you just concatenate the rotation of the object without considering Ri and R """ self._modified = True obj = self GL.glPushMatrix() GL.glLoadIdentity() ## GL.glMultMatrixf(obj.rotation) GL.glMultMatrixf(matrix) GL.glMultMatrixf(obj.rotation) m = Numeric.array(GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)).astype('f') obj.rotation = m.astype('f') obj.rotation.shape = (16, ) GL.glPopMatrix()
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)
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)
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)
def drawOne3dTextLine(self, textLine, index): c = self.vertexSet.vertices.array n = self.vertexSet.normals.array lenn = len(n) try: GL.glPushMatrix() GL.glTranslatef( float(c[index][0]), float(c[index][1]), float(c[index][2]), ) if self.billboard: GL.glMultMatrixf(self.billboardRotation) elif lenn == len(c): lMat = rotax.rotVectToVect(n[index], (0, 0, 1)) lMat = [ 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] ] GL.glMultMatrixf(lMat) elif lenn > 0: GL.glMultMatrixf(self.orientation) GL.glTranslatef( float(self.fontTranslation[0]), float(self.fontTranslation[1]), float(self.fontTranslation[2]), ) GL.glRotatef( float(self.fontRotateAngles[2]), 0., 0., 1., ) GL.glRotatef( float(self.fontRotateAngles[1]), 0., 1., 0., ) GL.glRotatef( float(self.fontRotateAngles[0]), 1., 0., 0., ) if self.fontTypeIsVector: GL.glScalef(float(self.fontScales[0]), float(self.fontScales[1]), float(self.fontScales[2])) if textLine is not None: self.fontStyleDict[self.fontStyle](textLine) else: GL.glScalef( float(self.fontScales[0]) * 40, float(self.fontScales[1]) * 40, 0) # to be the same size as vector fonts if textLine is not None: glf.glfDrawBString(textLine) finally: if textLine is None: lMatrix = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) GL.glPopMatrix() return lMatrix else: GL.glPopMatrix()