Esempio n. 1
0
    /// <summary>
    /// PHANTOM の周期(デフォルト1kHz)で繰り返し呼ばれるメソッド
    /// </summary>
    /// <description>この中ではPHANTOMの座標系/単位</description>
    /// <returns><c>true</c>, if update was phantomed, <c>false</c> otherwise.</returns>
    bool PhantomUpdate()
    {
        // 手先(ジンバル部分)の座標を取得 [mm]
        HandPosition = Phantom.GetPosition();

        // 手先の速度を取得 [mm/s]
        HandVelocity = Phantom.GetVelocity();

        // 手先姿勢を取得
        HandRotation = Phantom.GetRotation();

        // ペン先端の座標を取得 [mm]
        TipPosition = Phantom.GetTipPosition();


        // PHANTOMの発揮力 [N]
        Vector3 force = Vector3.zero;

        // 球体から受ける力を計算
        if (SphereList != null)
        {
            foreach (PhantomRigidSphere sphere in SphereList)
            {
                force += sphere.CalculateForce(TipPosition, HandVelocity);
            }
        }

        // 力の上限を超えないようにする
        if (force.sqrMagnitude > (MaxForce * MaxForce))
        {
            force.Normalize();
            force *= MaxForce;
        }

        // PHANTOMに対し力を指定
        Phantom.SetForce(force);

        return(true);
    }