示例#1
0
    // ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
    // CDShapeBehaviourの派生クラスで実装するメソッド

    // -- SpringheadのShapeオブジェクトを構築する
    public override CDShapeIf CreateShape(GameObject shapeObject)
    {
        Mesh mesh = shapeObject.GetComponent <MeshFilter>().mesh;

        // Verticesを除いて、Materialだけを持ってくる
        CDConvexMeshDesc d = new CDConvexMeshDesc();

        ApplyDesc(desc, d);

        // Initialize CDConvexMeshDesc by Unity Mesh
        for (int vi = 0; vi < mesh.vertices.Length; vi++)
        {
            Vector3 vU = mesh.vertices[vi];
            Vec3f   v  = new Vec3f();
            v.x = vU.x;
            v.y = vU.y;
            v.z = vU.z;
            d.vertices.push_back(v);
        }

        return(phSdk.CreateShape(CDConvexMeshIf.GetIfInfoStatic(), d));
    }
示例#2
0
        static void test_func_return()
        {
            test_name("function return");
            int memoryLeakTest = 0;

            PHSceneDesc descScene = new PHSceneDesc();
            PHSolidDesc descSolid = new PHSolidDesc();

            if (memoryLeakTest == 1)
            {
                return;
            }

            PHSdkIf phSdk = PHSdkIf.CreateSdk();        // ここでメモリリークする

            if (memoryLeakTest == 2)
            {
                return;
            }
            PHSceneIf phScene = phSdk.CreateScene(descScene);

            descSolid.mass    = 2.0;
            descSolid.inertia = new Matrix3d(2.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 2.0);
            PHSolidIf phSolid = phScene.CreateSolid(descSolid);

            descSolid.mass = 1e20f;

            descSolid.inertia = new Matrix3d(1e20f, 0.0, 0.0, 0.0, 1e20f, 0.0, 0.0, 0.0, 1e20f);
            PHSolidIf solid1 = phScene.CreateSolid(descSolid);

            PHHapticPointerDesc descHaptic = new PHHapticPointerDesc();
            PHHapticPointerIf   phHaptic   = phScene.CreateHapticPointer();

            //HISdkDesc descHi = new HISdkDesc();
            //HISdkIf hiSdk = HISdkIf.CreateSdk();

            put("ret int   ", "3    ", phScene.NSolids());
            for (int i = 0; i < 20; i++)
            {
                phScene.Step();
            }
            put("ret Uint  ", "20   ", phScene.GetCount());
            phHaptic.SetLocalRange(2.345f);
            put("ret float ", "2.345", phHaptic.GetLocalRange());
            put("ret double", "0.005", phScene.GetTimeStep());
            phScene.SetMaxVelocity(1.23);
            put("ret double", "0.123", phScene.GetMaxVelocity());
            phScene.EnableContactDetection(false);
            put("ret bool  ", "False", phScene.IsContactDetectionEnabled());
            phScene.EnableContactDetection(true);
            put("ret bool  ", "True ", phScene.IsContactDetectionEnabled());
            put("ret size_t", "152? ", phScene.GetDescSize());
            put("ret Vec3d ", "(0.0, -9.8, 0.0)", phScene.GetGravity());
            phScene.SetGravity(new Vec3d(0.1, -9.9, 0.2));
            put("ret Vec3d ", "(0.1, -9.9, 0.2)", phScene.GetGravity());

            // function returns array by using pointer
            CDConvexMeshDesc descMesh = new CDConvexMeshDesc();

            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    for (int z = 0; z < 10; z++)
                    {
                        Vec3f v3f = new Vec3f(x, y, z);
                        descMesh.vertices.push_back(new Vec3f(x, y, z));
                    }
                }
            }
            //PHSdkIf phSdk = PHSdkIf.CreateSdk();
            CDConvexMeshIf mesh = phSdk.CreateShape(CDConvexMeshIf.GetIfInfoStatic(), descMesh) as CDConvexMeshIf;

            mesh.GetVertices();
            arraywrapper_Vec3f vertices = mesh.GetVertices();

            Vec3f[] v3fr = new Vec3f[8];
            v3fr[0] = new Vec3f(0, 0, 0); v3fr[1] = new Vec3f(0, 0, 9);
            v3fr[2] = new Vec3f(0, 9, 0); v3fr[3] = new Vec3f(0, 9, 9);
            v3fr[4] = new Vec3f(9, 0, 0); v3fr[5] = new Vec3f(9, 0, 9);
            v3fr[6] = new Vec3f(9, 9, 0); v3fr[7] = new Vec3f(9, 9, 9);
            for (int i = 0; i < 8; i++)
            {
                put("ret_array", edit_vector(v3fr[i]), vertices[i]);
            }
        }
示例#3
0
        static void test_array()
        {
            test_name("array");

            PHOpObjDesc descOpObj = new PHOpObjDesc();
            GRMeshFace  meshFace  = new GRMeshFace();

            for (int i = 0; i < 4; i++)
            {
                meshFace.indices[i] = 100 + i;
            }
            for (int i = 0; i < 4; i++)
            {
                System.Console.WriteLine("array<int>: expected: " + (100 + i) + " result: " + meshFace.indices[i]);
            }
            arraywrapper_int iarray = new arraywrapper_int(4);

            for (int i = 0; i < 4; i++)
            {
                meshFace.indices[i] = 200 + i;
            }
            string[]            strsrc = { "abc", "def", "gh", "jklm" };
            arraywrapper_char_p icharp = new arraywrapper_char_p(4);

            for (int i = 0; i < 4; i++)
            {
                icharp[i] = strsrc[i];
            }
            for (int i = 0; i < 4; i++)
            {
                put("array<char*>", strsrc[i], icharp[i]);
            }
            meshFace.indices = iarray;
            for (int i = 0; i < 4; i++)
            {
                System.Console.WriteLine("array<int>: expected: " + (200 + i) + " result: " + meshFace.indices[i]);
            }
            //Vec3i v3i = new Vec3i(1, 2, 3);
            //System.Console.WriteLine("array<int> alloc(3): result:   " + v3i);
            //v3i.alloc(2);
            //for (int i = 0; i < 2; i++) {
            //    v3i[i].x = 10 * (i + 1);
            //    v3i[i].y = 10 * (i + 1);
            //    v3i[i].z = 10 * (i + 1);
            //}
            //System.Console.WriteLine("                     expected: " + "((10, 10, 10), (20, 20, 20))");
            //System.Console.WriteLine("                     result:   " + v3i);

            CDConvexMeshDesc descMesh = new CDConvexMeshDesc();

            for (int x = 0; x < 10; x++)
            {
                for (int y = 0; y < 10; y++)
                {
                    for (int z = 0; z < 10; z++)
                    {
                        descMesh.vertices.push_back(new Vec3f(x, y, z));
                    }
                }
            }
            PHSdkIf        phSdk    = PHSdkIf.CreateSdk();
            CDConvexMeshIf mesh     = phSdk.CreateShape(CDConvexMeshIf.GetIfInfoStatic(), (CDConvexMeshDesc)descMesh) as CDConvexMeshIf;
            var            vertices = mesh.GetVertices();

            for (int i = 0; i < mesh.NVertex(); i++)
            {
                put_indent(2, vertices[i]);
            }
        }