コード例 #1
0
    public void UpdateIKTargetPosition()
    {
        if (iktarget != null)
        {
            if (sprObject != null)
            {
                PHIKEndEffectorIf phIKee = sprObject as PHIKEndEffectorIf;
                if (phIKee.GetOriCtlMode() == PHIKEndEffectorDesc.OriCtlMode.MODE_LOOKAT)
                {
                    phIKee.SetTargetLookat(iktarget.transform.position.ToVec3d());
                }
                else
                {
                    phIKee.SetTargetPosition(iktarget.transform.position.ToVec3d());

                    // 現在の姿勢からの回転角がより少ない方のQuaternionに変換
                    Quaterniond qT    = iktarget.transform.rotation.ToQuaterniond();
                    Quaterniond qDiff = qT * phIKee.GetSolid().GetPose().Ori().Inv();
                    qDiff = Quaterniond.Rot(qDiff.RotationHalf());
                    qT    = qDiff * phIKee.GetSolid().GetPose().Ori();
                    phIKee.SetTargetOrientation(qT);
                }
            }
        }

        if (ikLocalTarget != null)
        {
            if (sprObject != null)
            {
                Vec3d targetLocalPos = gameObject.transform.ToPosed().Inv() * ikLocalTarget.transform.position.ToVec3d();
                phIKEndEffector.SetTargetLocalPosition(targetLocalPos);
            }
        }
    }