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


C# Microsoft.Xna.Framework.Vector3.Normalize方法代码示例

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


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

示例1: UpdateLink

        private void UpdateLink(int num)
        {


            if (((num >= 0) && (num <= (mSpriteList.Count - 1))) && (this.mPoints.Count >= 2))
            {
                Vector3 absoluteTopLeft = new Vector3();
                Vector3 absoluteTopRight = new Vector3();
                Vector3 absoluteBottomLeft = new Vector3();
                Vector3 absoluteBottomRight = new Vector3();

                Sprite sprite = mSpriteList[num];

                Segment horizontalConnectingSegment = GetHorizontalSegmentAt(num);

                float oldZ = sprite.Z;

                sprite.Position = (horizontalConnectingSegment.Point1.ToVector3() + horizontalConnectingSegment.Point2.ToVector3()) / 2.0f;

                sprite.Z = oldZ;

                horizontalConnectingSegment.ScaleBy(2);

                Vector3 normalVector = horizontalConnectingSegment.Point2.ToVector3() - horizontalConnectingSegment.Point1.ToVector3();
                normalVector = new Vector3(-normalVector.Y, normalVector.X, 0);
                normalVector.Normalize();
                normalVector *= Width / 2.0f;

                #region Get the left side

                if (num == 0)
                {

                    absoluteTopLeft = mPoints[num] + normalVector;
                    absoluteBottomLeft = mPoints[num] - normalVector;

                }
                else
                {
                    Segment thisAboveSegment = horizontalConnectingSegment;
                    thisAboveSegment.MoveBy(normalVector.X, normalVector.Y);
                    thisAboveSegment.ScaleBy(10);

                    Segment thisBelowSegment = horizontalConnectingSegment;
                    thisBelowSegment.MoveBy(-normalVector.X, -normalVector.Y);
                    thisBelowSegment.ScaleBy(10);

                    Segment leftAboveSegment;
                    Segment leftBelowSegment;

                    GetSegmentsAboveAndBelow(num - 1, out leftAboveSegment, out leftBelowSegment);
                    leftAboveSegment.ScaleBy(10);
                    leftBelowSegment.ScaleBy(10);

                    Point point;

                    thisAboveSegment.IntersectionPoint(ref leftAboveSegment, out point);
                    if (double.IsNaN(point.X) || double.IsNaN(point.Y))
                    {
                        absoluteTopLeft = mPoints[num] + normalVector;
                    }
                    else
                    {
                        absoluteTopLeft.X = (float)point.X;
                        absoluteTopLeft.Y = (float)point.Y;
                    }

                    thisBelowSegment.IntersectionPoint(ref leftBelowSegment, out point);


                    if (double.IsNaN(point.X) || double.IsNaN(point.Y))
                    {
                        absoluteBottomLeft = mPoints[num] - normalVector;
                    }
                    else
                    {
                        absoluteBottomLeft.X = (float)point.X;
                        absoluteBottomLeft.Y = (float)point.Y;
                    }
                }
                #endregion

                if (num + 1 == mPoints.Count - 1)
                {
                    absoluteTopRight = mPoints[num + 1] + normalVector;
                    absoluteBottomRight = mPoints[num + 1] - normalVector;
                }
                else
                {
                    Segment thisAboveSegment = horizontalConnectingSegment;
                    thisAboveSegment.MoveBy(normalVector.X, normalVector.Y);
                    thisAboveSegment.ScaleBy(10);

                    Segment thisBelowSegment = horizontalConnectingSegment;
                    thisBelowSegment.MoveBy(-normalVector.X, -normalVector.Y);
                    thisBelowSegment.ScaleBy(10);

                    Segment rightAboveSegment;
                    Segment rightBelowSegment;

//.........这里部分代码省略.........
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:101,代码来源:SpriteChain.cs

示例2: Raycast


//.........这里部分代码省略.........
                    if (nextPoly.PolyType == PolygonType.OffMeshConnection)
                        continue;

                    //if the link is internal, just return the ref
                    if (link.Side == BoundarySide.Internal)
                    {
                        nextRef = link.Reference;
                        break;
                    }

                    //if the link is at the tile boundary

                    //check if the link spans the whole edge and accept
                    if (link.BMin == 0 && link.BMax == 255)
                    {
                        nextRef = link.Reference;
                        break;
                    }

                    //check for partial edge links
                    int v0 = poly.Verts[link.Edge];
                    int v1 = poly.Verts[(link.Edge + 1) % poly.VertCount];
                    Vector3 left = tile.Verts[v0];
                    Vector3 right = tile.Verts[v1];

                    //check that the intersection lies inside the link portal
                    if (link.Side == BoundarySide.PlusX || link.Side == BoundarySide.MinusX)
                    {
                        //calculate link size
                        float s = 1.0f / 255.0f;
                        float lmin = left.Z + (right.Z - left.Z) * (link.BMin * s);
                        float lmax = left.Z + (right.Z - left.Z) * (link.BMax * s);
                        if (lmin > lmax)
                        {
                            //swap
                            float temp = lmin;
                            lmin = lmax;
                            lmax = temp;
                        }

                        //find z intersection
                        float z = startPoint.Position.Z + (endPos.Z - startPoint.Position.Z) * tmax;
                        if (z >= lmin && z <= lmax)
                        {
                            nextRef = link.Reference;
                            break;
                        }
                    }
                    else if (link.Side == BoundarySide.PlusZ || link.Side == BoundarySide.MinusZ)
                    {
                        //calculate link size
                        float s = 1.0f / 255.0f;
                        float lmin = left.X + (right.X - left.X) * (link.BMin * s);
                        float lmax = left.X + (right.X - left.X) * (link.BMax * s);
                        if (lmin > lmax)
                        {
                            //swap
                            float temp = lmin;
                            lmin = lmax;
                            lmax = temp;
                        }

                        //find x intersection
                        float x = startPoint.Position.X + (endPos.X - startPoint.Position.X) * tmax;
                        if (x >= lmin && x <= lmax)
                        {
                            nextRef = link.Reference;
                            break;
                        }
                    }
                }

                if (nextRef == PolyId.Null)
                {
                    //no neighbour, we hit a wall

                    //calculate hit normal
                    int a = segMax;
                    int b = (segMax + 1) < nv ? segMax + 1 : 0;
                    Vector3 va = verts[a];
                    Vector3 vb = verts[b];
                    float dx = vb.X - va.X;
                    float dz = vb.Z - va.Z;
                    hitNormal.X = dz;
                    hitNormal.Y = 0;
                    hitNormal.Z = -dx;
                    hitNormal.Normalize();

                    pathCount = n;
                    return true;
                }

                //no hit, advance to neighbour polygon
                curRef = nextRef;
            }

            pathCount = n;

            return true;
        }
开发者ID:keedongpark,项目名称:SharpNav,代码行数:101,代码来源:NavMeshQuery.cs

示例3: GetSegmentsAboveAndBelow

        void GetSegmentsAboveAndBelow(int index, out Segment aboveSegment, out Segment belowSegment)
        {
            Segment segment = GetHorizontalSegmentAt(index);

            segment.ScaleBy(2); // so they intersect

            Vector3 normalVector = segment.Point2.ToVector3() - segment.Point1.ToVector3();
            normalVector = new Vector3(-normalVector.Y, normalVector.X, 0);
            normalVector.Normalize();
            normalVector = normalVector * Width / 2.0f;

            aboveSegment = segment;
            aboveSegment.MoveBy(normalVector.X, normalVector.Y);

            belowSegment = segment;
            belowSegment.MoveBy(-normalVector.X, -normalVector.Y);
        }
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:17,代码来源:SpriteChain.cs


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