本文整理汇总了Python中Camera.Camera.renderCamera方法的典型用法代码示例。如果您正苦于以下问题:Python Camera.renderCamera方法的具体用法?Python Camera.renderCamera怎么用?Python Camera.renderCamera使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera.Camera
的用法示例。
在下文中一共展示了Camera.renderCamera方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blocks
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import renderCamera [as 别名]
class RenderWorld:
'''This is the class that renders blocks (and the floor that they sit on). Camera angles are handled by another class'''
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 400
def __init__(self, file_name):
'''Sets everything up: camera, modes, lighting, and the list of blocks'''
self.camera = Camera()
self.set_up_graphics()
self.makeLights()
self.objects = LoadWorld.load(file_name)
# glMaterialfv(GL_FRONT, GL_SPECULAR, [1, 1, 1, 1])
# glMaterialfv(GL_FRONT, GL_SHININESS, [50])
glClearColor(.529,.8078,.980,0)
glutDisplayFunc(self.display)
glutKeyboardFunc(self.keyPressed)
glutMainLoop()
def set_up_graphics(self):
'''Sets up the gl modes that are necessary'''
glutInit()
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(self.WINDOW_WIDTH, self.WINDOW_HEIGHT)
glutCreateWindow('World!')
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 floor and blocks and based on the camera angle'''
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
self.camera.renderCamera()
self.renderLightSource()
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()
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import renderCamera [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
#.........这里部分代码省略.........