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


Python Camera.strafe方法代码示例

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


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

示例1: blocks

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

#.........这里部分代码省略.........
        self.makeFloor()
        #Transparent blocks!
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)



        for obj in self.objects:

            glPushMatrix()

            if obj.get_type() == "block":
                self.draw_block(obj)

            elif obj.get_type() == "key":
                self.draw_key(obj)

            glPopMatrix()
        glDisable(GL_BLEND)

        glFlush()


    def draw_block(self, obj):
                #Set the blocks shininess, ambient, diffuse, and specular reflections. The blocks are slightly transparent.
        color = obj.get_color()
        pos = obj.get_pos()
        #glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 75)
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0], color[1], color[2], 1])
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, 1])
        #glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .7])
        glTranslate(pos[0],pos[1],pos[2])
        glutSolidCube(2)

    def draw_key(self, obj):
        color = obj.get_color()
        pos = obj.get_pos()
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0], color[1], color[2], .7])
        glTranslate(pos[0],pos[1],pos[2])
                #glutSolidTorus(.05, .25, 3, 3)
        glutSolidCone(.1, 2.0, 30, 4)


    def keyPressed(self, key, x, y):
        '''Called when a key is pressed'''
        if key == 'a':
            self.camera.strafe(-.1)
        elif key == 'd':
            self.camera.strafe(.1)
        elif key == 'w':
            self.camera.walk(-.1)
        elif key == 's':
            self.camera.walk(.1)
        elif key == 'j':
            self.camera.rotate(0,3,0)
        elif key == 'l':
            self.camera.rotate(0,-3,0)
        elif key == 'i':
            self.camera.rotate(3,0,0)
        elif key == 'k':
            self.camera.rotate(-3,0,0)
        elif key == ' ':
            self.camera.height(.1)
        elif key == 'c':
            self.camera.height(-.1)
        self.display()

    def renderLightSource(self):
        '''Resets the light sources to the right position'''
        glLightfv(GL_LIGHT0, GL_POSITION, self.diffuse_pos1)
        glLightfv(GL_LIGHT2, GL_POSITION, self.diffuse_pos2)
        glLightfv(GL_LIGHT3, GL_POSITION, self.diffuse_pos2)
        glLightfv(GL_LIGHT4, GL_POSITION, self.diffuse_pos2)
        
    def makeFloor(self):
        '''Makes a floor of size size and places an image (texture) on it'''
        glEnable(GL_TEXTURE_2D)
        size = 50
        image = Image.open("OtherMods/checkerboard.bmp")
	
        ix = image.size[0]
        iy = image.size[1]
        image = image.tostring("raw", "RGBX", 0, -1)

        glPixelStorei(GL_UNPACK_ALIGNMENT,1)
        glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 0.0) ; glVertex(-size,-.5,-size)
        glTexCoord2f(1.0, 0.0) ; glVertex(size,-.5,-size)
        glTexCoord2f(1.0, 1.0) ; glVertex(size,-.5,size)
        glTexCoord2f(0.0, 1.0) ; glVertex(-size,-.5,size)
        glEnd()
        glDisable(GL_TEXTURE_2D)
开发者ID:aapope,项目名称:OpenGLMaze,代码行数:104,代码来源:RenderWorld.py


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