Пример #1
0
    // Springhead剛体とGameObjectの間での位置姿勢の同期: 更新順を制御するためPHSceneからまとめて呼び出す
    public void UpdatePose()
    {
        if (sprObject != null)
        {
            PHSolidIf so = sprObject as PHSolidIf;
            if (fixedSolid)
            {
                // Fixedな剛体はHandleの位置をSpringheadに反映
                so.SetPose(new Posed(fixedSolidPosition.ToVec3d(), fixedSolidRotation.ToQuaterniond()));
                gameObject.transform.position = fixedSolidPosition;
                gameObject.transform.rotation = fixedSolidRotation;
            }
            else
            {
                // Fixedでない剛体の場合

                if (!so.IsDynamical())
                {
                    // Dynamicalでない剛体はUnityの位置をSpringheadに反映(操作可能)
                    so.SetPose(gameObject.transform.ToPosed());
                }
                else
                {
                    // Dynamicalな剛体はSpringheadのシミュレーション結果をUnityに反映
                    gameObject.transform.FromPosed(so.GetPose());
                }

                fixedSolidPosition = gameObject.transform.position;
                fixedSolidRotation = gameObject.transform.rotation;
            }
        }
    }
Пример #2
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());
        }
Пример #3
0
 // Springhead剛体とGameObjectの間での位置姿勢の同期: 更新順を制御するためPHSceneからまとめて呼び出す
 public void UpdatePose()
 {
     if (sprObject != null)
     {
         PHSolidIf so = sprObject as PHSolidIf;
         if (!so.IsDynamical() && !fixedSolid)
         {
             // Dynamicalでない(かつ、fixedでもない)剛体はUnityの位置をSpringheadに反映(操作可能)
             so.SetPose(gameObject.transform.ToPosed());
         }
         else
         {
             // Dynamicalな(もしくはfixedな)剛体はSpringheadのシミュレーション結果をUnityに反映
             gameObject.transform.FromPosed(so.GetPose());
         }
     }
 }
Пример #4
0
    // -- Sprオブジェクトの構築を行う
    public override ObjectIf Build()
    {
        PHSolidIf so = phScene.CreateSolid(desc);

        so.SetName("so:" + gameObject.name);
        so.SetPose(gameObject.transform.ToPosed());

        // Scene Hierarchyでの深さを取得した上でPHSceneBehaviourに登録
        var t = transform;

        while (t.parent != null)
        {
            treeDepth++; t = t.parent;
        }
        phSceneBehaviour.RegisterPHSolidBehaviour(this);

        UpdateCenterOfMass();

        return(so);
    }
Пример #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());
            }
            /**/
        }