本文整理汇总了C#中System.Vector2.Intersection方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2.Intersection方法的具体用法?C# Vector2.Intersection怎么用?C# Vector2.Intersection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Vector2
的用法示例。
在下文中一共展示了Vector2.Intersection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LineIntersectLinearSpellEx
//edited
public static bool LineIntersectLinearSpellEx(this Spell spell, Vector2 a, Vector2 b, out Vector2 intersection)
{
var myBoundingRadius = ObjectManager.Player.BoundingRadius;
var spellDir = spell.Direction;
var pSpellDir = spell.Direction.Perpendicular();
var spellRadius = spell.Radius;
var spellPos = spell.CurrentSpellPosition - spellDir * myBoundingRadius; //leave some space at back of spell
var endPos = spell.GetSpellEndPosition() + spellDir * myBoundingRadius; //leave some space at the front of spell
var startRightPos = spellPos + pSpellDir * (spellRadius + myBoundingRadius);
var startLeftPos = spellPos - pSpellDir * (spellRadius + myBoundingRadius);
var endRightPos = endPos + pSpellDir * (spellRadius + myBoundingRadius);
var endLeftPos = endPos - pSpellDir * (spellRadius + myBoundingRadius);
List<Geometry.IntersectionResult> intersects = new List<Geometry.IntersectionResult>();
Vector2 heroPos = ObjectManager.Player.ServerPosition.To2D();
intersects.Add(a.Intersection(b, startRightPos, startLeftPos));
intersects.Add(a.Intersection(b, endRightPos, endLeftPos));
intersects.Add(a.Intersection(b, startRightPos, endRightPos));
intersects.Add(a.Intersection(b, startLeftPos, endLeftPos));
var sortedIntersects = intersects.Where(i => i.Intersects).OrderBy(i => i.Point.Distance(heroPos)); //Get first intersection
if (sortedIntersects.Count() > 0)
{
intersection = sortedIntersects.First().Point;
return true;
}
intersection = Vector2.Zero;
return false;
}
示例2: CheckLineIntersection
public static bool CheckLineIntersection(Vector2 a, Vector2 b, Vector2 c, Vector2 d)
{
return a.Intersection(b, c, d).Intersects;
}
示例3: LineIntersectLinearSpellEx
public static bool LineIntersectLinearSpellEx(Vector2 a, Vector2 b, Spell spell, out Vector2 intersection)
{
var myBoundingRadius = myHero.BoundingRadius;
var spellDir = spell.direction;
var pSpellDir = spell.direction.Perpendicular();
var spellRadius = GetSpellRadius(spell);
var spellPos = SpellDetector.GetCurrentSpellPosition(spell) - spellDir * myBoundingRadius; //leave some space at back of spell
var endPos = spell.endPos + spellDir * myBoundingRadius; //leave some space at the front of spell
var startRightPos = spellPos + pSpellDir * (spellRadius + myBoundingRadius);
var startLeftPos = spellPos - pSpellDir * (spellRadius + myBoundingRadius);
var endRightPos = endPos + pSpellDir * (spellRadius + myBoundingRadius);
var endLeftPos = endPos - pSpellDir * (spellRadius + myBoundingRadius);
var int1 = a.Intersection(b, startRightPos, startLeftPos);
var int2 = a.Intersection(b, endRightPos, endLeftPos);
var int3 = a.Intersection(b, startRightPos, endRightPos);
var int4 = a.Intersection(b, startLeftPos, endLeftPos);
if (int1.Intersects)
{
intersection = int1.Point;
return true;
}
else if (int2.Intersects)
{
intersection = int2.Point;
return true;
}
else if (int3.Intersects)
{
intersection = int3.Point;
return true;
}
else if (int4.Intersects)
{
intersection = int4.Point;
return true;
}
intersection = Vector2.Zero;
return false;
}