Ejemplo n.º 1
0
    //Is a line intersecting with a plane?
    private void LinePlane()
    {
        Vector3 planeNormal = planeTrans.forward;

        Vector3 planePos = planeTrans.position;

        Vector3 line_p1 = t1_p1_trans.position;

        Vector3 line_p2 = t1_p2_trans.position;


        //2d space
        MyVector2 planeNormal_2d = planeNormal.ToMyVector2();

        MyVector2 planePos_2d = planePos.ToMyVector2();

        MyVector2 line_p1_2d = line_p1.ToMyVector2();

        MyVector2 line_p2_2d = line_p2.ToMyVector2();


        bool isIntersecting = Intersections.LinePlane(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d);


        //Debug
        //TestAlgorithmsHelpMethods.DrawPlane(planePos_2d, planeNormal_2d, Color.blue);

        ////Line
        //Gizmos.color = Color.white;

        //Gizmos.DrawWireSphere(line_p1, 0.1f);
        //Gizmos.DrawWireSphere(line_p2, 0.1f);

        //if (isIntersecting)
        //{
        //    Gizmos.color = Color.red;

        //    MyVector2 intersectionPoint = Intersections.GetLinePlaneIntersectionPoint(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d);

        //    Gizmos.DrawWireSphere(intersectionPoint.ToVector3(), 0.2f);
        //}

        //Gizmos.DrawLine(line_p1, line_p2);


        //Display with mesh
        //Plane
        TestAlgorithmsHelpMethods.DisplayPlaneMesh(planePos_2d, planeNormal_2d, 0.5f, Color.blue);

        //Line
        TestAlgorithmsHelpMethods.DisplayLineMesh(line_p1_2d, line_p2_2d, 0.5f, Color.white);

        if (isIntersecting)
        {
            MyVector2 intersectionPoint = Intersections.GetLinePlaneIntersectionPoint(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d);

            TestAlgorithmsHelpMethods.DisplayCircleMesh(intersectionPoint, 1f, 20, Color.red);
        }
    }