def intersection(self, other): """Returns the intersection of 2 hits""" ret = self if other is None: return None # fixme: Is this the best option? if other.entry > self.entry: ret.entry = other.entry ret.mat = other.mat ret.normal = other.normal ret.texCords = other.texCords if not isninf(other.exit): if not isninf(self.exit): if self.exit > other.exit: ret.exit = other.exit ret.normal2 = other.normal2 else: ret.exit = other.exit return ret
def intersect(self, ray): """Intersect the given ray with all objects in the scene, returning the pair (obj, t) of the first hit or None if there are no hits""" minHit = BlankHit(self.background) for o in self.objs: hit = o.intersect(ray) # hit.entry can be None when hit is not None if hit and not helpers.isninf(hit.entry) and (hit.entry > 0): if minHit is None or hit < minHit: minHit = hit return minHit
def difference(self, other): """Returns the driffence of 2 hits""" ret = self if other is None: return ret if other.exit and not isninf(other.exit): if other.exit > self.entry and other.entry < self.entry: ret.entry = other.exit ret.mat = other.mat if other.normal2 is None: print(other) ret.normal = -other.normal2 ret.texCords = other.texCords return ret
def intersect(self, ray): """Returns a hit, or None if the ray is parallel to the plane""" t = None hit = None angle = ray.dir.dot(self.norm) if angle != 0: t = (self.point - ray.start).dot(self.norm) / angle if angle < 0: hit = Hit(self, ray, t, float('inf'), self.norm, self.mat) else: hit = Hit(self, ray, float('-inf'), t, self.norm, self.mat) else: vector = unit(ray.start - self.point) if vector.dot(self.norm) < 0: hit = Hit(self, ray, float('-inf'), float('inf'), self.norm, self.mat) else: return None if (self.mat.texture is not None and not isninf(hit.entry)) > 0: hit.texCords = self.texCords(ray.pos(t)) return hit
def miss(self): return (self.exit < 0 and not isninf(self.exit)) or ( not isninf(self.exit) and not isninf(self.entry) and (self.entry - self.exit) > 0.00000001)