当前位置: 首页>>代码示例>>Python>>正文


Python Vector.toTuple方法代码示例

本文整理汇总了Python中Vector.Vector.toTuple方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.toTuple方法的具体用法?Python Vector.toTuple怎么用?Python Vector.toTuple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector.Vector的用法示例。


在下文中一共展示了Vector.toTuple方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OpenGLComponent

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import toTuple [as 别名]

#.........这里部分代码省略.........
        while not self.dataReady("callback"):  yield 1
        self.identifier = self.recv("callback")
        
        while 1:
            yield 1
            
            while self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
                    self.send(cmsg, "signal")
                    return
                   
            self.frametime = float(self.clock.tick())/1000.0
            self.handleMovement()
            self.handleEvents()
            self.applyTransforms()
            # frame function from derived objects
            self.frame()
            while not self.anyReady():
                self.pause()
                yield 1

                                          
    def applyTransforms(self):
        """ Use the objects translation/rotation/scaling values to generate a new transformation Matrix if changes have happened. """
        # generate new transformation matrix if needed
        if self.oldscaling != self.scaling or self.oldrot != self.rotation or self.oldpos != self.position:
            self.transform = Transform()
            self.transform.applyScaling(self.scaling)
            self.transform.applyRotation(self.rotation)
            self.transform.applyTranslation(self.position)

            if self.oldscaling != self.scaling:
                self.send(self.scaling.toTuple(), "scaling")
                self.oldscaling = self.scaling.copy()

            if self.oldrot != self.rotation:
                self.send(self.rotation.toTuple(), "rotation")
                self.oldrot = self.rotation.copy()

            if self.oldpos != self.position:
                self.send(self.position.toTuple(), "position")
                self.oldpos = self.position.copy()
                
            # send new transform to display service
            transform_update = { "TRANSFORM_UPDATE": True,
                                 "objectid": id(self),
                                 "transform": self.transform
                               }
            self.send(transform_update, "display_signal")


    def handleMovement(self):
        """ Handle movement commands received by corresponding inboxes. """
        while self.dataReady("position"):
            pos = self.recv("position")
            self.position = Vector(*pos)
        
        while self.dataReady("rotation"):
            rot = self.recv("rotation")
            self.rotation = Vector(*rot)
            
        while self.dataReady("scaling"):
            scaling = self.recv("scaling")
            self.scaling = Vector(*scaling)
            
开发者ID:3rdandUrban-dev,项目名称:Nuxleus,代码行数:69,代码来源:OpenGLComponent.py

示例2: Container

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import toTuple [as 别名]

#.........这里部分代码省略.........
        self.scacomms = {}
        
        
        contents = argd.get("contents", None)
        if contents is not None:
            for (comp, params) in contents.items():
                self.addElement(comp, **params)


    def main(self):
        while 1:

            while self.dataReady("control"):
                cmsg = self.recv("control")
                if isinstance(cmsg, producerFinished) or isinstance(cmsg, shutdownMicroprocess):
                    self.send(cmsg, "signal")
                    return

            self.handleMovement()
            self.applyTransforms()
            yield 1

           
    def handleMovement(self):
        """ Handle movement commands received by corresponding inboxes. """
        while self.dataReady("position"):
            pos = self.recv("position")
            self.position = Vector(*pos)
        
        while self.dataReady("rotation"):
            rot = self.recv("rotation")
            self.rotation = Vector(*rot)
            
        while self.dataReady("scaling"):
            scaling = self.recv("scaling")
            self.scaling = Vector(*scaling)
            
        while self.dataReady("rel_position"):
            self.position += Vector(*self.recv("rel_position"))
            
        while self.dataReady("rel_rotation"):
            self.rotation += Vector(*self.recv("rel_rotation"))
            
        while self.dataReady("rel_scaling"):
            self.scaling = Vector(*self.recv("rel_scaling"))


    def applyTransforms(self):
        """ Use the objects translation/rotation/scaling values to generate a new transformation Matrix if changes have happened. """
        # generate new transformation matrix if needed
        if self.oldscaling != self.scaling or self.oldrot != self.rotation or self.oldpos != self.position:
            self.transform = Transform()
            self.transform.applyScaling(self.scaling)
            self.transform.applyRotation(self.rotation)
            self.transform.applyTranslation(self.position)

            self.oldpos = self.position.copy()
            self.oldrot = self.rotation.copy()
            self.oldscaling = self.scaling.copy()
            
            self.rearangeContents()


    def rearangeContents(self):
        for comp in self.components:
            trans = self.transform.transformVector(self.rel_positions[comp])
            self.send(trans.toTuple(), self.poscomms[comp])
