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


C# System.Numerics.Vector3.Length方法代码示例

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


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

示例1: GetBoundingBox

        private void GetBoundingBox(ref Matrix3x3 o, out BoundingBox boundingBox)
        {
            #if !WINDOWS
            boundingBox = new BoundingBox();
            #endif
            //Sample the local directions from the matrix, implicitly transposed.
            var rightDirection = new System.Numerics.Vector3(o.M11, o.M21, o.M31);
            var upDirection = new System.Numerics.Vector3(o.M12, o.M22, o.M32);
            var backDirection = new System.Numerics.Vector3(o.M13, o.M23, o.M33);

            int right = 0, left = 0, up = 0, down = 0, backward = 0, forward = 0;
            float minX = float.MaxValue, maxX = -float.MaxValue, minY = float.MaxValue, maxY = -float.MaxValue, minZ = float.MaxValue, maxZ = -float.MaxValue;

            for (int i = 0; i < hullVertices.Count; i++)
            {
                float dotX, dotY, dotZ;
                Vector3Ex.Dot(ref rightDirection, ref hullVertices.Elements[i], out dotX);
                Vector3Ex.Dot(ref upDirection, ref hullVertices.Elements[i], out dotY);
                Vector3Ex.Dot(ref backDirection, ref hullVertices.Elements[i], out dotZ);
                if (dotX < minX)
                {
                    minX = dotX;
                    left = i;
                }
                if (dotX > maxX)
                {
                    maxX = dotX;
                    right = i;
                }

                if (dotY < minY)
                {
                    minY = dotY;
                    down = i;
                }
                if (dotY > maxY)
                {
                    maxY = dotY;
                    up = i;
                }

                if (dotZ < minZ)
                {
                    minZ = dotZ;
                    forward = i;
                }
                if (dotZ > maxZ)
                {
                    maxZ = dotZ;
                    backward = i;
                }

            }

            //Incorporate the collision margin.
            Vector3Ex.Multiply(ref rightDirection, meshCollisionMargin / (float)Math.Sqrt(rightDirection.Length()), out rightDirection);
            Vector3Ex.Multiply(ref upDirection, meshCollisionMargin / (float)Math.Sqrt(upDirection.Length()), out upDirection);
            Vector3Ex.Multiply(ref backDirection, meshCollisionMargin / (float)Math.Sqrt(backDirection.Length()), out backDirection);

            var rightElement = hullVertices.Elements[right];
            var leftElement = hullVertices.Elements[left];
            var upElement = hullVertices.Elements[up];
            var downElement = hullVertices.Elements[down];
            var backwardElement = hullVertices.Elements[backward];
            var forwardElement = hullVertices.Elements[forward];
            Vector3Ex.Add(ref rightElement, ref rightDirection, out rightElement);
            Vector3Ex.Subtract(ref leftElement, ref rightDirection, out leftElement);
            Vector3Ex.Add(ref upElement, ref upDirection, out upElement);
            Vector3Ex.Subtract(ref downElement, ref upDirection, out downElement);
            Vector3Ex.Add(ref backwardElement, ref backDirection, out backwardElement);
            Vector3Ex.Subtract(ref forwardElement, ref backDirection, out forwardElement);

            //Rather than transforming each axis independently (and doing three times as many operations as required), just get the 6 required values directly.
            TransformLocalExtremePoints(ref rightElement, ref upElement, ref backwardElement, ref o, out boundingBox.Max);
            TransformLocalExtremePoints(ref leftElement, ref downElement, ref forwardElement, ref o, out boundingBox.Min);
        }
开发者ID:Raverenx,项目名称:GameEngine,代码行数:76,代码来源:MobileMeshShape.cs

示例2: Kick

		public void Kick(Vector3 dir)
		{
			Speed = (dir.Length());
			RegenerateOrthonormalBasis(dir);
		}
开发者ID:cupsster,项目名称:SharpSteer2,代码行数:5,代码来源:Ball.cs


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