コード例 #1
0
ファイル: Sphere.cs プロジェクト: Tilps/Stash
 public override RealHitInfo DelayedHitCalc(Line by, HitInfo hit)
 {
     RealHitInfo realHit = new RealHitInfo();
     realHit.HitStuff = Surface;
     realHit.Pigment = Pigment;
     realHit.Normal = new Line();
     realHit.Normal.Start = by.Project(hit.HitDist);
     realHit.Normal.Direct.Dx = 0;
     realHit.Normal.Direct.Dy = 0;
     realHit.Normal.Direct.Dz = 0;
     switch (hit.SurfaceIndex)
     {
         case 0:
             Point hitLoc2 = inv.Apply(realHit.Normal.Start);
             realHit.Normal.Direct.Dx = hitLoc2.X;
             realHit.Normal.Direct.Dy = hitLoc2.Y;
             realHit.Normal.Direct.Dz = hitLoc2.Z;
             break;
         default:
             throw new InvalidOperationException("Invalid surface index in hitdata");
     }
     Vector before = realHit.Normal.Direct;
     realHit.Normal.Direct = trans.Apply(realHit.Normal.Direct);
     if (realHit.Normal.Direct.Dot(by.Direct) > 0)
     {
         realHit.Normal.Direct.ScaleSelf(-1.0);
     }
     return realHit;
 }
コード例 #2
0
ファイル: Box.cs プロジェクト: Tilps/Stash
 public override RealHitInfo DelayedHitCalc(Line by, HitInfo hit)
 {
     RealHitInfo realHit = new RealHitInfo();
     realHit.Normal = new Line();
     realHit.HitStuff = Surface;
     realHit.Pigment = Pigment;
     realHit.Normal.Start = by.Project(hit.HitDist);
     realHit.Normal.Direct.Dx = 0;
     realHit.Normal.Direct.Dy = 0;
     realHit.Normal.Direct.Dz = 0;
     Point hitLoc;
     Vector deviance = new Vector();
     if (rounded)
     {
         hitLoc = inv.Apply(realHit.Normal.Start);
         if (hit.SurfaceIndex != 5 || !RoundedTopOnly)
         {
             if (hitLoc.X < -1 + XRounding)
             {
                 switch (hit.SurfaceIndex)
                 {
                     case 2:
                     case 3:
                     case 4:
                     case 5:
                         deviance.Dx = -1 + (hitLoc.X + 1) / XRounding;
                         break;
                 }
             }
             if (hitLoc.X > 1 - XRounding)
             {
                 switch (hit.SurfaceIndex)
                 {
                     case 2:
                     case 3:
                     case 4:
                     case 5:
                         deviance.Dx = 1 - (1 - hitLoc.X) / XRounding;
                         break;
                 }
             }
             if (hitLoc.Y < -1 + YRounding)
             {
                 switch (hit.SurfaceIndex)
                 {
                     case 0:
                     case 1:
                     case 4:
                     case 5:
                         deviance.Dy = -1 + (hitLoc.Y + 1) / YRounding;
                         break;
                 }
             }
             if (hitLoc.Y > 1 - YRounding)
             {
                 switch (hit.SurfaceIndex)
                 {
                     case 0:
                     case 1:
                     case 4:
                     case 5:
                         deviance.Dy = 1 - (1 - hitLoc.Y) / YRounding;
                         break;
                 }
             }
         }
         if (!RoundedTopOnly && hitLoc.Z < -1 + ZRounding)
         {
             switch (hit.SurfaceIndex)
             {
                 case 0:
                 case 1:
                 case 2:
                 case 3:
                     deviance.Dz = -1 +(hitLoc.Z + 1) / ZRounding;
                     break;
             }
         }
         if (hitLoc.Z > 1 - ZRounding)
         {
             switch (hit.SurfaceIndex)
             {
                 case 0:
                 case 1:
                 case 2:
                 case 3:
                     deviance.Dz = 1 - (1 - hitLoc.Z) / ZRounding;
                     break;
             }
         }
     }
     switch (hit.SurfaceIndex)
     {
         case 0:
             realHit.Normal.Direct.Dx = 1;
             break;
         case 1:
             realHit.Normal.Direct.Dx = -1;
             break;
         case 2:
             realHit.Normal.Direct.Dy = 1;
             break;
         case 3:
             realHit.Normal.Direct.Dy = -1;
             break;
         case 4:
             realHit.Normal.Direct.Dz = 1;
             break;
         case 5:
             realHit.Normal.Direct.Dz = -1;
             break;
         default:
             throw new InvalidOperationException("Invalid surface index in hitdata");
     }
     Vector before = realHit.Normal.Direct;
     realHit.Normal.Direct = trans.Apply(realHit.Normal.Direct);
     if (realHit.Normal.Direct.Dot(by.Direct) > 0)
     {
         if (rounded)
         {
             before.ScaleSelf(-1.0);
             deviance.ScaleSelf(-1.0);
         }
         else
             realHit.Normal.Direct.ScaleSelf(-1.0);
     }
     if (rounded)
     {
         realHit.Normal.Direct = before;
         realHit.Normal.Direct.Add(deviance);
         realHit.Normal.Direct = trans.Apply(realHit.Normal.Direct);
         if (realHit.Normal.Direct.Dot(by.Direct) > 0)
         {
             Vector perp1 = realHit.Normal.Direct.Cross(by.Direct);
             realHit.Normal.Direct = by.Direct.Cross(perp1);
         }
     }
     return realHit;
 }
コード例 #3
0
ファイル: Cylinder.cs プロジェクト: Tilps/Stash
 public override RealHitInfo DelayedHitCalc(Line by, HitInfo hit)
 {
     RealHitInfo realHit = new RealHitInfo();
     realHit.HitStuff = Surface;
     realHit.Pigment = Pigment;
     realHit.Normal = new Line();
     realHit.Normal.Start = by.Project(hit.HitDist);
     realHit.Normal.Direct.Dx = 0;
     realHit.Normal.Direct.Dy = 0;
     realHit.Normal.Direct.Dz = 0;
     Point hitLoc;
     Vector deviance = new Vector();
     if (rounded)
     {
         hitLoc = inv.Apply(realHit.Normal.Start);
         if (hit.SurfaceIndex == 1 || (!RoundedTopOnly && hit.SurfaceIndex == 2))
         {
             double r = Math.Sqrt(hitLoc.X * hitLoc.X + hitLoc.Y * hitLoc.Y);
             if (r > 1 - RRounding)
             {
                 double dr = (1 - (1 - r) / RRounding) / (r);
                 deviance.Dx = hitLoc.X * dr;
                 deviance.Dy = hitLoc.Y * dr;
             }
         }
         if (!RoundedTopOnly && hitLoc.Z < -1 + ZRounding)
         {
             switch (hit.SurfaceIndex)
             {
                 case 0:
                     deviance.Dz = -1 + (hitLoc.Z + 1) / ZRounding;
                     break;
             }
         }
         if (hitLoc.Z > 1 - ZRounding)
         {
             switch (hit.SurfaceIndex)
             {
                 case 0:
                     deviance.Dz = 1 - (1 - hitLoc.Z) / ZRounding;
                     break;
             }
         }
     }
     switch (hit.SurfaceIndex)
     {
         case 0:
             Point hitLoc2 = inv.Apply(realHit.Normal.Start);
             realHit.Normal.Direct.Dx = hitLoc2.X;
             realHit.Normal.Direct.Dy = hitLoc2.Y;
             break;
         case 1:
             realHit.Normal.Direct.Dz = 1;
             break;
         case 2:
             realHit.Normal.Direct.Dz = -1;
             break;
         default:
             throw new InvalidOperationException("Invalid surface index in hitdata");
     }
     Vector before = realHit.Normal.Direct;
     realHit.Normal.Direct = trans.Apply(realHit.Normal.Direct);
     if (realHit.Normal.Direct.Dot(by.Direct) > 0)
     {
         if (rounded)
         {
             before.ScaleSelf(-1.0);
             deviance.ScaleSelf(-1.0);
         }
         else
             realHit.Normal.Direct.ScaleSelf(-1.0);
     }
     if (rounded)
     {
         realHit.Normal.Direct = before;
         realHit.Normal.Direct.Add(deviance);
         realHit.Normal.Direct = trans.Apply(realHit.Normal.Direct);
         if (realHit.Normal.Direct.Dot(by.Direct) > 0)
         {
             Vector perp1 = realHit.Normal.Direct.Cross(by.Direct);
             realHit.Normal.Direct = by.Direct.Cross(perp1);
         }
        }
     return realHit;
 }
コード例 #4
0
      private bool AreLinesEqual(Line line1, Line line2)
      {
         if (!line1.IsBound || !line2.IsBound)
         {
            // Two unbound lines are equal if they are going in the same direction and the origin
            // of one lies on the other one.
            return line1.Direction.IsAlmostEqualTo(line2.Direction) &&
               MathUtil.IsAlmostZero(line1.Project(line2.Origin).Distance);
         }

         for (int ii = 0; ii < 2; ii++)
         {
            if (line1.GetEndPoint(0).IsAlmostEqualTo(line2.GetEndPoint(ii)) &&
                line1.GetEndPoint(1).IsAlmostEqualTo(line2.GetEndPoint(1 - ii)))
               return true;
         }

         return false;
      }