#                self.send(self.rotation.toTuple(), self.rotcomms[comp])
            self.send(self.scaling.toTuple(), self.scacomms[comp])

            
    def addElement(self, comp, position=(0,0,0), rotation=(0,0,0), scaling=(1,1,1) ):
        self.components.append(comp)
        self.rel_positions[comp] = Vector( *position )
        self.rel_rotations[comp] = Vector( *rotation )
        self.rel_scalings[comp] = Vector( *scaling )
        
        self.poscomms[comp] = self.addOutbox("pos")
        self.link( (self, self.poscomms[comp]), (comp, "position") )
#        self.rotcomms[comp] = self.addOutbox("rot")
#        self.link( (self, self.rotcomms[comp]), (comp, "rotation") )
        self.scacomms[comp] = self.addOutbox("sca")
        self.link( (self, self.scacomms[comp]), (comp, "scaling") )

        self.rearangeContents()
        
        
    def removeElement(self, comp):
        self.components.remove(comp)
        self.rel_positions.pop(comp)
        self.rel_rotations.pop(comp)
        self.rel_scalings.pop(comp)
        
        # todo: unlink
        
        self.poscomms.pop(comp)
        self.rotcomms.pop(comp)
        self.scacomms.pop(comp)

        self.rearangeContents()
开发者ID:casibbald,项目名称:kamaelia,代码行数:104,代码来源:Container.py

示例3: OpenGLDisplay

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import toTuple [as 别名]

#.........这里部分代码省略.........
            self.link((self,callbackcomms), callbackservice)

            # get and link eventrequest comms
            eventrequestcomms = self.addOutbox("eventrequests")
            self.link((self,eventrequestcomms), eventrequestservice)
            self.wrapper_requestcomms[id(surface)] = eventrequestcomms

            # find corresponding pow2surface
            pow2surface = self.pygame_pow2surfaces[id(surface)]

            #determine texture coordinate lengths
            tex_w = float(surface.get_width())/float(pow2surface.get_width())
            tex_h = float(surface.get_height())/float(pow2surface.get_height())

            # generate response
            response = { "texname": self.pygame_texnames[id(surface)],
                         "texsize": (tex_w, tex_h),
                         "size": self.pygame_sizes[id(surface)] }
            try:
                response["eventservice"] = self.eventservices[id(surface)]
                response["eventswanted"] = self.eventswanted[id(surface)]
            except KeyError:
                response["eventservice"] = None
                response["eventswanted"] = None
            # send response
            self.send(response, callbackcomms)
    

    def setProjection(self):
        """ Sets projection matrix. """
        glMatrixMode(GL_PROJECTION)
        gluPerspective(self.perspectiveAngle, self.aspectRatio, self.nearPlaneDist, self.farPlaneDist)
        # apply viewer transforms
        gluLookAt( *(self.viewerposition.toTuple() + self.lookat.toTuple() + self.up.toTuple() ) )

        
    def doPicking(self, pos):
        """\
        Uses OpenGL picking to determine objects that have been hit by mouse pointer.
        see e.g. OpenGL Redbook
        """
        # object picking
        glSelectBuffer(512)
        glRenderMode(GL_SELECT)

        # prepare matrices
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        gluPickMatrix(pos[0], self.height-pos[1], 1, 1)
        self.setProjection()

        # "draw" objects in select mode
        glInitNames()
        glPushName(0)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        for obj in self.ogl_objects:
            try:
                glLoadMatrixf(self.ogl_transforms[obj].getMatrix())
                glLoadName(self.ogl_names[obj])
                glCallList(self.ogl_displaylists[obj])
            except KeyError: pass
        glPopMatrix()

        # restore matrices
开发者ID:3rdandUrban-dev,项目名称:Nuxleus,代码行数:70,代码来源:OpenGLDisplay.py


注:本文中的Vector.Vector.toTuple方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。