예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Vector Addition : " + v1 + " Plus " + v2 + " Equals " + VectorMathLib.vectorAddition3D(v1, v2));
        Debug.Log("Vector Substraction : " + v1 + " Minus " + v2 + " Equals " + VectorMathLib.vectorSubtraction3D(v1, v2));


        Debug.Log("Vector Dot Product : " + v1 + " . " + v2 + " Equals " + VectorMathLib.dotProduct3D(v1, v2));


        Debug.Log("Unit Vector : " + " Unit Vector of " + v2 + " Equals " + VectorMathLib.unitVector3DVector(v2));



        Debug.Log("Vector Reflection(Axis Aligned) : " + " The Reflection of " + v2 + " on the x Axis is " + VectorMathLib.vectorReflectionAxisAligned2D(v2, true, false));


        Debug.Log("Cartesian to Polar : " + " The Polar Corfinates of " + v1 + " is " + VectorMathLib.cartesianToPolar(v1));

        Debug.Log("Polar to Cartesian : " + " The Cartesian Corfinates of " + (4.5f, 12.0f) + " is " + VectorMathLib.polarToCartesian(4.5f, 12.0f));


        Debug.Log("Unit Direction Vector : " + " The Unit Direction Vector of " + v1 + " and " + v2 + "is" + VectorMathLib.getUnitDirectionVector(v1, v2));


        Debug.Log("Magnitude of 3D Vector: " + " The Unit Magnitude of " + v1 + "is" + VectorMathLib.magnitude3DVector(v1));


        Debug.Log("Scaler Multiple of 3D Vector: " + " The Scalar Multiple of 3D Vector " + v1 + "by" + 20.0f + "is" + VectorMathLib.scalerMultiple3DVector(v1, 20.0f));


        Debug.Log("Vectors nearly equal with radius: " + " Cheking if " + v1 + "and" + v2 + "are close by an ammount of:" + 10.0f + ":" + VectorMathLib.vectorsNearlyEquals(v1, v2, 10.0f));

        Debug.Log("Zero Vector" + VectorMathLib.zeroVector3D());
    }
예제 #2
0
    void Update()
    {
        x1 = transform.position;
        x2 = ball2.transform.position;

        time            = Time.deltaTime;
        frictionVector  = -VectorMathLib.scalerMultiple3DVector(VectorMathLib.unitVector3DVector(v1), coefficentOfFriction);
        frictionVector2 = -VectorMathLib.scalerMultiple3DVector(VectorMathLib.unitVector3DVector(v2), coefficentOfFriction);


        if (x1.z > 25.0f)
        {
            print("Hit Wall Top");
            v1.z = -v1.z;
            x1   = new Vector3(x1.x, x1.y, 25.0f - (x1.z - 25.0f));
            print(VectorMathLib.magnitude3DVector(v1));
        }
        else if (x1.z < -25.0f)
        {
            print("Hit Wall Top");
            v1.z = -v1.z;
            x1   = new Vector3(x1.x, x1.y, -25.0f + (-x1.z - 25.0f));
            print(VectorMathLib.magnitude3DVector(v1));
        }
        else if (x1.x > 25.0f)
        {
            print("Hit Wall Top");
            v1.x = -v1.x;
            x1   = new Vector3(25.0f - (x1.x - 25.0f), x1.y, x1.z);
            print(VectorMathLib.magnitude3DVector(v1));
        }
        else if (x1.x < -25.0f)
        {
            print("Hit Wall Top");
            v1.x = -v1.x;
            x1   = new Vector3(-25.0f + (-x1.x - 25.0f), x1.y, x1.z);
            print(VectorMathLib.magnitude3DVector(v1));
        }


        if (x2.z > 25.0f)
        {
            print("Hit Wall Top");
            v2.z = -v2.z;
            x2   = new Vector3(x2.x, x2.y, 25.0f - (x2.z - 25.0f));
            print(VectorMathLib.magnitude3DVector(v2));
        }
        else if (x2.z < -25.0f)
        {
            print("Hit Wall Top");
            v2.z = -v2.z;
            x2   = new Vector3(x2.x, x2.y, -25.0f + (-x2.z - 25.0f));
            print(VectorMathLib.magnitude3DVector(v2));
        }
        else if (x2.x > 25.0f)
        {
            print("Hit Wall Top");
            v2.x = -v2.x;
            x2   = new Vector3(25.0f - (x2.x - 25.0f), x2.y, x2.z);
            print(VectorMathLib.magnitude3DVector(v2));
        }
        else if (x2.x < -25.0f)
        {
            print("Hit Wall Top");
            v2.x = -v2.x;
            x2   = new Vector3(-25.0f + (-x2.x - 25.0f), x2.y, x2.z);
            print(VectorMathLib.magnitude3DVector(v2));
        }



        if ((VectorMathLib.magnitude3DVector(x1 - x2) <= 1.0f) & whiteHitsRed)
        {
            print("v1" + v1);
            print("v2" + v2);

            v1_1 = v1 - VectorMathLib.dotProduct3D(v1 - v2, x1 - x2) * (x1 - x2) / Mathf.Pow(VectorMathLib.magnitude3DVector(x1 - x2), 2);
            v2_1 = v2 - VectorMathLib.dotProduct3D(v2 - v1, x2 - x1) * (x2 - x1) / Mathf.Pow(VectorMathLib.magnitude3DVector(x2 - x1), 2);

            whiteHitsRed = false;

            print("v1-2" + v1_1);
            print("v2-2" + v2_1);

            v1_1 += frictionVector * time;
            v2_1 += frictionVector2 * time;

            print("3" + x1);
            x1 += v1_1 * time + frictionVector * Mathf.Pow(time, 2) / 2;
            print("4" + x2);
            x2 += v2_1 * time + frictionVector2 * Mathf.Pow(time, 2) / 2;

            v1 = v1_1;
            v2 = v2_1;
        }

        else
        {
            v1 += frictionVector * time;

            v2 += frictionVector2 * time;
            x1 += v1 * time + frictionVector * Mathf.Pow(time, 2) / 2;
            x2 += v2 * time + frictionVector * Mathf.Pow(time, 2) / 2;
        }

        transform.position       = x1;
        ball2.transform.position = x2;
    }