Esempio n. 1
0
    //Is a plane intersecting with a plane
    private void PlanePlane()
    {
        Vector3 planeNormal_1 = planeTrans.forward;

        Vector3 planePos_1 = planeTrans.position;

        Vector3 planeNormal_2 = rayTrans.forward;

        Vector3 planePos_2 = rayTrans.position;

        //3d to 2d
        MyVector2 normal_1 = planeNormal_1.ToMyVector2();
        MyVector2 normal_2 = planeNormal_2.ToMyVector2();

        MyVector2 pos1 = planePos_1.ToMyVector2();
        MyVector2 pos2 = planePos_2.ToMyVector2();


        //Intersections
        bool isIntersecting = Intersections.PlanePlane(pos1, normal_1, pos2, normal_2);

        Debug.Log("Are planes intersecting: " + isIntersecting);


        //Display
        //if (isIntersecting)
        //{
        //    MyVector2 intersectionPoint = Intersections.GetPlanePlaneIntersectionPoint(pos1, normal_1, pos2, normal_2);

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

        //Color planeColor = isIntersecting ? Color.red : Color.white;

        //TestAlgorithmsHelpMethods.DrawPlane(pos1, normal_1, planeColor);
        //TestAlgorithmsHelpMethods.DrawPlane(pos2, normal_2, planeColor);



        //Display with mesh
        TestAlgorithmsHelpMethods.DisplayPlaneMesh(pos1, normal_1, 0.5f, Color.blue);
        TestAlgorithmsHelpMethods.DisplayPlaneMesh(pos2, normal_2, 0.5f, Color.blue);

        if (isIntersecting)
        {
            MyVector2 intersectionPoint = Intersections.GetPlanePlaneIntersectionPoint(pos1, normal_1, pos2, normal_2);

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