Komak57

Untitled

Mar 4th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1.         bool LinePlane(Vector start, Vector end, Vector[] face, Vector norm)
  2.         {
  3.             //Vector direction = end.Subtract(start);
  4.             Vector direction = end.Subtract(start);
  5.  
  6.             // Prepare our barycentric variables
  7.             // UV are our pixel coordinates in a 0 to 1 range
  8.             Vector tmp = face[1].Subtract(face[0]);
  9.             Vector3 u = new Vector3(tmp.X, tmp.Y, tmp.Z);
  10.             tmp = face[2].Subtract(face[0]);
  11.             Vector3 v = new Vector3(tmp.X, tmp.Y, tmp.Z);
  12.             tmp = start.Subtract(face[0]);
  13.             Vector3 w = new Vector3(tmp.X, tmp.Y, tmp.Z);
  14.            
  15.             Vector3 vCrossW = Vector3.Cross(v, w);
  16.             Vector3 vCrossU = Vector3.Cross(v, u);
  17.  
  18.             // Test sign of r
  19.             if (Vector3.Dot(vCrossW, vCrossU) < 0) // < 0
  20.                 return false;
  21.  
  22.             Vector3 uCrossW = Vector3.Cross(u, w);
  23.             Vector3 uCrossV = Vector3.Cross(u, v);
  24.  
  25.             // Test sign of t
  26.             if (Vector3.Dot(uCrossW, uCrossV) < 0) // < 0
  27.                 return false;
  28.  
  29.             // At this piont, we know that r and t and both > 0
  30.             float denom = uCrossV.Length();
  31.             float r = vCrossW.Length() / denom;
  32.             float t = uCrossW.Length() / denom;
  33.  
  34.             if (!(r <= 1 && t <= 1 && r + t <= 1))
  35.                 return false;
  36.             return true;
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment