Beispiel #1
0
        static void test_tostring()
        {
            test_name("ToString");

            Vec3d v3d = new Vec3d(0.1, 0.2, 0.3);

            //string s = v3d.ToString();
/**/ put("ToString", "(0.1, 0.2, 0.3)", v3d.ToString());
/**/ System.Console.WriteLine("ToString: implicit ToString call           : " + v3d);

            PHSceneDesc descScene = new PHSceneDesc();
            PHSolidDesc descSolid = new PHSolidDesc();
            PHSdkIf     phSdk     = PHSdkIf.CreateSdk();
            PHSceneIf   phScene   = phSdk.CreateScene(descScene);
            PHSolidIf   phSolid   = phScene.CreateSolid(descSolid);

            phSolid.SetPose(new Posed(1, 0, 0, 0, 0, 2, 0));
            put_title("ToString: phSolid");
            put_indent(2, phSolid.ToString());

            FWWinBaseDesc descWinBase = new FWWinBaseDesc();
            FWSdkIf       fwSdk       = FWSdkIf.CreateSdk();

            put_title("ToString: fwSdk.ToString");
            put_indent(2, fwSdk.ToString());
        }
Beispiel #2
0
        static void test_intrinsic()
        {
            test_name("intrinsic");

            // intrinsic member
            PHSceneDesc     descScene  = new PHSceneDesc();
            PHRaycastHit    raycastHit = new PHRaycastHit();
            GRVertexElement vertexelm  = new GRVertexElement();

            // simple
            vertexelm.offset            = 123;              put("short ", "123  ", vertexelm.offset);
            descScene.numIteration      = 123;        put("int   ", "123  ", descScene.numIteration);
            descScene.bCCDEnabled       = true;        put("bool  ", "True ", descScene.bCCDEnabled);
            raycastHit.distance         = 0.123F;        put("float ", "0.123", raycastHit.distance);
            descScene.airResistanceRate = 0.123; put("double", "0.123", descScene.airResistanceRate);
            // nested
            descScene.gravity.x = 0;
            descScene.gravity.y = 0;
            descScene.gravity.z = -4.5;
/**/ put("set by elm", "(0.0, 0.0, -4.5)", descScene.gravity);
            descScene.gravity = new Vec3d(2.5, -5.2, 0.5);
/**/ put("set struct", "(2.5, -5.2, 0.5)", descScene.gravity);
            // structure
            Vec3d v3d = new Vec3d(0.1, 0.2, 0.3);

            put("Vec new", "(0.1, 0.2, 0.3)", v3d);
            put("Vec * c", "(0.2, 0.4, 0.6)", v3d * 2);
            put("c * Vec", "(0.2, 0.4, 0.6)", 2 * v3d);
            Posed pose = new Posed(new Vec3d(1, 2, 3), new Quaterniond(1, 0, 0, 0));

            put2("pose", new Posed(1, 0, 0, 0, 1, 2, 3), pose);
        }
Beispiel #3
0
    // UnityのOnValidate : SprBehaviourのものをオーバーライド
    public override void OnValidate()
    {
        if (GetDescStruct() == null)
        {
            ResetDescStruct();
        }

        if (sprObject != null)
        {
            // PHSceneの設定
            {
                PHSceneDesc d = new PHSceneDesc();
                phScene.GetDesc(d);
                desc.ApplyTo(d);
                phScene.SetDesc(d);
            }

            // PHIKEngineの設定
            {
                PHIKEngineDesc d = new PHIKEngineDesc();
                phScene.GetIKEngine().GetDesc(d);
                descIK.ApplyTo(d);
                phScene.GetIKEngine().SetDesc(d);
            }

            // DescではなくStateに含まれる変数。ApplyToで自動同期されないので手動で設定
            phScene.SetTimeStep(desc.timeStep);
            phScene.SetHapticTimeStep(desc.haptictimeStep);

            // IKの有効・無効の切り替え
            phScene.GetIKEngine().Enable(enableIK);
        }

        ApplyCollisionList();
    }
Beispiel #4
0
        static void Main(string[] args)
        {
            PHSceneDesc descScene = new PHSceneDesc();

            descScene.airResistanceRate = 0.5;
            descScene.gravity           = new Vec3d(0, 0, -4.5);

            System.Console.WriteLine(descScene.gravity);
        }
