Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
 def forward(self, amount):
   movement = amount * unit(self.facing())
   self.position += movement
   self.lookat += movement
   if not self.disconnected:
     self.robot.forward(amount)
   glutPostRedisplay()
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
 def normal(self, p):
     """The surface normal at the given point on the sphere"""
     return unit(p - self.center)
Ejemplo n.º 9
0
 def __init__(self, point, normal):
     """Create a plane through a given point with given normal"""
     self.point = point
     self.norm = unit(normal)
Ejemplo n.º 10
0
 def facing(self):
   direction = self.lookat - self.position
   if not self.disconnected:
     direction.dy = 0
   return unit(direction)
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 def right(self, amount):
   movement = amount * unit((self.lookat - self.position).cross(Vector3(self.viewup)))
   self.position += movement
   self.lookat += movement
   glutPostRedisplay()
Ejemplo n.º 13
0
 def forward(self, amount):
   movement = amount * unit(self.lookat - self.position)
   self.position += movement
   self.lookat += movement
   glutPostRedisplay()
Ejemplo n.º 14
0
 def normal(self, p):
     """The surface normal at the given point on the sphere"""
     return unit(p - self.centre)
Ejemplo n.º 15
0
 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