def render(self, canvas):
fovRadians = math.pi * (self.fieldOfView / 2.0) / 180.0
halfWidth = math.tan(fovRadians)
halfHeight = 0.75 * halfWidth
width = halfWidth * 2
height = halfHeight * 2
pixelWidth = width / (canvas.width - 1)
pixelHeight = height / (canvas.height - 1)
eye = Ray(self.position, self.lookingAt - self.position)
vpRight = eye.vector.cross(Vector.UP).normalized()
vpUp = vpRight.cross(eye.vector).normalized()
for y in xrange(canvas.height):
for x in xrange(canvas.width):
xcomp = vpRight.scale(x * pixelWidth - halfWidth)
ycomp = vpUp.scale(y * pixelHeight - halfHeight)
ray = Ray(eye.point, eye.vector + xcomp + ycomp)
colour = self.rayColour(ray)
canvas.plot(x, y, *colour)
评论列表
文章目录