Example #1
0
 def checkInter(self, objlist):
     min_length = 1.0e8
     min_object = face(vector3(0.0,0.0,0.0), vector3(0.0,0.0,0.0), 0)
     for element in objlist:
         dest = self.intersection(element)
         if vector3.norm(dest) < min_length :
             min_length = vector3.norm(dest)
             min_object = element
     i_point = vector3.add_vec(self.point, vector3.mul_vec(self.direction, min_length))
     return i_point, min_object
Example #2
0
 def checkShadow(self, start, light, objlist):
     occluded = 0
     o2light = vector3.nrm_vec(vector3.sub_vec(light.point, start))
     min_length = vector3.norm(o2light)
     if min_length > 1.0e6 : print "a"; return 0
     ray2light = ray(vector3.sub_vec(start,vector3.mul_vec(o2light, -1.0e-8)), o2light)
     for element in objlist:
         dest = ray2light.intersection(element)
         if vector3.norm(dest) < min_length :
             occluded = 1
     return occluded
Example #3
0
 def intersection (self, obj):
     k = 0.0
     if obj.radius > 0.0: #sphere
         o2e = vector3.sub_vec(self.point, obj.point)
         half_b = vector3.dot_vec(o2e, self.direction)
         c = vector3.dot_vec(o2e,o2e) - obj.radius*obj.radius
         if half_b*half_b - c >= 0:
             k =  -half_b - sqrt(half_b*half_b - c)
         else :
             k = 1.0e8
     else : #face
         o2e = vector3.sub_vec(self.point, obj.point)
         b = vector3.dot_vec(self.direction,obj.normal)
         if abs(b) > 1.0e-3 :
             k = -(vector3.dot_vec(o2e,obj.normal)) / b
         else :
             k = 1.0e8
     if k<0 : k = 1.0e8
     return vector3.mul_vec(self.direction, k)
Example #4
0
 def reflect(self, face, normal):
     self.point = self.intersection(face)
     '''  calc direction '''
     tmp_vec = vector3.mul_vec(normal, 2*vector3.dot_vec(self.direction, normal))
     self.direction = vector3.sub_vec(self.direction, tmp_vec)