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


C# Vector2.ProjectOn方法代码示例

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


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

示例1: GetClosestOutsidePoint

        public static Vector2 GetClosestOutsidePoint(Vector2 from, List<Geometry.Polygon> polygons)
        {
            var result = new List<Vector2>();

            foreach (var poly in polygons)
            {
                for (var i = 0; i <= poly.Points.Count - 1; i++)
                {
                    var sideStart = poly.Points[i];
                    var sideEnd = poly.Points[(i == poly.Points.Count - 1) ? 0 : i + 1];

                    result.Add(from.ProjectOn(sideStart, sideEnd).SegmentPoint);
                }
            }
            return result.MinOrDefault(vector2 => vector2.Distance(from));
        }
开发者ID:Maskov,项目名称:LeagueSharp,代码行数:16,代码来源:Evader.cs

示例2: FindLineCircleIntersections

        //http://csharphelper.com/blog/2014/09/determine-where-a-line-intersects-a-circle-in-c/
        // Find the points of intersection.
        public static int FindLineCircleIntersections(
            Vector2 center, float radius,
            Vector2 from, Vector2 to,
            out Vector2 intersection1, out Vector2 intersection2)
        {
            float cx = center.X;
            float cy = center.Y;
            float dx, dy, A, B, C, det, t;

            dx = to.X - from.X;
            dy = to.Y - from.Y;

            A = dx * dx + dy * dy;
            B = 2 * (dx * (from.X - cx) + dy * (from.Y - cy));
            C = (from.X - cx) * (from.X - cx) +
                (from.Y - cy) * (from.Y - cy) -
                radius * radius;

            det = B * B - 4 * A * C;
            if ((A <= 0.0000001) || (det < 0))
            {
                // No real solutions.
                intersection1 = new Vector2(float.NaN, float.NaN);
                intersection2 = new Vector2(float.NaN, float.NaN);
                return 0;
            }
            else if (det == 0)
            {
                // One solution.
                t = -B / (2 * A);
                intersection1 =
                    new Vector2(from.X + t * dx, from.Y + t * dy);
                intersection2 = new Vector2(float.NaN, float.NaN);

                var projection1 = intersection1.ProjectOn(from, to);
                if (projection1.IsOnSegment)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                // Two solutions.
                t = (float)((-B + Math.Sqrt(det)) / (2 * A));
                intersection1 =
                    new Vector2(from.X + t * dx, from.Y + t * dy);
                t = (float)((-B - Math.Sqrt(det)) / (2 * A));
                intersection2 =
                    new Vector2(from.X + t * dx, from.Y + t * dy);

                var numIntersections = 0;
                var projection1 = intersection1.ProjectOn(from, to);
                var projection2 = intersection2.ProjectOn(from, to);

                if (projection1.IsOnSegment && projection2.IsOnSegment)
                {
                    return 2;
                }
                else if (projection1.IsOnSegment && !projection2.IsOnSegment)
                {
                    return 1;
                }
                else if (!projection1.IsOnSegment && projection2.IsOnSegment)
                {
                    intersection1 = intersection2;
                    return 1;
                }

                return 0;
            }
        }
开发者ID:bongy97,项目名称:LeagueSharp-1,代码行数:77,代码来源:MathUtils.cs

示例3: GetSpellProjection

        public static Vector2 GetSpellProjection(this Spell spell, Vector2 pos, bool predictPos = false)
        {
            if (spell.SpellType == SpellType.Line
                || spell.SpellType == SpellType.Arc)
            {
                if (predictPos)
                {
                    var spellPos = spell.CurrentSpellPosition;
                    var spellEndPos = spell.GetSpellEndPosition();

                    return pos.ProjectOn(spellPos, spellEndPos).SegmentPoint;
                }
                return pos.ProjectOn(spell.StartPos, spell.EndPos).SegmentPoint;
            }

            if (spell.SpellType == SpellType.Circular)
            {
                return spell.EndPos;
            }

            return Vector2.Zero;
        }
开发者ID:giaanthunder,项目名称:EloBuddy,代码行数:22,代码来源:Spell.cs

示例4: inSkillShot

        public static bool inSkillShot(Spell spell, Vector2 position, float radius)
        {
            if (spell.info.spellType == SpellType.Line)
            {
                Vector2 spellPos = SpellDetector.GetCurrentSpellPosition(spell); //leave little space at back of skillshot

                if (spell.info.projectileSpeed == float.MaxValue
                    && Evade.GetTickCount() - spell.startTime > spell.info.spellDelay)
                {
                    return false;
                }

                var projection = position.ProjectOn(spellPos, spell.endPos);

                if (projection.SegmentPoint.Distance(spell.endPos) < 100) //Check Skillshot endpoints
                {
                    //unfinished
                }

                return projection.SegmentPoint.Distance(position) <= GetSpellRadius(spell) + radius;
            }
            else if (spell.info.spellType == SpellType.Circular)
            {
                return position.Distance(spell.endPos) <= GetSpellRadius(spell) + radius;
            }
            else if (spell.info.spellType == SpellType.Cone)
            {

            }
            return false;
        }
开发者ID:qktlfflzk,项目名称:Backup5.4,代码行数:31,代码来源:EvadeHelper.cs


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