Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool LinePlane(Vector start, Vector end, Vector[] face, Vector norm)
- {
- //Vector direction = end.Subtract(start);
- Vector direction = end.Subtract(start);
- // Prepare our barycentric variables
- // UV are our pixel coordinates in a 0 to 1 range
- Vector tmp = face[1].Subtract(face[0]);
- Vector3 u = new Vector3(tmp.X, tmp.Y, tmp.Z);
- tmp = face[2].Subtract(face[0]);
- Vector3 v = new Vector3(tmp.X, tmp.Y, tmp.Z);
- tmp = start.Subtract(face[0]);
- Vector3 w = new Vector3(tmp.X, tmp.Y, tmp.Z);
- Vector3 vCrossW = Vector3.Cross(v, w);
- Vector3 vCrossU = Vector3.Cross(v, u);
- // Test sign of r
- if (Vector3.Dot(vCrossW, vCrossU) < 0) // < 0
- return false;
- Vector3 uCrossW = Vector3.Cross(u, w);
- Vector3 uCrossV = Vector3.Cross(u, v);
- // Test sign of t
- if (Vector3.Dot(uCrossW, uCrossV) < 0) // < 0
- return false;
- // At this piont, we know that r and t and both > 0
- float denom = uCrossV.Length();
- float r = vCrossW.Length() / denom;
- float t = uCrossW.Length() / denom;
- if (!(r <= 1 && t <= 1 && r + t <= 1))
- return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment