Raycast() публичный Метод

public Raycast ( RayD, ray, double &enter ) : bool
ray RayD,
enter double
Результат bool
Пример #1
0
    public void TestPlaneRayCast()
    {
        Random.InitState(123);
        for (int i = 0; i < 1000; i++)
        {
            Vector3  direction  = Random.onUnitSphere;
            float    dist       = Random.Range(-999, 999);
            Vector3D directionD = new Vector3D(direction);
            Plane3D  planeD     = new Plane3D(directionD, dist);
            Plane    plane      = new Plane(direction, dist);
            for (int j = 0; j < 10; j++)
            {
                Vector3  pos     = Random.insideUnitSphere * 999;
                Vector3  rayDir  = Random.onUnitSphere;
                Vector3D posD    = new Vector3D(pos);
                Vector3D rayDirD = new Vector3D(rayDir);
                Ray      r       = new Ray(pos, rayDir);
                RayD     rd      = new RayD(posD, rayDirD);

                float  enter;
                double enterD;
                bool   res  = plane.Raycast(r, out enter);
                bool   resD = planeD.Raycast(rd, out enterD);
                Assert.AreEqual(res, resD, "Raycast Res " + plane + " ray " + r);
                if (enterD < 1e7)
                {
                    Assert.AreEqual((double)enter, enterD, Mathf.Abs(enter) / 1000,
                                    "GetDistanceToPoint " + plane + " ray " + r);
                }
            }
        }
    }
Пример #2
0
    Vector3D ProjectToTriangle(Vector3D point)
    {
        Plane3D plane          = new Plane3D(Normal, points[0]);
        bool    isPointInPlane = System.Math.Abs(plane.GetDistanceToPoint(point)) < 0.0001;

        if (!isPointInPlane)
        {
            double dist;
            point.y = 0;
            var ray = new RayD(point, Vector3D.up);
            plane.Raycast(ray, out dist);
            point.y = dist;
        }
        return(point);
    }
Пример #3
0
    void ReprojectY(List <Triangle> res, Plane3D plane)
    {
        double pos = 0;

        foreach (var t in res)
        {
            for (int i = 0; i < 3; i++)
            {
                var p = t.points[i];
                p.y = 0;
                RayD r = new RayD(p, Vector3D.up);
                if (plane.Raycast(r, out pos))
                {
                    p.y         = (float)pos;
                    t.points[i] = p;
                }
            }
        }
    }
Пример #4
0
 void ReprojectY(List<Triangle> res, Plane3D plane)
 {
     double pos = 0;
     foreach (var t in res){
         for (int i=0;i<3;i++){
             var p = t.points[i];
             p.y = 0;
             RayD r = new RayD(p, Vector3D.up);
             if (plane.Raycast(r,out pos)){
                 p.y = (float)pos;
                 t.points[i] = p;
             }
         }
     }
 }
Пример #5
0
 Vector3D ProjectToTriangle(Vector3D point)
 {
     Plane3D plane = new Plane3D(Normal, points[0]);
     bool isPointInPlane = System.Math.Abs(plane.GetDistanceToPoint(point))<0.0001;
     if (!isPointInPlane) {
         double dist;
         point.y = 0;
         var ray = new RayD(point, Vector3D.up);
         plane.Raycast(ray, out dist);
         point.y = dist;
     }
     return point;
 }