当前位置: 首页>>代码示例>>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;未经允许,请勿转载。