SHARE
TWEET

Untitled

a guest May 14th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize, bool buildable_to, v3s16 *p)
  3. {
  4.     float distance = pos1.getDistanceFrom(pos2);
  5.  
  6.     //calculate normalized direction vector
  7.     v3f normalized_vector = v3f((pos2.X - pos1.X)/distance,
  8.         (pos2.Y - pos1.Y)/distance,
  9.         (pos2.Z - pos1.Z)/distance);
  10.  
  11.     //find out if there's a node on path between pos1 and pos2
  12.     for (float i = 1; i < distance; i += stepsize) {
  13.         v3s16 pos = floatToInt(v3f(normalized_vector.X * i,
  14.             normalized_vector.Y * i,
  15.             normalized_vector.Z * i) +pos1,BS);
  16.  
  17.         MapNode n = getMap().getNodeNoEx(pos);
  18.  
  19.         if(n.drawtype != NDT_AIRLIKE) {
  20.             if(buildable_to == true) {
  21.                 if(n.buildable_to == false) {
  22.                     if (p) {
  23.                         *p = pos;
  24.                     }
  25.                     return false;
  26.                 }
  27.             }
  28.             else
  29.             {
  30.                 if (p) {
  31.                     *p = pos;
  32.                 }
  33.                 return false;
  34.             }
  35.         }
  36.     }
  37.     return true;
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top