本文整理汇总了Python中World.World.setCube方法的典型用法代码示例。如果您正苦于以下问题:Python World.setCube方法的具体用法?Python World.setCube怎么用?Python World.setCube使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World.World
的用法示例。
在下文中一共展示了World.setCube方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import setCube [as 别名]
class Render:
def __init__(self,width,height):
self.globalLight = 0.45
self.accelerate = True
self.width = width
self.height = height
# world
self.world = World()
self.world.setCube()
#self.world.setTest()
# Viewport Transformation
nx = self.width # number of x in screen
ny = self.height # number of y in screen
self.Tvp = ViewportTransformation(nx,ny)
# Camera Transformation
self.viewDist = 200
self.Tcam = CamaraTransformation(self.viewDist)
# Perspective Projection
self.Tper = PerspectiveProjection(l=-100,r=100,b=-100,t=100,n=-100,f=-300)
# background
self.backgound = Color(255,255,255)
self.lineColor = Color(0,0,0)
def toggleAccelerate(self):
self.accelerate = not self.accelerate
def changeViewDist(self,deltaViewDist):
newViewDist = self.viewDist + deltaViewDist
if newViewDist < 142 or newViewDist > 1000:
return
self.viewDist = newViewDist
self.Tcam = CamaraTransformation(self.viewDist)
def naiveDrawLine(self,window,p,q):
# see https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
x0,y0 = p
x1,y1 = q
if x0 > x1:
p,q = q,p
x0,y0 = p
x1,y1 = q
# x0 <= x1
x0,y0,x1,y1 = int(x0),int(y0),int(x1),int(y1)
dx = abs(x1-x0)
dy = abs(y1-y0)
if x0 < x1:
sx = 1
else:
sx = -1
if y0 < y1:
sy = 1
else:
sy = -1
err = dx-dy
while True:
p = [x0,y0]
pygame.draw.line(window,self.lineColor,p,p)
if x0 == x1 and y0 == y1:
break
e2 = 2 * err
if e2 > -dy:
err = err - dy
x0 = x0 + sx
if x0 == x1 and y0 == y1:
p = [x0,y0]
pygame.draw.line(window,self.lineColor,p,p)
break
if e2 < dx:
err = err + dx
y0 = y0 + sy
def drawLine(self,window,p,q):
if self.accelerate:
pygame.draw.aaline(window,self.lineColor,p,q, 2)
else:
self.naiveDrawLine(window,p,q)
def naiveDrawPolygon(self,window,color,pointList):
if len(pointList) > 3:
self.naiveDrawPolygon(window,color,pointList[:3])
self.naiveDrawPolygon(window,color,[pointList[0]]+pointList[2:])
return
x1,y1 = pointList[0][0], pointList[0][1]
x2,y2 = pointList[1][0], pointList[1][1]
x3,y3 = pointList[2][0], pointList[2][1]
x2,y2 = x2-x1, y2-y1
#.........这里部分代码省略.........