예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        var      p         = new MVector3(1, 0, 0);
        var      aaaaa     = new UnityEngine.Quaternion(1, 1, 1, 1);
        var      ptemp     = new UnityEngine.Vector3(0.5f, 0, 0);
        var      a         = aaaaa * aaaaa * aaaaa * ptemp;
        Matrix33 rotation  = Matrix33.AngleAxis(45, new MVector3(0, 0, 1));
        Matrix33 rotation2 = Matrix33.AngleAxis(-45, new MVector3(0, 0, 1));

        Debug.Log(p * rotation);
        Debug.Log(p * rotation * rotation2);
        Debug.Log(p * (rotation * rotation2));

        Debug.Log("-------------------------------------------------------------");
        Matrix44 mul = Matrix44.AngleAxisTranslate(45, new MVector3(0, 0, 1), new MVector3(1, 1, 0));

        Debug.Log(p * mul);
        Debug.Log(p * (mul * mul.Inverse()));

        Debug.Log("-------------------------------------------------------------");
        Matrix44 r          = Matrix44.AngleAxis(45, new MVector3(0, 0, 1));
        Matrix44 t          = Matrix44.Translate(new MVector3(1, 1, 0));
        Matrix44 composite  = r * t;
        Matrix44 composite2 = t.Inverse() * r.Inverse();

        Debug.Log(p * composite);
        Debug.Log(p * composite * composite2);
        Debug.Log(p * composite * composite.Inverse());

        mMesh     = GetComponent <MeshFilter>().mesh;
        mVertices = mMesh.vertices;
        mNormals  = mMesh.normals;


        var temp = new Matrix33(10, 0, 0, 0, 10, 0, 0, 0, 1);

        var temp2       = temp.Inverse();
        var tempInverse = new Matrix33(0, 0, 0, 0, 0, 0, -3, -4, 1);

        p   = new MVector3(0, 0, 1);
        p   = p * temp;
        p.z = 1;
        p   = p * tempInverse;
        var t3 = temp * tempInverse;

        t = Matrix44.Translate(new MVector3(3, 4, 5));
        r = Matrix44.AngleAxis(30, new MVector3(0, 1, 0));
        var s = Matrix44.Scale(new MVector3(0.5f, 2, 1));

        p = new MVector3(1, 1, 1);
        var p1 = p * s * r * t;

        p = p1 * t.Inverse() * r.Inverse() * s.Inverse();

        var ray2d1 = new MRay(new MVector3(1, -1, 0), new MVector3(1, 1, 0));

        var   aaa  = ray2d1.GetNearestPos(new MVector3(1, 1, 0));
        float aaaa = 1;

        var plane1 = new MPlane(new MVector3(1, 1, 1), 1);
        var pos1   = plane1.GetNearestPos(new MVector3(5, 5, 5));
        var pos2   = plane1.GetNearestPos(new MVector3(-5, -5, -5));

        var plane2 = new MPlane(new MVector3(-1, -1, -1), -1);
        var pos3   = plane2.GetNearestPos(new MVector3(5, 5, 5));
        var pos4   = plane2.GetNearestPos(new MVector3(-5, -5, -5));

        var plane3 = new MPlane(new MVector3(-1, -1, -1), 1);
        var pos5   = plane3.GetNearestPos(new MVector3(5, 5, 5));
        var pos6   = plane3.GetNearestPos(new MVector3(-5, -5, -5));

        // 三角形测试
        pos1 = new MVector3(0, 0, 3);
        pos2 = new MVector3(0, 1, 3);
        pos3 = new MVector3(1, 0, 3);
        var triangle1 = new Triangle(pos1, pos2, pos3);
        var result    = triangle1.InclusionPos(pos1);
        var targetPos = MVector3.zero;

        result = triangle1.InclusionPos(pos2);
        result = triangle1.GetGravityPos(pos2, out targetPos);
        result = triangle1.InclusionPos(pos3);
        result = triangle1.GetGravityPos(pos3, out targetPos);
        float dis = 0;

        result = triangle1.Raycast(new MRay(new MVector3(0.4f, 0.6f, -0.2567f), new MVector3(0, 0, 1)), out dis);
        pos4   = new MVector3(0.5f, 0.5f, 3);
        result = triangle1.InclusionPos(pos4);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        pos4   = new MVector3(0.4f, 0.4f, 0.1f);
        result = triangle1.InclusionPos(pos4);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        pos4   = new MVector3(0.6f, 0.6f, 3);
        result = triangle1.InclusionPos(pos4);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        pos4   = new MVector3(-0.1f, -0.1f, 3);
        result = triangle1.InclusionPos(pos4);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.GetGravityPos(pos4, out targetPos);
        result = triangle1.InclusionPos(pos3);
        result = triangle1.GetGravityPos(pos3, out targetPos);
        result = triangle1.GetGravityPos(pos3, out targetPos);
        var tempxxx = 0;

        Circle2D c1 = new Circle2D(MVector2.zero, 1);
        var      t1 = c1.GetNearestPos(new MVector2(2, 0));
        var      t2 = c1.GetNearestPos(new MVector2(0.5f, 0));

        tempxxx = 0;

        var      r1 = new MRay2D(new MVector2(1, 1), new MVector2(0, -1));
        var      r2 = new MRay2D(new MVector2(10, 0), new MVector2(1, 0));
        MVector2 r12v;
        bool     r12r = r1.Interact(r2, out r12v);

        float c10, c11;
        bool  r10 = c1.IntersectRay(r1, out c10, out c11);

        tempxxx = 0;
    }