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


C# Vec3.Length方法代码示例

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


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

示例1: VolumeCheckGetFirstNotFreePlace

        bool VolumeCheckGetFirstNotFreePlace( Capsule[] sourceVolumeCapsules, Vec3 destVector, bool firstIteration, float step,
			out List<Body> collisionBodies, out float collisionDistance, out bool collisionOnFirstCheck )
        {
            collisionBodies = new List<Body>();
            collisionDistance = 0;
            collisionOnFirstCheck = false;

            bool firstCheck = true;

            Vec3 direction = destVector.GetNormalize();
            float totalDistance = destVector.Length();
            int stepCount = (int)( (float)totalDistance / step ) + 2;
            Vec3 previousOffset = Vec3.Zero;

            for( int nStep = 0; nStep < stepCount; nStep++ )
            {
                float distance = (float)nStep * step;
                if( distance > totalDistance )
                    distance = totalDistance;
                Vec3 offset = direction * distance;

                foreach( Capsule sourceVolumeCapsule in sourceVolumeCapsules )
                {
                    Capsule checkCapsule = CapsuleAddOffset( sourceVolumeCapsule, offset );

                    Body[] bodies = PhysicsWorld.Instance.VolumeCast( checkCapsule, (int)ContactGroup.CastOnlyContact );
                    foreach( Body body in bodies )
                    {
                        if( body == mainBody || body == fixRotationJointBody )
                            continue;
                        collisionBodies.Add( body );
                    }
                }

                if( collisionBodies.Count != 0 )
                {
                    //second iteration
                    if( nStep != 0 && firstIteration )
                    {
                        float step2 = step / 10;
                        Capsule[] sourceVolumeCapsules2 = new Capsule[ sourceVolumeCapsules.Length ];
                        for( int n = 0; n < sourceVolumeCapsules2.Length; n++ )
                            sourceVolumeCapsules2[ n ] = CapsuleAddOffset( sourceVolumeCapsules[ n ], previousOffset );
                        Vec3 destVector2 = offset - previousOffset;

                        List<Body> collisionBodies2;
                        float collisionDistance2;
                        bool collisionOnFirstCheck2;
                        if( VolumeCheckGetFirstNotFreePlace( sourceVolumeCapsules2, destVector2, false, step2, out collisionBodies2,
                            out collisionDistance2, out collisionOnFirstCheck2 ) )
                        {
                            collisionBodies = collisionBodies2;
                            collisionDistance = ( previousOffset != Vec3.Zero ? previousOffset.Length() : 0 ) + collisionDistance2;
                            collisionOnFirstCheck = false;
                            return true;
                        }
                    }

                    collisionDistance = distance;
                    collisionOnFirstCheck = firstCheck;
                    return true;
                }

                firstCheck = false;
                previousOffset = offset;
            }

            return false;
        }
开发者ID:whztt07,项目名称:SDK,代码行数:69,代码来源:Character.cs


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