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()); }
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()); } /**/ }
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]); } }
// -- 全てのBuildが完了した後に行う処理を書く。オブジェクト同士をリンクするなど public override void Link() { if (sprObject == null) { return; } // 慣性テンソルを自動決定する if (autoSetInertiaTensor && phSolid.NShape() > 0) { float totalVolume = 0; for (int i = 0; i < phSolid.NShape(); i++) { var shape = phSolid.GetShape(i); totalVolume += shape.CalcVolume(); } for (int i = 0; i < phSolid.NShape(); i++) { var shape = phSolid.GetShape(i); shape.SetDensity((float)(phSolid.GetMass()) / totalVolume); } phSolid.CompInertia(); // -- // <!!> SpineとShoulderはCompInertiaすると落ちるのでデバッグ中 /* * if (name == "Spine" || name.Contains("Shoulder")) { * var I = phSolid.GetInertia(); * string str = name + " : \r\n"; * for (int i = 0; i < 3; i++) { * for (int j = 0; j < 3; j++) { * str += I[i][j].ToString("F4") + ", "; * } * str += "\r\n"; * } * * CDRoundConeIf rc = phSolid.GetShape(0) as CDRoundConeIf; * if (rc != null) { * float mass = (float)(phSolid.GetMass()); * float radius = (rc.GetRadius().x + rc.GetRadius().y) * 0.5f; * float length = rc.GetLength() + rc.GetRadius().x + rc.GetRadius().y; * float Ix = 0.5f * mass * radius * radius; * float Iy = mass * ((radius * radius / 4.0f) + (length * length / 12.0f)); * float Iz = Iy; * phSolid.SetInertia(new Matrix3d(Ix, 0, 0, 0, Iy, 0, 0, 0, Iz)); * } * * I = phSolid.GetInertia(); * str += "\r\n"; * for (int i = 0; i < 3; i++) { * for (int j = 0; j < 3; j++) { * str += I[i][j].ToString("F4") + ", "; * } * str += "\r\n"; * } * Debug.Log(str); * } */ // -- PHSolidDesc desc_ = new PHSolidDesc(); phSolid.GetDesc(desc_); desc = desc_; } //float I = (float)(phSolid.GetMass()); //phSolid.SetInertia(new Matrix3d(I, 0, 0, 0, I, 0, 0, 0, I)); }