Beispiel #5
0
        static void test_simulation()
        {
            test_name("physical simulation");

            PHSceneDesc descScene = new PHSceneDesc();
            PHSolidDesc descSolid = new PHSolidDesc();
            CDBoxDesc   descBox   = new CDBoxDesc();
            PHSdkIf     phSdk     = PHSdkIf.CreateSdk();
            PHSceneIf   phScene   = phSdk.CreateScene(descScene);
            PHSolidIf   phSolid   = phScene.CreateSolid(descSolid);

            phSolid.AddShape(phSdk.CreateShape(CDBoxIf.GetIfInfoStatic(), descBox));
            phSolid.SetPose(new Posed(1, 0, 0, 0, 0, 2, 0));

            PHSolidIf phFloor = phScene.CreateSolid(descSolid);

            phFloor.SetDynamical(false);
            descBox.boxsize = new Vec3f(10, 10, 10);
            phFloor.AddShape(phSdk.CreateShape(CDBoxIf.GetIfInfoStatic(), descBox));
            phFloor.SetPose(new Posed(1, 0, 0, 0, 0, -5, 0));

            PHBallJointDesc descJoint = new PHBallJointDesc();
            PHBallJointIf   j         = phScene.CreateJoint(phFloor, phSolid, PHBallJointIf.GetIfInfoStatic(), descJoint).Cast();

            System.Console.WriteLine(j.GetName());

            PHIKBallActuatorDescStruct s = new PHIKBallActuatorDesc();

            put("bias", "something", s.bias);

            /**/
            for (int i = 0; i < 200; i++)
            {
                phScene.Step();
                //System.Console.WriteLine(i.ToString() + " : " + phSolid.GetPose());
                System.Console.WriteLine(String.Format("{0, 3}", i) + " : " + phSolid.GetPose());
            }
            /**/
        }
Beispiel #6
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]);
            }
        }
Beispiel #7
0
        static void test_type_conv()
        {
            test_name("type conversion");

            string msg_f3 = "f2d: (1, 2, 3)";
            string msg_d3 = "d2f: (4, 5, 6)";

            Vec3f f3 = new Vec3f(1, 2, 3);
            Vec3d d3 = new Vec3d(4, 5, 6);

            put("type_conv", msg_f3, f3);
//            print_vec3f(d3, msg_f3);    // This cause CS1502 and CS1503 compile error. <- OK
            put("type_conv", msg_d3, (Vec3f)d3);

            Vec3fStruct f3s = f3;
            Vec3dStruct d3s = d3;

            put("type_conv", msg_f3, "(" + f3s.x + ", " + f3s.y + ", " + f3s.z + ")");
//            print_vec3fs(d3s, msg_d3);  // This cause CS1502 and CS1503 compile error. <- OK
            put("type_conv", msg_d3,
                "(" + ((Vec3fStruct)d3s).x + ", " + ((Vec3fStruct)d3s).y + ", " + ((Vec3fStruct)d3s).z + ")");

            // -----
            // 戻り値の自動型変換のテスト
            PHSdkIf   phSdk   = PHSdkIf.CreateSdk();
            CDBoxDesc descBox = new CDBoxDesc();

            descBox.boxsize = new Vec3f(1, 4, 9);
            CDShapeIf shape = phSdk.CreateShape(CDBoxIf.GetIfInfoStatic(), descBox);
            // ↑ CreateShapeはCDBoxIfオブジェクトを返す。それをCDShapeIfで受ける。

            // CDShapeIf型の変数に格納されているが中身はCDBoxIfなので型変換可能。
            CDBoxIf box = shape as CDBoxIf;

            put("type_conv", "(1, 4, 9)", box.GetBoxSize().ToString());

            // CDBoxIf is not a CDSphereIf なので nullになることが期待される。
            CDSphereIf sphere = shape as CDSphereIf;

            if (sphere == null)
            {
                put("type_conv", "null", "null");
            }
            else
            {
                put("type_conv", "null", sphere.ToString());
            }

            // CDBoxIf is a CDConvexIf なのでnullにはならず型変換される。
            CDConvexIf convex = shape as CDConvexIf;

            if (convex == null)
            {
                put("type_conv", "not null", "null");
            }
            else
            {
                put("type_conv", "not null", convex.ToString());
            }

            // -----
            PHSceneDesc descScn = new PHSceneDesc();
            PHSceneIf   scene   = phSdk.CreateObject(PHSceneIf.GetIfInfoStatic(), descScn) as PHSceneIf;

            System.Console.WriteLine((scene == null) ? "null" : scene.ToString());

            // constructor による初期値設定のテスト
            // ---- State を継承 ----
            // 暗黙の型変換による
            PHSceneDescStruct structScene1 = new PHSceneDesc();
            Vec3d             v3d1         = new Vec3d(0.0, -9.8, 0.0);
            Vec3d             v3d2         = new Vec3d(1.0, -8.8, 1.0);

            put("by typeconv:    gravity ", edit_vector(v3d1), edit_vector(structScene1.gravity));
            put("by typeconv:    timeStep", "0.005", structScene1.timeStep);
            // constructor による
            PHSceneDescStruct structScene2 = new PHSceneDescStruct();

            put("by constructor: gravity ", edit_vector(v3d1), edit_vector(structScene2.gravity));
            put("by constructor: timeStep", "0.005", structScene2.timeStep);
            // ApplyFrom による
            PHSceneDescStruct structScene3 = new PHSceneDescStruct();

            structScene3.gravity  = v3d2;
            structScene3.timeStep = 1.001;
            put("by Apply(): fm: gravity ", edit_vector(v3d2), edit_vector(structScene3.gravity));
            put("by Apply(): fm: timeStep", "1.001", structScene3.timeStep);
            structScene2.ApplyFrom((PHSceneDesc)structScene3);
            put("by Apply(): to: gravity ", edit_vector(v3d2), edit_vector(structScene2.gravity));
            put("by Apply(): to: timeStep", "0.005", structScene2.timeStep);
            //
            // ---- Desc を継承 ----
            CDSphereDescStruct structSphere1 = new CDSphereDescStruct();
            CDSphereDesc       descSphere1   = structSphere1;
            CDSphereDescStruct structSphere2 = new CDSphereDescStruct();
            CDSphereDesc       descSphere2   = structSphere2;

            descSphere2.radius           = 2;
            descSphere2.material.density = 2;
            //
            put("DescStruct: radius      ", "1", structSphere1.radius);
            put("DescStruct: base.density", "1", structSphere1.material.density);
            structSphere1.ApplyFrom(descSphere2);
            put("ApplyFrom:");
            put("DescStruct: radius      ", "2", structSphere1.radius);
            put("DescStruct: base.density", "1", structSphere1.material.density);
            structSphere1 = descSphere2;
            put("assignment:");
            put("DescStruct: radius      ", "2", structSphere1.radius);
            put("DescStruct: base.density", "2", structSphere1.material.density);
            //
            descSphere2.radius           = 3;
            descSphere2.material.density = 3;
            structSphere1.ApplyFrom(descSphere2);
            put("ApplyTo:");
            put("DescStruct: radius      ", "3", structSphere1.radius);
            put("DescStruct: base.density", "2", structSphere1.material.density);
            structSphere1.material.density = 3;
            descSphere1 = structSphere2;
            put("assignment:");
            put("DescStruct: radius      ", "3", structSphere1.radius);
            put("DescStruct: base.density", "3", structSphere1.material.density);

            //
            // ---- 比較 ----
            Vec3d v3d_c11 = new Vec3d(1, 2, 3);
            Vec3d v3d_c12 = new Vec3d(1, 2, 3);
            Vec3d v3d_c21 = new Vec3d(4, 5, 6);

            put("compare: ==, same", "True ", v3d_c11 == v3d_c12);
            put("compare: ==, diff", "False", v3d_c11 == v3d_c21);
            put("compare: ==, null", "False", v3d_c11 == null);
            put("compare: ==, null", "False", null == v3d_c11);
            put("compare: !=, same", "False", v3d_c11 != v3d_c12);
            put("compare: !=, diff", "True ", v3d_c11 != v3d_c21);
            put("compare: !=, null", "True ", v3d_c11 != null);
            put("compare: !=, null", "True ", null != v3d_c11);
            vectorwrapper_int vw11 = new vectorwrapper_int((IntPtr)0);
            vectorwrapper_int vw12 = new vectorwrapper_int((IntPtr)0);
            vectorwrapper_int vw21 = new vectorwrapper_int((IntPtr)1);

            put("compare: ==, wrap", "True ", vw11 == vw12);
            put("compare: ==, wrap", "False", vw11 == vw21);
            put("compare: ==, null", "False", vw11 == null);
            put("compare: ==, null", "False", null == vw21);
            put("compare: !=, wrap", "False", vw11 != vw12);
            put("compare: !=, wrap", "True ", vw11 != vw21);
            put("compare: !=, null", "True ", vw11 != null);
            put("compare: !=, null", "True ", null != vw21);
        }
