def litColour(self, normal, ambientLight, lights, viewVector, texCords=None): """The RGB colour of this material with the given surface normal under the given lighting when viewed from an eyepoint in the viewVector direction.""" diffcol = self.diffuseColour if self.texture: diffcol = self.texture.colour(texCords) colour = ambientLight * diffcol for light in filter(lambda x: x != None, lights): if self.shininess: H = unit(light.vector + viewVector) colour += (max(0, normal.dot(light.vector)) * diffcol + normal.dot(H)**self.shininess * self.specularColour) * light.colour colour += max(0, normal.dot(light.vector)) * diffcol * light.colour return colour
def right(self, amount): movement = amount * unit(self.facing().cross(self.viewup)) self.position += movement self.lookat += movement if not self.disconnected: self.robot.right(amount) glutPostRedisplay()
def forward(self, amount): movement = amount * unit(self.facing()) self.position += movement self.lookat += movement if not self.disconnected: self.robot.forward(amount) glutPostRedisplay()
def litColour(self, normal, ambientLight, lights, viewVector, texCords=None): """The RGB colour of this material with the given surface normal under the given lighting when viewed from an eyepoint in the viewVector direction.""" diffcol = self.diffuseColour if self.texture: diffcol = self.texture.colour(texCords) colour = ambientLight * diffcol for light in filter(lambda x: x != None, lights) : if self.shininess: H = unit(light.vector + viewVector) colour += (max(0, normal.dot(light.vector)) * diffcol + normal.dot(H)**self.shininess * self.specularColour) * light.colour colour += max(0, normal.dot(light.vector)) * diffcol * light.colour return colour
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, (), self.norm, self.mat) else: hit = Hit(self, ray, None, t, self.norm, self.mat) else: vector = unit(ray.start - self.point) if vector.dot(self.norm) < 0: hit = Hit(self, ray, None, (), self.norm, self.mat) else: return None if self.mat.texture and hit.entry > 0: hit.texCords = self.texCords(ray.pos(t)) return hit
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, (), self.norm, self.mat) else : hit = Hit(self, ray, None, t, self.norm, self.mat) else: vector = unit(ray.start - self.point) if vector.dot(self.norm) < 0: hit = Hit(self, ray, None, (), self.norm, self.mat) else: return None if self.mat.texture and hit.entry > 0: hit.texCords = self.texCords(ray.pos(t)) return hit
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 normal(self, p): """The surface normal at the given point on the sphere""" return unit(p - self.center)
def __init__(self, point, normal): """Create a plane through a given point with given normal""" self.point = point self.norm = unit(normal)
def facing(self): direction = self.lookat - self.position if not self.disconnected: direction.dy = 0 return unit(direction)
def __init__(self, point, normal, material): """Create a plane through a given point with given normal and surface material""" self.point = point self.norm = unit(normal) self.mat = material
def right(self, amount): movement = amount * unit((self.lookat - self.position).cross(Vector3(self.viewup))) self.position += movement self.lookat += movement glutPostRedisplay()
def forward(self, amount): movement = amount * unit(self.lookat - self.position) self.position += movement self.lookat += movement glutPostRedisplay()
def normal(self, p): """The surface normal at the given point on the sphere""" return unit(p - self.centre)