/// <summary> /// Creates a new bullet visualisation. /// </summary> /// <param name="quarter">Town quarter where the bullet is located</param> /// <param name="start">Starting position</param> /// <param name="azimuth">The flight direction</param> /// <param name="range">The flight range</param> /// <param name="startHeight">Starting height</param> /// <param name="endHeight">Ending height</param> public BulletVisualisation(TownQuarter quarter, Vector2 start, float azimuth, float range, float startHeight, float endHeight) { Vector2 end = start.Go(range, azimuth); Vector2 startL = start.Go(Width, azimuth - MathHelper.PiOver2); Vector2 startR = start.Go(Width, azimuth + MathHelper.PiOver2); Vector2 endL = end.Go(Width, azimuth - MathHelper.PiOver2); Vector2 endR = end.Go(Width, azimuth + MathHelper.PiOver2); horizontalPlate = new Plate(quarter, startL.ToVector3(startHeight), startR.ToVector3(startHeight), endL.ToVector3(endHeight), endR.ToVector3(endHeight), Texture, Texture, false); verticalPlate = new Plate(quarter, start.ToVector3(startHeight + Width), start.ToVector3(startHeight - Width), end.ToVector3(endHeight + Width), end.ToVector3(endHeight - Width), Texture, Texture, false); }
public static Matrix CreateLocalTransformation(Vector2 position, float rotation, Vector2 scale) { return Matrix.CreateScale(new Vector3(scale, 1.0f)) * Matrix.CreateRotationZ(MathHelper.ToRadians(rotation)) * Matrix.CreateTranslation(position.ToVector3()); }
public override void OnFinishCasting(Vector2 position, Vector2 endPosition, AttackableUnit target) { /* * spawn tornado * var castInfo = Spell.GetCastInformations(position.ToVector3(), * endPosition.ToVector3(), "YasuoQ3Mis", 0); * castInfo.DesignerCastTime = 0f; * castInfo.DesignerTotalTime = 0f; * castInfo.ExtraCastTime = 0f; * Owner.Game.Send(new CastSpellAnswerMessage(Owner.NetId, Environment.TickCount, false, castInfo));*/ var castInfo = Spell.GetCastInformations(position.ToVector3(), endPosition.ToVector3(), "YasuoQ", 0); castInfo.DesignerCastTime = 0.2f; castInfo.DesignerTotalTime = 0.2f; Owner.Game.Send(new CastSpellAnswerMessage(Owner.NetId, Environment.TickCount, false, castInfo)); var a = GetTargets(); foreach (var b in a) { CreateFX("Yasuo_Base_Q_hit_tar.troy", "", 1f, (AIUnit)b, false); b.InflictDamages(new Damages(Owner, b, 100f, false, DamageType.DAMAGE_TYPE_PHYSICAL, true)); } }
public static bool ShArcContains2DPoint(Vector2 point, Vector2 arcOrigin, Vector2 arcStartPoint, float degreesFromStart, ArcEpsilon epsilon = new ArcEpsilon()) { degreesFromStart = ArcMath.ConvertToSh2DArcAngle(arcOrigin, arcStartPoint, degreesFromStart); epsilon.ExtrudeEps = 0.0f; return(ShArcContains3DPoint(point.ToVector3(), false, arcOrigin.ToVector3(), arcStartPoint.ToVector3(), Vector3.forward, degreesFromStart, epsilon)); }
private void Update() { cushionCollider.size = new Vector2(Camera.ViewportRect.width + 2 * CushionRange, Camera.ViewportRect.height + 2 * CushionRange); cushionCollider.offset = Vector2.zero; Debug.DrawLine(transform.position, transform.position + seperate.ToVector3(), Color.blue); Debug.DrawLine(transform.position, transform.position + followSpeed.ToVector3(), Color.red); }
private static bool IsCondemnable(Vector2 from, Obj_AI_Base unit, int range) { if (from.ToVector3().GetTumbleEndPos().Distance(unit) < 300 || !from.IsInRange(unit, 425)) { return(false); } var position = Prediction.Position.GetPrediction(unit, new Prediction.Position.PredictionData(Prediction.Position.PredictionData.PredictionType.Linear, Settings.PushDistance, 80, 0, 550, 1800)).UnitPosition.To2D(); for (var i = range; i >= 100; i -= 100) { var vec = position.Extend(from, -i); const int var = 18 * 4 / 100; var left = position.Extend( vec + (position - vec).Normalized().Rotated((float)Helpers.ToRadian(Math.Max(0, var))) * Math.Abs(i < 200 ? 50 : 60 * 4), i); var right = position.Extend( vec + (position - vec).Normalized().Rotated((float)Helpers.ToRadian(-Math.Max(0, var))) * Math.Abs(i < 200 ? 50 : 60 * 4), i); if (left.IsWall() && right.IsWall() && vec.IsWall()) { return(true); } } return(false); }
public void SetPoint(int index, Vector2 point) { if (index > -1 && index < points.Count) { points[index] = transform.InverseTransformPoint(point.ToVector3(drawSettings.axis, drawSettings.zPosition)).ToVector2(drawSettings.axis); } }
private static void LetsPush() { var me = ObjectMgr.LocalHero; if (!Push.CanBeCasted() || !Utils.SleepCheck("preComboW8")) { return; } if (AnyStoneNear(me, new Vector3(), 200F)) { } else if (Remnant.CanBeCasted()) { var ang = me.FindAngleBetween(Game.MousePosition, true); var p = new Vector2((float)(me.Position.X + 50 * Math.Cos(ang)), (float)(me.Position.Y + 50 * Math.Sin(ang))); Remnant.UseAbility(p.ToVector3(true)); } else { return; } var pos = Game.MousePosition; if (AnyStoneNear(me, pos)) { var ang = me.FindAngleBetween(pos, true); pos = new Vector2((float)(pos.X + 300 * Math.Cos(ang)), (float)(pos.Y + 300 * Math.Sin(ang))).ToVector3(true); } Push.UseAbility(pos); Utils.Sleep(500, "preComboW8"); }
private static void ToVector3Test() { var v3 = new Vector3(1, 0, 1); var v2 = new Vector2(1, 1); Assert.AreEqual(v2.ToVector3(), v3); }
public void Test_Utils_Vector2_ToVector3() { var a = new Vector2(10, 10); var b = new Vector3(10, 10, 0); Assert.AreEqual(b, a.ToVector3()); }
void Update() { transform.position += direction.ToVector3() * Speed * Time.deltaTime; Ray ray = new Ray(transform.position, (transform.rotation * Vector3.up)); Debug.DrawRay(ray.origin, ray.direction, Color.red); RaycastHit2D[] hits = Physics2D.RaycastAll(ray.origin.ToVector2(), ray.direction.ToVector2(), 0.0f); foreach (RaycastHit2D hit in hits) { if (hit.collider.gameObject == this.gameObject) { continue; } Ship ship = hit.collider.gameObject.GetComponent <Ship>(); if (ship != null && ship.Team != Team) { ShipMotor motor = hit.collider.gameObject.GetComponent <ShipMotor>(); if (motor.Destroyed) { break; } motor.Damage(Team, Damage); if (!Piercing) { Destroy(this.gameObject); } } } }
private static void LetAghanimCombo(Hero me, Hero target) { if (!Utils.SleepCheck("nextAction")) { return; } var ability = me.FindSpell("earth_spirit_petrify"); if (ability == null) { return; } if (ability.Level == 0) { return; } var inStone = target.Modifiers.Any(x => x.Name == "modifier_earthspirit_petrify"); var dist = me.Distance2D(target); if (ability.CanBeCasted() && !inStone) { if (Menu.Item("dagger").GetValue <StringList>().SelectedIndex == (int)DaggerStage.OnStartCombo || Menu.Item("dagger").GetValue <StringList>().SelectedIndex == (int)DaggerStage.AfterSmash) { var blink = me.FindItem("item_blink"); if (dist >= ability.CastRange && blink != null && blink.CanBeCasted()) { var ang = me.FindAngleBetween(target.Position, true); var p = new Vector2((float)(target.Position.X - 100 * Math.Cos(ang)), (float)(target.Position.Y - 100 * Math.Sin(ang))); blink.UseAbility(p.ToVector3(true)); } } ability.UseAbility(target); Utils.Sleep(150 + ability.FindCastPoint(), "nextAction"); return; } if (Pull != null && Pull.CanBeCasted() && inStone) { Pull.UseAbility(target.Position); //PrintInfo(Roll.CastSkillShot(target).ToString()); Utils.Sleep(300 + Pull.FindCastPoint(), "nextAction"); return; } if (Push != null && Push.CanBeCasted() && inStone && dist <= 150) { Push.UseAbility(Game.MousePosition); if (Roll != null && Roll.CanBeCasted()) { if (Remnant != null && Remnant.CanBeCasted()) { var ang = me.FindAngleBetween(Game.MousePosition, true); var p = new Vector2((float)(me.Position.X + 100 * Math.Cos(ang)), (float)(me.Position.Y + 100 * Math.Sin(ang))); Remnant.UseAbility(p.ToVector3(true)); } Roll.UseAbility(Game.MousePosition, true); } Utils.Sleep(300 + Push.FindCastPoint(), "nextAction"); } }
/// <summary> /// Calculates point that the human is looking at. /// </summary> /// <param name="from">The eyes position</param> /// <param name="distance">Looking distance</param> /// <returns>The watched point</returns> Vector3 GetLookingAtCoordinates(Vector3 from, float distance) { float distance2D = (float)Math.Cos(lookAngle) * distance; Vector2 ret = from.XZToVector2().Go(distance2D, azimuth); return(ret.ToVector3((float)Math.Sin(lookAngle) * distance + from.Y)); }
private void OnDrawGizmosSelected() { Gizmos.color = Color.yellow; Gizmos.DrawWireCube(transform.position + FollowRangeOffset.ToVector3(), FollowStartRange.ToVector3() * 2); Gizmos.color = Color.red; Gizmos.DrawWireCube(transform.position + FollowRangeOffset.ToVector3(), MaxFollowRange * 2); }
private bool IsCondemnable(Vector2 from, AIHeroClient unit, int range) { if (Helpers.GetTumbleEndPos(from.ToVector3()).Distance(unit) < 300 || !from.IsInRange(unit, 425)) { return(false); } var position = Prediction.Position.GetPrediction(unit, new Prediction.Position.PredictionData(Prediction.Position.PredictionData.PredictionType.Linear, Settings.PushDistance, 80, 0, 550, 1800)).UnitPosition.To2D(); for (var i = range; i >= 100; i -= 100) { var vec = position.Extend(from, -i); var left = new Vector2[5]; var right = new Vector2[5]; var var = 18 * i / 100; for (var x = 0; x < 5; x++) { left[x] = position.Extend(vec + (position - vec).Normalized().Rotated((float)Helpers.ToRadian(Math.Max(0, var))) * Math.Abs(i < 200 ? 50 : 60 * x), i); right[x] = position.Extend(vec + (position - vec).Normalized().Rotated((float)Helpers.ToRadian(-Math.Max(0, var))) * Math.Abs(i < 200 ? 50 : 60 * x), i); if (left[x].IsWall() && right[x].IsWall() && vec.IsWall()) { return(true); } } } return(false); }
private bool TryHitDisplaceObject(Vector2 directionToMove, RaycastHit2D hit) { var displaceObject = hit.collider.GetComponent <DisplaceObject>(); if (displaceObject == null) { return(false); } if (!displaceObject.CanHit()) { return(true); //If we can't hit this object just don't do anything. This was implemented to handle rocks moving } var transitionToPoint = hit.point - directionToMove * .5f; if ((transitionToPoint.ToVector3() - Owner.transform.position).sqrMagnitude <= .1f) { displaceObject.Displace(directionToMove); return(true); } Owner.TransitionTo(new BeginMoveState(References, transitionToPoint, _ => { displaceObject.Displace(directionToMove.ToVector3()); return(true); }, directionToMove)); return(true); }
protected override void HandleUpdate(PlayerInput input) { var t = StateCount / Mathf.Min(Owner.settings.MoveTime * _dist, Owner.settings.MaxMoveTime); t = Owner.settings.MoveCurve.Evaluate(t); Owner.transform.position = Vector3.Lerp(_startPoint, _transitionToPoint, t); var dist = (_transitionToPoint.ToVector3() - Owner.transform.position).magnitude; _tridentAnimation.SetHeight(dist + .65f); if (!(t >= 1)) { return; } if (_moveCallback != null) { var shouldTransitionBack = _moveCallback(Owner); if (!shouldTransitionBack) { return; } } Owner.transform.position = _transitionToPoint; Owner.TransitionTo(new IdlePlayerState(References)); }
internal static PredictionOutput GetConePrediction(PredictionInput input) { var mainTargetPrediction = input.GetPrediction(false, true); var posibleTargets = new List <PossibleTarget> { new PossibleTarget { Position = mainTargetPrediction.UnitPosition.ToVector2(), Unit = input.Unit } }; if (mainTargetPrediction.Hitchance >= HitChance.Medium) { posibleTargets.AddRange(GetPossibleTargets(input)); } if (posibleTargets.Count > 1) { var candidates = new List <Vector2>(); posibleTargets.ForEach(i => i.Position -= input.From.ToVector2()); for (var i = 0; i < posibleTargets.Count; i++) { for (var j = 0; j < posibleTargets.Count; j++) { if (i == j) { continue; } var p = (posibleTargets[i].Position + posibleTargets[j].Position) * 0.5f; if (!candidates.Contains(p)) { candidates.Add(p); } } } var bestCandidateHits = -1; var bestCandidate = new Vector2(); var positionsList = posibleTargets.Select(i => i.Position).ToList(); candidates.ForEach( i => { var hits = GetHits(i, input.Range, input.Radius, positionsList); if (hits > bestCandidateHits) { bestCandidate = i; bestCandidateHits = hits; } }); if (bestCandidateHits > 1 && input.From.DistanceSquared(bestCandidate) > 50 * 50) { return(new PredictionOutput { Input = input, CastPosition = bestCandidate.ToVector3(), UnitPosition = mainTargetPrediction.UnitPosition, Hitchance = mainTargetPrediction.Hitchance, AoeHitCount = bestCandidateHits }); } } return(mainTargetPrediction); }
public void _CheckObstacle() { //FixedPoint length = FixedPoint.N_0; //if (m_bLerp) // length = m_length; //else // length = new FixedPoint(m_triggerData.Length); Vector2d startPos = m_caster.GetPos(); Vector2 intersectionPont = Vector2.zero; // 实际表现效果要短一点 Vector2d endPos = startPos + GetDir().normalized *new FixedPoint(m_triggerData.Length); if (CMapMgr.GetMap().LineObstacle( (int)startPos.x.value, (int)startPos.y.value, (int)endPos.x.value, (int)endPos.y.value, ref intersectionPont)) { if (m_vCreature != null) { GetVTrigger().SetLineTargetPos(intersectionPont.ToVector3()); } } else if (m_vCreature != null) { GetVTrigger().SetLineTargetPos(endPos.ToVector3()); } //} }
public static bool threeSixty(AIHeroClient unit, Vector2 pos = new Vector2()) { if (unit.HasBuffOfType(BuffType.SpellImmunity) || unit.HasBuffOfType(BuffType.SpellShield) || ObjectManager.Player.IsDashing()) { return(false); } var prediction = E.GetPrediction(unit); var predictionsList = pos.IsValid() ? new List <Vector3> { pos.ToVector3() } : new List <Vector3> { unit.Position, unit.Position, prediction.CastPosition, prediction.UnitPosition }; var wallsFound = 0; Points = new List <Vector2>(); foreach (var position in predictionsList) { for (var i = 0; i < getMenuSliderItem(emenu, "PushDistance"); i += (int)unit.BoundingRadius) // 420 = push distance { var cPos = ObjectManager.Player.Position.Extend(position, ObjectManager.Player.Distance(position) + i); Points.Add(cPos.ToVector2()); if (NavMesh.GetCollisionFlags(cPos).HasFlag(CollisionFlags.Wall) || NavMesh.GetCollisionFlags(cPos).HasFlag(CollisionFlags.Building)) { wallsFound++; break; } } } if (wallsFound / predictionsList.Count >= 33 / 100f) { return(true); } return(false); }
void Update() { var dir = targetPos.ToVector3() - transform.position; var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); }
private void SetGroundNormal(Vector2 normal) { groundNormal = normal.normalized; groundTangent = Vector3.Cross(groundNormal.ToVector3(), Vector3.forward).ToVector2().normalized; Debug.DrawLine(transform.position, transform.position + groundNormal.ToVector3(), Color.green); Debug.DrawLine(transform.position, transform.position + groundTangent.ToVector3(), Color.red); }
public Vector2 TransformPoint(Vector2 vector) { #if USE_MATRIX_FOR_ROTATION return(position + Math.Mul(rotation, vector)); #else return(position + (rotation.Xyz * vector.ToVector3()).ToVector2()); #endif }
/// <summary> /// Gets the 2D world position as a 3D point that the mouse is pointing to. /// </summary> /// <returns>The 2D world position beneath the user's mouse (z = 0)</returns> public static Vector3 GetMousePosition3D() { // Get the mouse position as a vector2 Vector2 target = GetMousePosition(); // And convert to a vector3 return(target.ToVector3()); }
public Incinerator(Vector2 position) { this.Position = position; cube = new Cube(new Vector3(position.X, 0, position.Y), RM.GetTexture("incinerator")); cube.ScaleVector = new Vector3(24, 64, 24); cube.SetPosition(position.ToVector3() + new Vector3(0, -56, 0)); }
public void SetDirectionalVelocity(Vector2 dir) { Vector3 direction = dir.ToVector3(); // rb.velocity = Quaternion.AngleAxis(transform.eulerAngles.y, Vector3.up) * direction; SetVelocity(Quaternion.AngleAxis(transform.eulerAngles.y, Vector3.up) * direction); rb.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, direction.x * -tilt); }
private void OnDrawGizmos() { Gizmos.color = Color.red; Gizmos.DrawWireCube(Vector2.zero, levelScale.ToVector3() * 2); Gizmos.color = Color.green; Gizmos.DrawWireCube(crateSpawnZone.position, crateSpawnZone.transform.localScale.ToVector2().ToVector3() * 2); }
/// <summary> /// Initializes a new instance of the <see cref="FixedCamera2D" /> class. /// </summary> /// <param name="name">The name.</param> /// <param name="position">The camera position</param> public FixedCamera2D(string name, Vector2 position) { this.entity = new Entity(name) .AddComponent(new Camera2D() { Position = position.ToVector3(0), }); }
// <summary> // Transforms direction from local space to world space. // </summary> public Vector2 TransformDirection(Vector2 vector) { #if USE_MATRIX_FOR_ROTATION return(Math.Mul(rotation, vector)); #else return((rotation.Xyz * vector.ToVector3()).ToVector2()); #endif }
protected void Start() { _isBallHeld = false; origin.x = 0f; origin.y = -ResolutionManager.HalfHeight; Block.position = origin.ToVector3(); HoldBall(); }
/// <summary> /// Initializes a new instance of the <see cref="FixedCamera2D" /> class. /// </summary> /// <param name="name">The name.</param> /// <param name="position">The camera position</param> public FixedCamera2D(string name, Vector2 position) { this.InitEntity(name); Vector3 position3D = position.ToVector3(-10); this.entity.FindComponent <Transform3D>(false).Position = position3D; }
public static void Initialize(this IProjectile projectile, Vector2 gridVelocity, ProjectileParameters projectileParameters, DamageTypes damageParameters, Vector3 targetPosition, Quaternion targetRotation, Transform projectileTransform, int sourceGridID) { projectileTransform.position = targetPosition; projectileTransform.rotation = targetRotation; projectile.damageTypes = damageParameters; projectile.projectileReferences.rb2d.AddForce(gridVelocity.ToVector3() + (projectileTransform.right * projectileParameters.speed)); projectile.sourceGridID = sourceGridID; }
void AddVert(int index, Vector2 position, Vector2 texCoord, Color col) { _vertices.EnsureCapacity(); _vertices.Buffer[index].Position = position.ToVector3(); _vertices.Buffer[index].TextureCoordinate = texCoord; _vertices.Buffer[index].Color = col; _vertices.Length++; }
public Door(Vector2 position) { Position = position; cube = new Cube(Position.ToVector3(), RM.GetTexture("door")); cube.SetPosition(new Vector3(Position.X, Y, Position.Y)); HudIcons.Add(new HudIcon() { text = "Open door", texture = RM.GetTexture("opendooricon"), Action = (() => state = DoorState.Opening) }); HudIcons.Add(new HudIcon() { text = "Close door", texture = RM.GetTexture("closedooricon"), Action = (() => state = DoorState.Closing) }); HudIcons.Add(new HudIcon() { text = "Lock/unlock", texture = RM.GetTexture("lockicon"), Action = (() => Locked = !Locked) }); HudIcons.Add(new HudIcon() { text = "Toggle AI", texture = RM.GetTexture("dooraiicon"), Action = (() => ai = !ai) }); }
public void ToVector3Test() { const float TestValueA = 5.722222f; const float TestValueB = -72.333e-7f; Vector2 vectorA = new Vector2(TestValueA, TestValueB); Vector3 resultA = vectorA.ToVector3(); Assert.AreEqual(resultA.X, TestValueA); Assert.AreEqual(resultA.Y, TestValueB); Assert.AreEqual(resultA.Z, 0); }
public static Vector2 PointToWorldSpace(Vector2 point, Vector2 heading, Vector2 position) { Vector2 TransPoint = point; float desiredAngle = WrapAngle((float)Math.Atan2(heading.Y, heading.X)); TransPoint = Vector2.Transform(point, Matrix.CreateRotationZ(desiredAngle) * Matrix.CreateTranslation(position.ToVector3()) ); return TransPoint; }
public void SetPoint(int index, Vector2 point) { if (index > -1 && index < _points.Count) { Vector3 p = transform.InverseTransformPoint(point.ToVector3(_yPosition)); Vector2 pos = new Vector2(p.x, p.z); _points[index] = pos; } }
public void RpcResetCampInfo(int playerID, int camp, Vector2 position) { Debug.LogFormat("Unit{2}.RpcResetCampInfo({0},{1})", camp, position, playerID); name = "Player Unit " + playerID; if (isLocalPlayer) { transform.position = position.ToVector3(1.1f); _rebirthPosition = Position; } }
/// <summary> /// Creates a Rendernstruction representing a circle. Uses triangle fan method. /// </summary> /// <param name="center2d">The center of the circle</param> /// <param name="rad">The radian of the circle</param> /// <param name="rads">Number of radians to draw (if drawing a half circle for example)</param> /// <param name="closeCircle"> /// If set to <c>true</c>, connect the circle. /// Unless not drawing a full circle, set to true. /// </param> /// <param name="c">The color of the circle</param> public static RenderInstruction Circle(Vector2 center2d, float rad, double rads, bool closeCircle, Color c) { Vector3 center = center2d.ToVector3(); // number of vertices used const int quality = 43; // number of triangles used, -1 because the center vertex const int nTriangles = quality - 1; VertexPositionColor[] vertexCircle = new VertexPositionColor[quality]; vertexCircle[0].Position = center; vertexCircle[0].Color = c; // Find quality - 1 points on the circle pereferi. for (int n = 1; n < quality; n++) { double frac = n / (float) (quality - 1); double r = frac * rads; Vector3 offset = new Vector3(rad * (float)Math.Cos(r), rad * (float)Math.Sin(r), 0); vertexCircle[n].Position = center + offset; vertexCircle[n].Color = c; } // Every group of three indexes points to indexes that points to coordinates in vertexCircle. // Together, these coordinates form a triangle. int[] ind = new int[nTriangles * 3]; short ii = 0; for (; ii < ind.Length - 3; ii += 3) { // + 1 because ii start at zero, but vertexIndex start at 1 since center has index 0 int vertexIndex = (ii/ 3) + 1; // All triangles points to the center, // and two coordinates on the pereferi. // Note that the order of the two coordinates are important. ind[ii] = 0; ind[ii + 2] = vertexIndex; ind[ii + 1] = vertexIndex + 1; } // Last one that glues it together. if (closeCircle) { ind[ii] = 0; ind[ii + 2] = (short)(ii / 3 + 1); ind[ii + 1] = 1; } return new RenderInstruction(vertexCircle, ind, PrimitiveType.TriangleList); }
public static RenderInstruction Triangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) { VertexPositionColor[] vertexTriangle = new VertexPositionColor[3]; vertexTriangle[0].Position = v1.ToVector3(); vertexTriangle[1].Position = v2.ToVector3(); vertexTriangle[2].Position = v3.ToVector3(); vertexTriangle[0].Color = vertexTriangle[1].Color = vertexTriangle[2].Color = color; int[] ind = { 0, 1, 2 }; return new RenderInstruction(vertexTriangle, ind, PrimitiveType.TriangleList); }
/// <summary> /// Creates a RenderInstruction representing a line. /// </summary> /// <param name="start2d">The starting point of the line</param> /// <param name="end2d">The ending point of the line</param> /// <param name="color">The color of the line</param> public static RenderInstruction Line(Vector2 start2d, Vector2 end2d, Color color) { VertexPositionColor[] line = new VertexPositionColor[2]; line[0].Position = start2d.ToVector3(); line[1].Position = end2d.ToVector3(); line[0].Color = line[1].Color = color; int[] ind = { 0, 1 }; return new RenderInstruction(line, ind, PrimitiveType.LineList); }
public static RenderInstruction Rectangle(Vector2 topLeft2d, Vector2 dims, Color c) { Vector3 topLeft = topLeft2d.ToVector3(); Vector3 topRight = new Vector3(topLeft.X + dims.X, topLeft.Y, 0); Vector3 bottomRight = new Vector3(topLeft.X, topLeft.Y - dims.Y, 0); Vector3 bottomLeft = new Vector3(topLeft.X + dims.X, topLeft.Y - dims.Y, 0); VertexPositionColor[] vertexRectangle = new VertexPositionColor[4]; vertexRectangle[0].Position = topLeft; vertexRectangle[1].Position = topRight; vertexRectangle[2].Position = bottomRight; vertexRectangle[3].Position = bottomLeft; // Do __not__ touch the order of these. int[] ind = new int[6]; ind[0] = 0; ind[1] = 1; ind[2] = 2; ind[3] = 3; ind[4] = 2; ind[5] = 1; vertexRectangle[0].Color = vertexRectangle[1].Color = vertexRectangle[2].Color = vertexRectangle[3].Color = c; return new RenderInstruction(vertexRectangle, ind, PrimitiveType.TriangleList); }
public static Matrix CreateOrthonormalBasis(Vector2 x, Vector2 ySugg) { Vector3 z = Vector3.Cross(x.ToVector3(), ySugg.ToVector3()); if (z.LengthSquared() == 0.0) new Exception("arguments cannot be parrallel."); Vector3 y = Vector3.Cross(z, x.ToVector3()); y.Normalize(); z.Normalize(); Matrix m = new Matrix(); m.Right = x.ToVector3(); m.Up = y; m.Forward = z; m.Translation = Vector3.Zero; return m; }
public static List<Obj_AI_Base> VCollision(this Spell spell, Vector2 fromVector2, List<Vector2> to) { return spell.VCollision(fromVector2.ToVector3(), to.ToVector3()); }
/// <summary> /// Returns an Area-of-Effect cone prediction from a prediction input source. /// </summary> /// <param name="input"> /// <see cref="PredictionInput" /> input /// </param> /// <returns> /// <see cref="PredictionOutput" /> output /// </returns> public static PredictionOutput GetConePrediction(PredictionInput input) { var mainTargetPrediction = Movement.GetPrediction(input, false, true); var posibleTargets = new List<PossibleTarget> { new PossibleTarget { Position = mainTargetPrediction.UnitPosition.ToVector2(), Unit = input.Unit } }; if (mainTargetPrediction.Hitchance >= HitChance.Medium) { // Add the posible targets in range: posibleTargets.AddRange(GetPossibleTargets(input)); } if (posibleTargets.Count > 1) { var candidates = new List<Vector2>(); foreach (var target in posibleTargets) { target.Position = target.Position - input.From.ToVector2(); } for (var i = 0; i < posibleTargets.Count; i++) { for (var j = 0; j < posibleTargets.Count; j++) { if (i != j) { var p = (posibleTargets[i].Position + posibleTargets[j].Position) * 0.5f; if (!candidates.Contains(p)) { candidates.Add(p); } } } } var bestCandidateHits = -1; var bestCandidate = new Vector2(); var positionsList = posibleTargets.Select(t => t.Position).ToList(); foreach (var candidate in candidates) { var hits = GetHits(candidate, input.Range, input.Radius, positionsList); if (hits > bestCandidateHits) { bestCandidate = candidate; bestCandidateHits = hits; } } if (bestCandidateHits > 1 && input.From.ToVector2().DistanceSquared(bestCandidate) > 50 * 50) { return new PredictionOutput { Hitchance = mainTargetPrediction.Hitchance, AoeHitCount = bestCandidateHits, UnitPosition = mainTargetPrediction.UnitPosition, CastPosition = bestCandidate.ToVector3(), Input = input }; } } return mainTargetPrediction; }
public void ApplyImpulse(Vector2 impulse, Vector2 contact) { this.vel += impulse * this.InvMass; var impulsiveTorque = Vector3.Cross((contact - this.Position).ToVector3(), impulse.ToVector3()); this.ang_v += impulsiveTorque.Z * this.GetInverseInertiaMoment(); }
/// <summary> /// finds the velocity of a point rotating about another point /// </summary> /// <param name="relPos">the relative position of the point (from its center of rotation)</param> /// <param name="angVel">the angular velocity of the point</param> /// <returns></returns> public static Vector2 VelOfPoint(Vector2 relPos, float angVel) { return Vector3.Cross(angVel * Vector3.UnitZ, relPos.ToVector3()).ToVector2(); }
public int AddPoint(Vector2 point, int insertPoint) { if (insertPoint < 0 || insertPoint > _points.Count - 1) { Vector3 p = transform.InverseTransformPoint(point.ToVector3(_yPosition)); Vector2 pos = new Vector2(p.x, p.z); KeyValuePair<Vector2, Vector2> values = new KeyValuePair<Vector2,Vector2>(pos, pos); _startEndPoints.Add(values); _points.Add(pos); } else { Vector3 p = transform.InverseTransformPoint(point.ToVector3(_yPosition)); Vector2 pos = new Vector2(p.x, p.z); KeyValuePair<Vector2, Vector2> values = new KeyValuePair<Vector2, Vector2>(pos, pos); _startEndPoints.Insert(insertPoint, values); _points.Insert(insertPoint, pos); } return (insertPoint < 0 || insertPoint > _points.Count - 1) ? _points.Count - 1 : insertPoint; }
private void RecalculateCameraPosition(Vector2 cameraPosition) { cameraPositionComponent = position + cameraPosition * componentBoardRatio; cameraViewRectangle = new Rectangle( cameraPositionComponent.ToVector3(), (cameraPositionComponent + camera.ViewSize * componentBoardRatio).ToVector3(), cameraColor); }