Advertisement
Guest User

Untitled

a guest
Nov 19th, 2012
1,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. public override Intersection Intersect(Ray ray)
  2.         {
  3.             Intersection result = new Intersection();
  4.  
  5.             result.Thing = this;
  6.             result.Ray = ray;
  7.  
  8.             // Find t.
  9.             double t = - (Vector3.Dot(Norm,ray.Start) + Offset) / (Vector3.Dot(Norm, ray.Dir));
  10.             result.Dist = t;
  11.  
  12.             // Get a point on the plane.
  13.             Vector3 p = ray.Start + t * ray.Dir;
  14.  
  15.             // Does the ray intersect the plane inside or outside?
  16.             Vector3 planeToRayStart = ray.Start - p;
  17.             double dot = Vector3.Dot (planeToRayStart, Norm);
  18.             if (dot > 0) {
  19.                 result.Inside = false;
  20.             } else {
  21.                 result.Inside = true;
  22.             }
  23.  
  24.             return result;
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement