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


Python Camera.rotate方法代码示例

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


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

示例1: blocks

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import rotate [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

示例2: __init__

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import rotate [as 别名]
class RenderCube:
    '''This is the class that renders a rainbow cube
    Camera angles are handled by Camera.py.
    '''
    WINDOW_WIDTH = 700
    WINDOW_HEIGHT = 700
    MAP_SIZE =100

    def __init__(self):
        '''Sets up camera, modes, lighting, sounds, and objects.'''
        self.set_up_graphics()
        self.makeLights()
        self.camera = Camera(0,0,5)
        self.verts=self.GenArray()
        self.colors=self.GenArray('color')

        glClearColor(1,1,1,0)

        glutIdleFunc(self.display)
        glutDisplayFunc(self.display)

        glutIgnoreKeyRepeat(GLUT_KEY_REPEAT_OFF)
        glutKeyboardFunc(self.keyPressed)
        glutKeyboardUpFunc(self.keyUp)

        glutSetCursor(GLUT_CURSOR_NONE)
        glutPassiveMotionFunc(self.mouseMove)

        glutMainLoop()

    def set_up_graphics(self):
        '''Sets up OpenGL to provide double buffering, RGB coloring,
        depth testing, the correct window size, and a title.'''
        glutInit()
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
        glutInitWindowSize(self.WINDOW_WIDTH, self.WINDOW_HEIGHT)
        glutCreateWindow('RainbowCube!')

        glMatrixMode(GL_PROJECTION)
        gluPerspective(45,1,.15,100)
        glMatrixMode(GL_MODELVIEW)

        glEnable(GL_DEPTH_TEST)

    def makeLights(self):
        '''Sets up the light sources and their positions. We have an
        ambient light and two sets of specular/diffuse lights.'''
        self.diffuse_pos1 = (50,5,0,1)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, (.5, .5, .5, 1))
        glLightfv(GL_LIGHT0, GL_POSITION, self.diffuse_pos1)

        glLightfv(GL_LIGHT1, GL_AMBIENT, (.2, .2, .2, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, (0, 0, 1, 0))

        glLightfv(GL_LIGHT2, GL_SPECULAR, (.8, .8, .8, 1))
        glLightfv(GL_LIGHT2, GL_POSITION, self.diffuse_pos1)

        self.diffuse_pos2 = (0,1,0,1)
        glLightfv(GL_LIGHT3, GL_DIFFUSE, (.5, .5, .5, 1))
        glLightfv(GL_LIGHT3, GL_POSITION, self.diffuse_pos2)
        glLightfv(GL_LIGHT4, GL_SPECULAR, (.8, .8, .8, 1))
        glLightfv(GL_LIGHT4, GL_POSITION, self.diffuse_pos2)

        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHT1)
        glEnable(GL_LIGHT2)

    def display(self, x=0, y=0):
        '''Called for every refresh; redraws the cube at current position
        based on the camera angle.'''
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()

        self.camera.move()
        self.camera.renderCamera()
        self.renderLightSource()
        glPushMatrix()
        # Set the object shininess, ambient, diffuse, and
        # specular reflections.
        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 75)
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, 1])
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .8])

        glTranslate(0,0,0)
        self.MakeCube()
        glPopMatrix()
        glutSwapBuffers()

    def mouseMove(self, x, y):
        '''Called when the mouse is moved.'''
        factor = 2
        
        tmp_x = (self.camera.mouse_x - x)/factor
        tmp_y = (self.camera.mouse_y - y)/factor
        if tmp_x > self.camera.ROTATE:
            tmp_x = self.camera.ROTATE
        self.camera.rotate(0, tmp_x, 0)
        x = self.WINDOW_WIDTH/2
        y = self.WINDOW_HEIGHT/2
#.........这里部分代码省略.........
开发者ID:swilson11235,项目名称:RainbowCube,代码行数:103,代码来源:RenderCube.py

示例3: __init__

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

#.........这里部分代码省略.........
        if self.last_time+f_rate <= time.time():
            self.last_time = time.time()

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

            glLoadIdentity()        
            glDisable(GL_LIGHTING)
            self.camera.renderRotateCamera()
            glTranslate(-self.skybox.x/2, -1-self.camera.pos_Y, -self.skybox.z/2)
            glCallList(self.sky_index)

            if abs(self.curr_time - time.time()) >= 1:
                print "FPS:", self.count
                print time.time()
                self.count = 0
                self.curr_time = time.time()
            else:
                self.count+=1
        
            if self.need_lists:
                self.create_render_newlist()

            #self.lock.acquire()
                

            glLoadIdentity()
        #Put camera and light in the correct position
            self.camera.move()
            self.camera.renderRotateCamera()
            self.camera.renderTranslateCamera()

            glEnable(GL_LIGHTING)
            glEnable(GL_LIGHT0)
            glEnable(GL_LIGHT1)
            self.renderLightSource()
            
            for index in self.land_index_list:
            #print "INDEX:", index
                glCallList(index)

            for index in self.water_index_list:
                glCallList(index)

            for index in self.building_index_list:
                glCallList(index[0])
            
            
            glDisable(GL_TEXTURE_2D)
            glutSwapBuffers()

    def renderLightSource(self):
        '''Resets the light sources to the right position.'''
        if self.camera.pos_Y <= self.convert.sea_level:
            glLightfv(GL_LIGHT0, GL_DIFFUSE, (0, .2, 1, 1))
        else:
            glLightfv(GL_LIGHT0, GL_DIFFUSE, (1, 1, 1, 1))
        glLightfv(GL_LIGHT0, GL_POSITION, self.diffuse_pos1)

       
    def mouseMove(self, x, y):
        '''Called when the mouse is moved.'''
        factor = 3
        
        tmp_x = (self.camera.mouse_x - x)/factor
        tmp_y = (self.camera.mouse_y - y)/factor
        if tmp_x > self.camera.ROTATE:
            tmp_x = self.camera.ROTATE
        self.camera.rotate(tmp_y, tmp_x, 0)
        x = self.WINDOW_WIDTH/2
        y = self.WINDOW_HEIGHT/2
        glutWarpPointer(x, y)
        self.camera.mouse_x = x
        self.camera.mouse_y = y
        
    def keyPressed(self, key, x, y):
        '''Called when a key is pressed.'''
        if key.lower() in self.camera.keys:
            self.camera.keys[key.lower()] = True
        if glutGetModifiers() == GLUT_ACTIVE_SHIFT:
            self.camera.keys["shift"] = True
        if key == 'p' and not self.poly_view:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
            self.poly_view = True
        elif key == 'p' and self.poly_view:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
            self.poly_view = False
        elif key == 't':
            exit(9)
        if key.lower() == 'q':
            self.camera.WALK *= 1.2
            self.camera.SPRINT *= 1.2
        if key.lower() == 'e':
            self.camera.WALK *= .8
            self.camera.SPRINT *= .8

    def keyUp(self, key, x, y):
        '''Called when a key is released.'''
        self.camera.keys[key.lower()] = False
        if not glutGetModifiers() == GLUT_ACTIVE_SHIFT:
            self.camera.keys["shift"] = False
开发者ID:aapope,项目名称:TerrainGeneration,代码行数:104,代码来源:RenderWorld.py

示例4: __init__

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import rotate [as 别名]
class TestRender:
    '''This is the class that renders maze.
    Camera angles are handled by Camera.py.
    '''
    WINDOW_WIDTH = 700
    WINDOW_HEIGHT = 700
    SCALE = .5
    MAP_SIZE =100
    X_FACTOR = 1
    Y_FACTOR = 1
    Z_FACTOR = 1
    MAP_SIZE = 100
    SEA_LEVEL = 4

    def __init__(self):
        self.set_up_graphics()
        self.load_object()
	self.set_up_glut()
        self.camera = Camera(0,60,0)
	self.camera.rotate(-75,-150,0)
	self.poly_view = False	
        self.start_loop()


    def set_up_glut(self):
        glutIdleFunc(self.display)
        glutDisplayFunc(self.display)

        glutIgnoreKeyRepeat(GLUT_KEY_REPEAT_OFF)
        glutKeyboardFunc(self.keyPressed)
        glutKeyboardUpFunc(self.keyUp)

        glutSetCursor(GLUT_CURSOR_NONE)
        glutPassiveMotionFunc(self.mouseMove)
	
	#glGenLists(50)
	#glNewList(1, GL_COMPILE)
	#glNewList(1, GL_COMPILE)
    
    def start_loop(self):	
	glutMainLoop()

    def set_up_graphics(self):
        glutInit()
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
        glutInitWindowSize(self.WINDOW_WIDTH, self.WINDOW_HEIGHT)
        glutCreateWindow('Terrains!')

        glMatrixMode(GL_PROJECTION)

        gluPerspective(45,1,.1,500)
        glMatrixMode(GL_MODELVIEW)

        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable (GL_BLEND)
        
        
        glClearColor(.529,.8078,.980,0)
        glEnable(GL_NORMALIZE)

        glEnable (GL_DEPTH_TEST)

        #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    
    def load_object(self):
        self.load = Structure()
        self.structure = self.load.create_structure()

    def load_object2(self):
        self.load = Grass()
        self.structure = self.load.create_grass_list()

    def display(self, x=0, y=0):

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        #Put camera and light in the correct position
        self.camera.move()
	self.camera.renderRotateCamera()
        self.camera.renderTranslateCamera()
        glCallList(self.structure)
	
        
        glDisable(GL_TEXTURE_2D)
        glutSwapBuffers()
       
    def mouseMove(self, x, y):
        '''Called when the mouse is moved.'''
        factor = 2
        
        tmp_x = (self.camera.mouse_x - x)/factor
        tmp_y = (self.camera.mouse_y - y)/factor
        if tmp_x > self.camera.ROTATE:
            tmp_x = self.camera.ROTATE
        self.camera.rotate(tmp_y, tmp_x, 0)
        x = self.WINDOW_WIDTH/2
        y = self.WINDOW_HEIGHT/2
        glutWarpPointer(x, y)
        self.camera.mouse_x = x
        self.camera.mouse_y = y
#.........这里部分代码省略.........
开发者ID:aapope,项目名称:TerrainGeneration,代码行数:103,代码来源:TestRender.py

示例5: LivePlot

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

#.........这里部分代码省略.........
        glPointSize(10)
        glDisable(GL_DEPTH_TEST)
        self.batch.draw()
        
        self.camera.postrender()
        
    def render_2d(self):
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        
        w,h = self.get_size()
        glOrtho(0, w, 0, h, -1.0, 2.0)
        
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        
        ## Draw Text
        glDisable(GL_DEPTH_TEST)
        self.fps_display.draw()
        self.camera_mode_display.draw()
        glEnable(GL_DEPTH_TEST)
        
        glPopMatrix()
        
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()


    ## Events -----------------------------------------------------------------
    ## Input events
    def on_key_press(self, symbol, modifiers):
        pass
    
    def on_key_release(self, symbol, modifiers):
        if symbol == key.ESCAPE:
            self.close()
        elif symbol == key.F:
            if not self.fullscreen:
                pos = self.get_location()
                screens = pyglet.window.get_platform().get_default_display().get_screens()
                
                for s in screens:
                    if pos[0] >= s.x and \
                       pos[0] < s.x + s.width and \
                       pos[1] >= s.y and \
                       pos[1] < s.y + s.height:
                           screen = s
                           break
                    
                self.set_fullscreen(True, screen)
            else:
                self.set_fullscreen(False)
        elif symbol == key._1:
            self.camera.set_mode(Camera.FREE)
            self.set_exclusive_mouse(True)
        elif symbol == key._2:
            self.camera.set_mode(Camera.FOLLOW)
            self.set_exclusive_mouse(False)
        elif symbol == key._3:
            self.camera.set_mode(Camera.XY)
            self.set_exclusive_mouse(False)
        elif symbol == key._4:
            self.camera.set_mode(Camera.FIXED)
            self.set_exclusive_mouse(False)
        elif symbol == key.SPACE:
            self.camera.next_view()
    
    def on_mouse_motion(self, x, y, dx, dy):
        self.camera.rotate(-dx/700, dy/700)
    
    
    ## Window events
    def on_resize(self, width, height):
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        
        fov = 50
        aspect = width / height

        if width < height:
            fov = 360/math.pi * math.atan(math.tan(fov * math.pi/360) / aspect)
                    
        gluPerspective(fov, aspect, 0.1, 200000)
        
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        
        # Update text labels
        self.camera_mode_display.x = width - 5

        return pyglet.event.EVENT_HANDLED

    def on_draw(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        
        self.render()
        self.render_2d()
开发者ID:ngieseker,项目名称:Vision-System,代码行数:104,代码来源:LivePlot.py


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