當前位置: 首頁>>代碼示例>>C#>>正文


C# Bone.worldToLocal方法代碼示例

本文整理匯總了C#中Spine.Bone.worldToLocal方法的典型用法代碼示例。如果您正苦於以下問題:C# Bone.worldToLocal方法的具體用法?C# Bone.worldToLocal怎麽用?C# Bone.worldToLocal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Spine.Bone的用法示例。


在下文中一共展示了Bone.worldToLocal方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: apply

 /// <summary>Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as
 /// possible. The target is specified in the world coordinate system.</summary>
 /// <param name="child">Any descendant bone of the parent.</param>
 public static void apply(Bone parent, Bone child, float targetX, float targetY, int bendDirection, float alpha)
 {
     float childRotation = child.rotation, parentRotation = parent.rotation;
     if (alpha == 0) {
         child.rotationIK = childRotation;
         parent.rotationIK = parentRotation;
         return;
     }
     float positionX, positionY;
     Bone parentParent = parent.parent;
     if (parentParent != null) {
         parentParent.worldToLocal(targetX, targetY, out positionX, out positionY);
         targetX = (positionX - parent.x) * parentParent.worldScaleX;
         targetY = (positionY - parent.y) * parentParent.worldScaleY;
     } else {
         targetX -= parent.x;
         targetY -= parent.y;
     }
     if (child.parent == parent) {
         positionX = child.x;
         positionY = child.y;
     } else {
         child.parent.localToWorld(child.x, child.y, out positionX, out positionY);
         parent.worldToLocal(positionX, positionY, out positionX, out positionY);
     }
     float childX = positionX * parent.worldScaleX, childY = positionY * parent.worldScaleY;
     float offset = (float)Math.Atan2(childY, childX);
     float len1 = (float)Math.Sqrt(childX * childX + childY * childY), len2 = child.data.length * child.worldScaleX;
     // Based on code by Ryan Juckett with permission: Copyright (c) 2008-2009 Ryan Juckett, http://www.ryanjuckett.com/
     float cosDenom = 2 * len1 * len2;
     if (cosDenom < 0.0001f) {
         child.rotationIK = childRotation + ((float)Math.Atan2(targetY, targetX) * radDeg - parentRotation - childRotation)
             * alpha;
         return;
     }
     float cos = (targetX * targetX + targetY * targetY - len1 * len1 - len2 * len2) / cosDenom;
     if (cos < -1)
         cos = -1;
     else if (cos > 1)
         cos = 1;
     float childAngle = (float)Math.Acos(cos) * bendDirection;
     float adjacent = len1 + len2 * cos, opposite = len2 * (float)Math.Sin(childAngle);
     float parentAngle = (float)Math.Atan2(targetY * adjacent - targetX * opposite, targetX * adjacent + targetY * opposite);
     float rotation = (parentAngle - offset) * radDeg - parentRotation;
     if (rotation > 180)
         rotation -= 360;
     else if (rotation < -180) //
         rotation += 360;
     parent.rotationIK = parentRotation + rotation * alpha;
     rotation = (childAngle + offset) * radDeg - childRotation;
     if (rotation > 180)
         rotation -= 360;
     else if (rotation < -180) //
         rotation += 360;
     child.rotationIK = childRotation + (rotation + parent.worldRotation - child.parent.worldRotation) * alpha;
 }
開發者ID:nalone,項目名稱:spine-runtimes,代碼行數:59,代碼來源:IkConstraint.cs


注:本文中的Spine.Bone.worldToLocal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。