Advertisement
vikhik

loscheck v3

May 26th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1.     def loscheck(self, target_pos):
  2.         canSee = True
  3.         for obj in self.world.objs:
  4.             #is the obj.pos + obj.radius in the line between self.pos and target_pos
  5.                 #return True
  6.                
  7.             #find closest point on line (self.pos to target_pos) to obj.pos
  8.            
  9.             A = self.pos
  10.             B = target_pos
  11.             P = obj.pos
  12.            
  13.             AB = B - A
  14.            
  15.             if AB.lengthSq() == 0: #I'm me, ofc I can see myself.
  16.                 return False
  17.            
  18.             AP = P - A
  19.            
  20.             AB_sq = float(AB.lengthSq())
  21.            
  22.             AP_dot_AB = float(AP.dot(AB))
  23.            
  24.             #d = dist from A to closest point to P along line AB
  25.             d = AP_dot_AB / AB_sq
  26.            
  27.             #D = nearest point on line AB to P
  28.             D = A + AB*d
  29.  
  30.             DP = P - D
  31.  
  32.             #is this point inside of the obj radius
  33.             if (DP.length() < obj.radius):
  34.                 canSee = False
  35.            
  36.         return canSee
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement