def render_intersection(self, intersection, ray, world, bouncenum): """Returns the value to render, possibly by recusively rendering reflections""" global bounces bounces.append(self) # getting color r1mod = (vectormath.get_projection_of_ray_onto_ray( [self.ray1[0], intersection], self.ray1 ) % vectormath.get_distance(*self.ray1)) r2mod = (vectormath.get_projection_of_ray_onto_ray( [self.ray2[0], intersection], self.ray2 ) % vectormath.get_distance(*self.ray2)) if (numpy.floor(r1mod) + numpy.floor(r2mod)) % 2 == 0: color = 0 else: color = 1 if bouncenum > BOUNCELIMIT: print 'bouncelimit acheived, ignoring further reflections for this ray' print bounces bounces = [] return self.color * .5 + self.color * .5 * world.render_light(intersection, ray) else: bounce_ray = self.get_bounced_ray(ray, intersection) v = ( color * .5 + self.reflectivity/2 * world.render_ray(bounce_ray, bouncenum+1) + color * (1 - self.reflectivity/2) * world.render_light(intersection, ray) ) return v
def object_intersection_sort_method(x): obj, intersection = x proj = vectormath.get_projection_of_ray_onto_ray((ray[0], intersection), ray) if proj < .0001: # behind object - return inf so goes to back of list return float('inf') else: return proj