// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // SprBehaviourの派生クラスで実装するメソッド // -- DescStructオブジェクトを再構築する public override void ResetDescStruct() { desc = new PHSceneDescStruct(); desc.timeStep = Time.fixedDeltaTime; // 初期値ではUnityに合わせておく descIK = new PHIKEngineDescStruct(); descIK.regularizeParam = 0.1f; }
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); }