Esempio n. 1
0
 def baseColourAt(self, p):
     v = p - PZERO
     v.scale(1.0 / self.checkSize)
     if (hax.ftoi(hax.abs(v.x) + 0.5) + \
         hax.ftoi(hax.abs(v.y) + 0.5) + \
         hax.ftoi(hax.abs(v.z) + 0.5)) \
        % 2:
         return self.otherColour
     else:
         return self.baseColour
Esempio n. 2
0
 def baseColourAt(self, p):
     v = p - PZERO
     v.scale(1.0 / self.checkSize)
     if (hax.ftoi(hax.abs(v.x) + 0.5) + \
         hax.ftoi(hax.abs(v.y) + 0.5) + \
         hax.ftoi(hax.abs(v.z) + 0.5)) \
        % 2:
         return self.otherColour
     else:
         return self.baseColour
Esempio n. 3
0
    def render(self, canvas):
        #print 'Computing field of view'
        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(VUP).normalized()
        vpUp = vpRight.cross(eye.vector).normalized()

        #print 'Looping over pixels'
        previousfraction = 0.0
        for y in range(canvas.height):
            currentfraction = hax.itof(y) / canvas.height
            if currentfraction - previousfraction > 0.05:
                print '%d%% complete' % hax.ftoi(currentfraction * 100)
                previousfraction = currentfraction
            for x in range(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[0], colour[1], colour[2])

        print 'Complete.'
        canvas.save()
Esempio n. 4
0
    def render(self, canvas):
        #print 'Computing field of view'
        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(VUP).normalized()
        vpUp = vpRight.cross(eye.vector).normalized()

        #print 'Looping over pixels'
        previousfraction = 0.0
        for y in range(canvas.height):
            currentfraction = hax.itof(y) / canvas.height
            if currentfraction - previousfraction > 0.05:
                print '%d%% complete' % hax.ftoi(currentfraction * 100)
                previousfraction = currentfraction
            for x in range(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[0], colour[1], colour[2])

        print 'Complete.'
        canvas.save()
Esempio n. 5
0
 def plot(self, x, y, r, g, b):
     i = ((self.height - y - 1) * self.width + x) * 3
     self.bytes[i  ] = hax.max(0, hax.min(255, hax.ftoi(r * 255)))
     self.bytes[i+1] = hax.max(0, hax.min(255, hax.ftoi(g * 255)))
     self.bytes[i+2] = hax.max(0, hax.min(255, hax.ftoi(b * 255)))
Esempio n. 6
0
 def plot(self, x, y, r, g, b):
     i = ((self.height - y - 1) * self.width + x) * 3
     self.bytes[i] = hax.max(0, hax.min(255, hax.ftoi(r * 255)))
     self.bytes[i + 1] = hax.max(0, hax.min(255, hax.ftoi(g * 255)))
     self.bytes[i + 2] = hax.max(0, hax.min(255, hax.ftoi(b * 255)))