CCD自体は魔法のように機能します。3D で作業している場合は、まず、ボーンの制限を適用せずに各軸で行うべき回転を見つけます。
その後のアプローチは
expectedRotation.X = min(expectedRotation.X, maxLimit.X)
expectedRotation.X = max(expectedRotation.X, minLimit.X)
expectedRotation.Y = min(expectedRotation.Y, maxLimit.Y)
expectedRotation.Y = max(expectedRotation.Y, minLimit.Y)
expectedRotation.Z = min(expectedRotation.Z, maxLimit.Z)
expectedRotation.Z = max(expectedRotation.Z, minLimit.Z)
間違っています。軸の 1 つをさらに移動できない場合、他の 2 つの軸が移動し続け、奇妙な結果が得られるためです。
修正:
3 つの軸のいずれかが制限制約と一致しない場合は、回転をまったく変更してはなりません。
まず、すべての角度を -180 から 180 の形式で度に変換します。次に、次のようにします
vector3df angleDifference = expectedRotation - baseRotation; //baseRotation is just the initial rotation from which the bone limits are calculated.
if(angleDifference.X < boneLimits.minRotation.X || angleDifference.Y < boneLimits.minRotation.Y || angleDifference.Z < boneLimits.minRotation.Z || angleDifference.X > boneLimits.maxRotation.X || angleDifference.Y > boneLimits.maxRotation.Y || angleDifference.Z > boneLimits.maxRotation.Z)
return currentRotation;
return expectedRotation;