예제 #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
예제 #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()
예제 #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()
예제 #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
예제 #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
예제 #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
예제 #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
예제 #8
0
 def normal(self, p):
     """The surface normal at the given point on the sphere"""
     return unit(p - self.center)
예제 #9
0
 def __init__(self, point, normal):
     """Create a plane through a given point with given normal"""
     self.point = point
     self.norm = unit(normal)
예제 #10
0
 def facing(self):
   direction = self.lookat - self.position
   if not self.disconnected:
     direction.dy = 0
   return unit(direction)
예제 #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
예제 #12
0
파일: robot.py 프로젝트: nihil-momenti/Maze
 def right(self, amount):
   movement = amount * unit((self.lookat - self.position).cross(Vector3(self.viewup)))
   self.position += movement
   self.lookat += movement
   glutPostRedisplay()
예제 #13
0
파일: robot.py 프로젝트: nihil-momenti/Maze
 def forward(self, amount):
   movement = amount * unit(self.lookat - self.position)
   self.position += movement
   self.lookat += movement
   glutPostRedisplay()
예제 #14
0
 def normal(self, p):
     """The surface normal at the given point on the sphere"""
     return unit(p - self.centre)
예제 #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