Beispiel #8
0
    // UnityのOnValidate : SprBehaviourのものをオーバーライド
    public override void OnValidate()
    {
        if (GetDescStruct() == null)
        {
            ResetDescStruct();
        }

        if (sprObject != null)
        {
            // PHSceneの設定
            {
                PHSceneDesc d = new PHSceneDesc();
                phScene.GetDesc(d);
                desc.ApplyTo(d);
                phScene.SetDesc(d);
            }

            // PHIKEngineの設定
            {
                PHIKEngineDesc d = new PHIKEngineDesc();
                phScene.GetIKEngine().GetDesc(d);
                descIK.ApplyTo(d);
                phScene.GetIKEngine().SetDesc(d);
            }

            // DescではなくStateに含まれる変数。ApplyToで自動同期されないので手動で設定
            phScene.SetTimeStep(desc.timeStep);
            phScene.SetHapticTimeStep(desc.haptictimeStep);

            // IKの有効・無効の切り替え
            phScene.GetIKEngine().Enable(enableIK);
        }

        // <!!> PHJointBehaviourのdisableCollisionと衝突するので要検討
        if (sprObject != null)
        {
            for (int i = 0; i < collision.Count; i++)
            {
                CollisionSetting c = collision[i];
                if (c.solid1 == null && c.solid2 == null)
                {
                    phScene.SetContactMode(c.mode);
                }
                else if (c.solid1 == null)
                {
                    if (c.solid2.sprObject != null)
                    {
                        phScene.SetContactMode(c.solid2.phSolid, c.mode);
                    }
                }
                else if (c.solid2 == null)
                {
                    if (c.solid1.sprObject != null)
                    {
                        phScene.SetContactMode(c.solid1.phSolid, c.mode);
                    }
                }
                else
                {
                    if (c.solid1.sprObject != null && c.solid2.sprObject != null)
                    {
                        phScene.SetContactMode(c.solid1.phSolid, c.solid2.phSolid, c.mode);
                    }
                }
            }
        }
    }