当前位置: 首页>>代码示例>>C#>>正文


C# Bone.GetXAxis方法代码示例

本文整理汇总了C#中Bone.GetXAxis方法的典型用法代码示例。如果您正苦于以下问题:C# Bone.GetXAxis方法的具体用法?C# Bone.GetXAxis怎么用?C# Bone.GetXAxis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bone的用法示例。


在下文中一共展示了Bone.GetXAxis方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckOrientationalConstraint

        // An orientational constraint is the twist of the bone around its own direction vector
        // with respect to its parent
        // It is defined as an allowed range betwen angles [start,end]
        // where start != end && 0 < start, end <= 360
        // If both start and end is 0 no twist constraint exist
        /// <summary>
        /// Checks if the bone has a legal rotation in regards to its parent, returns true if legal, false otherwise.
        /// The out rotation gives the rotation the bone should be applied to to be inside the twist constraints
        /// </summary>
        /// <param name="b">The bone under consideration</param>
        /// <param name="refBone">The parent of the bone, to check whether the child has legal rotation</param>
        /// <param name="rotation">The rotation bone b should applie to be inside the constraints</param>
        /// <returns></returns>
        public bool CheckOrientationalConstraint(Bone b, Bone refBone, out Quaternion rotation)
        {
            if (b.Orientation.Xyz.IsNaN() || refBone.Orientation.Xyz.IsNaN())
            {
                rotation = Quaternion.Identity;
                return false;
            }
            Vector3 thisY = b.GetYAxis();
            Quaternion referenceRotation = refBone.Orientation * b.ParentPointer;
            Vector3 reference = Vector3.Transform(
                    Vector3.Transform(Vector3.UnitZ, referenceRotation),
                    QuaternionHelper2.GetRotationBetween(
                            Vector3.Transform(Vector3.UnitY, referenceRotation),
                            thisY));

            float twistAngle = MathHelper.RadiansToDegrees(Vector3.CalculateAngle(reference, b.GetZAxis()));

            if (Vector3.CalculateAngle(reference, b.GetXAxis()) > Mathf.PI / 2) // b is twisted left with respect to parent
                twistAngle = 360 - twistAngle;

            float leftLimit = b.StartTwistLimit;
            float rightLimit = b.EndTwistLimit;

            float precision = 0.5f;
            bool inside = (leftLimit >= rightLimit) ? // The allowed range is on both sides of the reference vector
                    inside = twistAngle - leftLimit >= precision || twistAngle - rightLimit <= precision :
                    inside = twistAngle - leftLimit >= precision && twistAngle - rightLimit <= precision;

            if (!inside) // not inside constraints
            {
                // Create a rotation to the closest limit
                float toLeft = Math.Min(360 - Math.Abs(twistAngle - leftLimit), Math.Abs(twistAngle - leftLimit));
                float toRight = Math.Min(360 - Math.Abs(twistAngle - rightLimit), Math.Abs(twistAngle - rightLimit));
                if (toLeft < toRight)
                {
                    // Anti-clockwise rotation to left limit
                    rotation = Quaternion.FromAxisAngle(thisY, -MathHelper.DegreesToRadians(toLeft));
                    return true;
                }
                else
                {
                    // Clockwise to right limit
                    rotation = Quaternion.FromAxisAngle(thisY, MathHelper.DegreesToRadians(toRight));
                    return true;
                }
            }
            rotation = Quaternion.Identity;
            return false;
        }
开发者ID:jamesrrowland,项目名称:Qualisys-Unity-SDK,代码行数:62,代码来源:ConstraintsFunctions.cs


注:本文中的Bone.GetXAxis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。