public void DrawLine(Vector3 v1, Vector3 v2, float width, Color color, float[,] matrix) { v1 = v1.Transform(matrix); v2 = v2.Transform(matrix); float angle = (v1.ToVector2() - v2.ToVector2()).Angle() + 90; Vector3 offset = new Vector2(width / 2, angle).ToCartesian().ToVector3(); DrawTriangle(v1 + offset, v1 - offset, v2 + offset, color, Color.Transparent, Matrix.GetIdentity()); DrawTriangle(v1 - offset, v2 - offset, v2 + offset, color, Color.Transparent, Matrix.GetIdentity()); }
public void ToVector2Test() { const float TestValueA = 5.722222f; const float TestValueB = 7.5213f; const float TestValueC = -72.333e-7f; Vector3 vectorA = new Vector3(new Vector2(TestValueA, TestValueB), TestValueC); Vector2 resultA = vectorA.ToVector2(); Assert.AreEqual(resultA.X, TestValueA); Assert.AreEqual(resultA.Y, TestValueB); }
private void update_(Vector3 startV3) { //raycast to test how far we could go.. Vector3 MaxRangeTestVector3 = MathEx.GetPointAt(startV3, Range, MathEx.ToRadians(DirectionDegrees)); Vector2 RaycastTestV2; //we use main grid providers raycast to test since we are looking at how far we can travel and not if anything is blocking us. if (Navigation.MGP.Raycast(startV3.ToVector2(), MaxRangeTestVector3.ToVector2(), out RaycastTestV2)) {//Set our endpoint at the Hit point MaxRangeTestVector3 = RaycastTestV2.ToVector3(); MaxRangeTestVector3.Z = Navigation.MGP.GetHeight(MaxRangeTestVector3.ToVector2()); //adjust height acordingly! } Range = Vector3.Distance2D(ref startV3, ref MaxRangeTestVector3); //lets see if we can stand here at all? if (!Navigation.MGP.CanStandAt(MaxRangeTestVector3)) { //just because raycast set our max range, we need to see if we can use that cell as a walking point! if (!Navigation.CanRayCast(startV3, MaxRangeTestVector3, NavCellFlags.AllowWalk)) { //loop to find a walkable range. float currentRange = Range - 2.5f; float directionRadianFlipped = Navigation.FindDirection(MaxRangeTestVector3, startV3, true); int maxTestAttempts = (int)(currentRange / 2.5f); for (int i = 0; i < maxTestAttempts; i++) { Vector3 newtestPoint = MathEx.GetPointAt(MaxRangeTestVector3, currentRange, directionRadianFlipped); newtestPoint.Z = Navigation.MGP.GetHeight(newtestPoint.ToVector2());//update Z if (Navigation.CanRayCast(startV3, newtestPoint, NavCellFlags.AllowWalk)) { MaxRangeTestVector3 = newtestPoint; break; } if (currentRange - 2.5f <= 0f) break; currentRange = -2.5f; } Range = currentRange; } } EndingPoint = MaxRangeTestVector3; StartingPoint = startV3; Range = startV3.Distance2D(MaxRangeTestVector3); //(float)GridPoint.GetDistanceBetweenPoints(StartingPoint, EndingPoint); Center = MathEx.GetPointAt(startV3, Range / 2, MathEx.ToRadians(DirectionDegrees)); }
public virtual void Update() { prevPos = Pos; Speed.Y += Gravity * Global.Speed; Pos += Speed * Global.Speed; Scale += ScaleSpeed * Global.Speed; SetVertexPositions(); //Global.Output += Pos; foreach (var b in Behaviors) { b.Update(this); } if (MotionStretch) { stretchRot = -MathHelper.ToDegrees(MyMath.Direction(Pos.ToVector2(), prevPos.ToVector2())) + 90; stretchScale = MyMath.Distance((Pos - prevPos).ToVector2().ToVector3()) * 0.04f; } else { stretchRot = Rotation; stretchScale = 0; } Depth += 0.000f * Global.Speed; }
public Vector3 GetWorldPosition(Vector3 relativePosition) { var v2Diff = relativePosition.ToVector2() + Min; return new Vector3(v2Diff.X, v2Diff.Y, relativePosition.Z); }
public Vector3 GetWorldPosition(Vector3 relativePosition) { var v2Diff = relativePosition.ToVector2() + Min; return(new Vector3(v2Diff.X, v2Diff.Y, relativePosition.Z)); }
///<summary> ///Runs raycasting and intersection tests to validate LOS. ///</summary> public bool LOSTest(Vector3 PositionToTestFrom, bool NavRayCast = true, bool ServerObjectIntersection = true, NavCellFlags Flags = NavCellFlags.None, bool ContinueOnFailures = true) { LastLOSCheck = DateTime.Now; bool Failed = false; if (NavRayCast) { //This is a basic raycast test to see if we have clear view of the object. //Navigator.SearchGridProvider.Update(); Vector2 hitpos; Vector3 ObjectPosition = Obj.Position; //Must check the Z difference.. (so we don't get false-positive result) if (PositionToTestFrom.Z >= ObjectPosition.Z) { RayCast = !Navigator.SearchGridProvider.Raycast(PositionToTestFrom.ToVector2(), ObjectPosition.ToVector2(), out hitpos); } else { RayCast = !Navigator.SearchGridProvider.Raycast(ObjectPosition.ToVector2(), PositionToTestFrom.ToVector2(), out hitpos); } if (!RayCast.Value) { Failed = true; if (!ContinueOnFailures) { return(false); } } } if (ServerObjectIntersection) { //This test uses the obstacle cache to check objects for intersection Vector3 TargetTestLocation = Obj.Position; if (Funky.Difference(Bot.Character.Data.Position.Z, TargetTestLocation.Z) > 1f) { //Get actual height using MGP TargetTestLocation.Z = Navigation.MGP.GetHeight(TargetTestLocation.ToVector2()); } ObjectIntersection = ObjectCache.Obstacles.Values.OfType <CacheServerObject>() .Any(obstacle => obstacle.RAGUID != Obj.RAGUID && obstacle.Obstacletype.HasValue && obstacle.Obstacletype.Value != ObstacleType.Monster && obstacle.TestIntersection(PositionToTestFrom, TargetTestLocation)); if (!Failed && ObjectIntersection.Value) { Failed = true; if (!ContinueOnFailures) { return(false); } } } if (!Flags.Equals(NavCellFlags.None)) { //Raycast test to validate it can preform the path -- walk/projectile bool NavTest = Navigation.CanRayCast(PositionToTestFrom, Obj.Position, Flags); if (Flags.HasFlag(NavCellFlags.AllowWalk)) { NavCellWalk = NavTest; } if (Flags.HasFlag(NavCellFlags.AllowProjectile)) { NavCellProjectile = NavTest; } if (!Failed && !NavTest) { Failed = true; } } //this.LastVectorTested=PositionToTestFrom; return(!Failed); }
/// <summary> /// Seeks for the closest Vector2 to the extended Vector3. /// </summary> /// <param name="vector3">Extended SharpDX Vector3</param> /// <param name="array">Vector2 Collection</param> /// <returns>Closest Vector2</returns> public static Vector2 Closest(this Vector3 vector3, IEnumerable <Vector2> array) { return(vector3.ToVector2().Closest(array)); }
/// <summary> /// Returns the polar for vector angle (in Degrees). /// </summary> /// <param name="vector3">Extended SharpDX Vector2</param> /// <returns>Polar for Vector Angle (Degrees)</returns> public static float Polar(this Vector3 vector3) { return(vector3.ToVector2().Polar()); }
/// <summary> /// Gets if the Vector3 is inside the polygon. /// </summary> /// <param name="point">The Point</param> /// <returns>Whether the Vector3 is inside the polygon</returns> public bool IsInside(Vector3 point) { return(!this.IsOutside(point.ToVector2())); }
public CollisionObject(Entity9 entity, Vector3 position, float radius) { this.Entity = entity; this.Position = position.ToVector2(); this.Radius = radius; }
/// <summary> /// Returns if the Vector3 is in range of the spell. /// </summary> /// <param name="point">Vector3 point</param> /// <param name="range">Range</param> public bool IsInRange(Vector3 point, float range = -1) { return(IsInRange(point.ToVector2(), range)); }
/// <summary> /// TODO The get first wall point. /// </summary> /// <param name="from"> /// TODO The from. /// </param> /// <param name="to"> /// TODO The to. /// </param> /// <param name="step"> /// TODO The step. /// </param> /// <returns> /// </returns> public static Vector2?GetFirstWallPoint(Vector3 from, Vector3 to, float step = 25) { return(GetFirstWallPoint(from.ToVector2(), to.ToVector2(), step)); }
/// <summary> /// Initializes a new instance of the <see cref="RectanglePoly" /> class. /// </summary> /// <param name="start"> /// The Start /// </param> /// <param name="end"> /// The End /// </param> /// <param name="width"> /// The Width /// </param> public RectanglePoly(Vector3 start, Vector3 end, float width) : this(start.ToVector2(), end.ToVector2(), width) { }
internal override void InitVelocityConstraints(TimeStep step) { Body b1 = _body1; Body b2 = _body2; if (_enableMotor || _enableLimit) { // You cannot create a rotation limit between bodies that // both have fixed rotation. Box2DXDebug.Assert(b1._invI > 0.0f || b2._invI > 0.0f); } // Compute the effective mass matrix. Vector2 r1 = b1.GetTransform().TransformDirection(_localAnchor1 - b1.GetLocalCenter()); Vector2 r2 = b2.GetTransform().TransformDirection(_localAnchor2 - b2.GetLocalCenter()); // J = [-I -r1_skew I r2_skew] // [ 0 -1 0 1] // r_skew = [-ry; rx] // Matlab // K = [ m1+r1y^2*i1+m2+r2y^2*i2, -r1y*i1*r1x-r2y*i2*r2x, -r1y*i1-r2y*i2] // [ -r1y*i1*r1x-r2y*i2*r2x, m1+r1x^2*i1+m2+r2x^2*i2, r1x*i1+r2x*i2] // [ -r1y*i1-r2y*i2, r1x*i1+r2x*i2, i1+i2] float m1 = b1._invMass, m2 = b2._invMass; float i1 = b1._invI, i2 = b2._invI; _mass.Col1.x = m1 + m2 + r1.y * r1.y * i1 + r2.y * r2.y * i2; _mass.Col2.x = -r1.y * r1.x * i1 - r2.y * r2.x * i2; _mass.Col3.x = -r1.y * i1 - r2.y * i2; _mass.Col1.y = _mass.Col2.x; _mass.Col2.y = m1 + m2 + r1.x * r1.x * i1 + r2.x * r2.x * i2; _mass.Col3.y = r1.x * i1 + r2.x * i2; _mass.Col1.z = _mass.Col3.x; _mass.Col2.z = _mass.Col3.y; _mass.Col3.z = i1 + i2; _motorMass = 1.0f / (i1 + i2); if (_enableMotor == false) { _motorImpulse = 0.0f; } if (_enableLimit) { float jointAngle = b2._sweep.A - b1._sweep.A - _referenceAngle; if (Box2DXMath.Abs(_upperAngle - _lowerAngle) < 2.0f * Settings.AngularSlop) { _limitState = LimitState.EqualLimits; } else if (jointAngle <= _lowerAngle) { if (_limitState != LimitState.AtLowerLimit) { _impulse.z = 0.0f; } _limitState = LimitState.AtLowerLimit; } else if (jointAngle >= _upperAngle) { if (_limitState != LimitState.AtUpperLimit) { _impulse.z = 0.0f; } _limitState = LimitState.AtUpperLimit; } else { _limitState = LimitState.InactiveLimit; _impulse.z = 0.0f; } } else { _limitState = LimitState.InactiveLimit; } if (step.WarmStarting) { // Scale impulses to support a variable time step. _impulse *= step.DtRatio; _motorImpulse *= step.DtRatio; Vector2 P = _impulse.ToVector2(); b1._linearVelocity -= m1 * P; b1._angularVelocity -= i1 * (r1.Cross(P) + _motorImpulse + _impulse.z); b2._linearVelocity += m2 * P; b2._angularVelocity += i2 * (r2.Cross(P) + _motorImpulse + _impulse.z); } else { _impulse = Vector3.zero; _motorImpulse = 0.0f; } }
void OnSceneGUI() { #region - GUI Handles and vert manipulation GUIHandleSizeModifier = Mathf.Abs(SceneView.currentDrawingSceneView.camera.transform.position.z)/100f; meshPosition = generatedMesh.transform.position; //Draw the vert handles for(int i = 0; i < generatedMesh.verts.Length; i++) { Vector3 oldPoint = generatedMesh.verts[i]; Handles.color = vertHandleColour; Vector3 newPoint = Handles.FreeMoveHandle(generatedMesh.verts[i] + meshPosition, Quaternion.identity, 0.4f * GUIHandleSizeModifier, Vector3.one, Handles.DotCap); //if the handle has changed the position of any vert, update that position if(oldPoint != newPoint) { generatedMesh.verts[i] = newPoint - meshPosition; } } //Draw the handle at the centre point of all verts Handles.color = centerPointColour; Vector3 centreOffset = Handles.FreeMoveHandle(generatedMesh.verts.GetCenterPointFromCollection() + meshPosition, Quaternion.identity, 0.6f * GUIHandleSizeModifier, Vector3.one, Handles.DotCap); //Update the positions of the verts if the centre point has been changed Vector3 centreOffSetDist = (generatedMesh.verts.GetCenterPointFromCollection() + meshPosition) - centreOffset; if(centreOffSetDist != Vector3.zero) { generatedMesh.transform.position = generatedMesh.transform.position - centreOffSetDist; } //Display the delete position of individual verts if selected Handles.color = deletePositionColour; if(vertDeletionIndex != -1) Handles.DrawSolidDisc(generatedMesh.verts[vertDeletionIndex] + meshPosition, Vector3.forward, 0.6f * GUIHandleSizeModifier); //Draw the selection rectangle if(drawSelectionRectangle) { Handles.color = Color.green; Handles.DrawSolidRectangleWithOutline(selectionRectangleVerts, selectionRectangleFillColour, selectionRectangleLineColour); } //Draw discs on selection of multiple verts if(indexesOfVertsWithinSelectionRectangle.Count > 0) { Handles.color = vertSelectedColour; for(int i = 0; i < indexesOfVertsWithinSelectionRectangle.Count; i++) { Handles.DrawSolidDisc(generatedMesh.verts[indexesOfVertsWithinSelectionRectangle[i]] + meshPosition, Vector3.forward, 0.7f * GUIHandleSizeModifier); } //Draw centre point of selected verts Handles.color = Color.red; Vector3 offSet = Handles.FreeMoveHandle(selectedVertsCentrePoint, Quaternion.identity, 0.7f * GUIHandleSizeModifier, Vector3.one, Handles.DotCap); //if the central handle of the selected points has been moved, move all the individual selected verts if(offSet != selectedVertsCentrePoint) { Vector3 offSetDist = (selectedVertsCentrePoint - offSet); for(int i = 0; i < indexesOfVertsWithinSelectionRectangle.Count; i++) { generatedMesh.verts[indexesOfVertsWithinSelectionRectangle[i]] = generatedMesh.verts[indexesOfVertsWithinSelectionRectangle[i]] - new Vector3(offSetDist.x, offSetDist.y, 0); } selectedVertsCentrePoint = offSet.RoundVector3To(generatedMesh.deltaLimiter); } } generatedMesh.CalculateVerts(); #endregion #region - MOUSE AND INPUT EVENTS int controlID = GUIUtility.GetControlID(FocusType.Passive); switch(Event.current.GetTypeForControl(controlID)) { case EventType.MouseDown: GUIUtility.hotControl = controlID; //Get the delete position if (Event.current.button == 1 && Event.current.clickCount == 1) { //Destruction of a point. Get the closest point from mouse click using vector2.distance Ray worldRay = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition); Vector3 mouseClickPos2D = new Vector3(worldRay.origin.x, worldRay.origin.y, 0f) - meshPosition; mouseDragRectStartPos = -mouseClickPos2D; vertDeletionIndex = mouseClickPos2D.IndexOfClosestPointInArray(generatedMesh.verts); } //delete the position on double click if (Event.current.button == 1 && Event.current.clickCount == 2) { if(vertDeletionIndex != -1) { generatedMesh.DeleteVertPosition(vertDeletionIndex); vertDeletionIndex = -1; } } //reset the delete position if (Event.current.button == 0 && Event.current.clickCount == 1) { Ray worldRay = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition); mouseDragRectStartPos = new Vector2(worldRay.origin.x, worldRay.origin.y); if(vertDeletionIndex != -1) vertDeletionIndex = -1; } //Creation of a new vert postion if (Event.current.button == 0 && Event.current.clickCount == 2) { Ray worldRay = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition); Vector3 mouseClickPos2D = new Vector3(worldRay.origin.x, worldRay.origin.y, 0f) - meshPosition; if(!mouseClickPos2D.Equals(Vector3.zero)) if(!generatedMesh.isVertPositionTaken(mouseClickPos2D)) generatedMesh.AddNewVertPosition(mouseClickPos2D); generatedMesh.ReOrganiseVertIndexes(); generatedMesh.CalculateVerts(); Repaint(); } //Scroll wheel button is pushed down if(Event.current.button == 2) { GUIUtility.hotControl = 0; Selection.activeGameObject = null; } Event.current.Use(); break; case EventType.MouseDrag: if(Event.current.button == 0) { //draw the dragwindow if(GUIUtility.hotControl == controlID) { Ray worldRay = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition); mouseDragRectEndPos = new Vector2(worldRay.origin.x, worldRay.origin.y); float selectionRectangleWidth = mouseDragRectEndPos.x - mouseDragRectStartPos.x; float selectionRectangleHeight = mouseDragRectEndPos.y - mouseDragRectStartPos.y; if(!drawSelectionRectangle) drawSelectionRectangle = true; selectionRectangleVerts[0] = new Vector3(mouseDragRectStartPos.x, mouseDragRectStartPos.y, 0f); selectionRectangleVerts[1] = new Vector3(mouseDragRectStartPos.x + selectionRectangleWidth, mouseDragRectStartPos.y, 0f); selectionRectangleVerts[2] = new Vector3(mouseDragRectStartPos.x + selectionRectangleWidth, (mouseDragRectStartPos.y + selectionRectangleHeight), 0f); selectionRectangleVerts[3] = new Vector3(mouseDragRectStartPos.x, (mouseDragRectStartPos.y + selectionRectangleHeight), 0f); } } Event.current.Use(); break; case EventType.MouseUp: if(GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; //Selection Rectangle Position List<Vector2> selectionPositions = new List<Vector2>(); if(drawSelectionRectangle) { //Get a collection of all the vert indexes that are within the rectangle valume just drawn List <int> indexesOfVertsWithinSelectionRectangleNew = new List<int>(); for(int i = 0; i < generatedMesh.verts.Length; i++) { if(generatedMesh.verts[i].ToVector2().isPositionWithinRectangleVolume(mouseDragRectStartPos - meshPosition, mouseDragRectEndPos - meshPosition)) { indexesOfVertsWithinSelectionRectangleNew.Add(i); selectionPositions.Add(generatedMesh.verts[i].ToVector2()); } } if(indexesOfVertsWithinSelectionRectangle.Count > 0) indexesOfVertsWithinSelectionRectangle.Clear(); indexesOfVertsWithinSelectionRectangle = indexesOfVertsWithinSelectionRectangleNew; selectedVertsCentrePoint = selectionPositions.GetCenterPointFromCollection() + meshPosition.ToVector2(); drawSelectionRectangle = false; } else if(indexesOfVertsWithinSelectionRectangle.Count > 0) indexesOfVertsWithinSelectionRectangle.Clear(); } Event.current.Use(); break; //Exit the selection of this gameobject case EventType.KeyDown: Event e = Event.current; if(e.keyCode == KeyCode.Escape) Selection.activeGameObject = null; //If multiple verts are currently selected, delete them if(e.keyCode == KeyCode.Delete) { if(indexesOfVertsWithinSelectionRectangle.Count > 0) { generatedMesh.DeleteVertPositions(indexesOfVertsWithinSelectionRectangle.ToArray()); indexesOfVertsWithinSelectionRectangle.Clear(); generatedMesh.CalculateVerts(); } } GUIUtility.hotControl = 0; Event.current.Use(); break; } #endregion if(GUI.changed) EditorUtility.SetDirty(target); }
/// <summary> /// Converts Vector3 to 2D, then adds it to the points. /// </summary> /// <param name="point">Point</param> public void Add(Vector3 point) { Points.Add(point.ToVector2()); }
/// <summary> /// Initializes a new instance of the <see cref="ArcPoly" /> class, after converting the points to 2D. /// </summary> /// <param name="start"> /// Start of the Arc /// </param> /// <param name="direction"> /// Direction of the Arc /// </param> /// <param name="angle"> /// Angle of the Arc /// </param> /// <param name="radius"> /// Radius of the Arc /// </param> /// <param name="quality"> /// Quality of the Arc /// </param> public ArcPoly(Vector3 start, Vector3 direction, float angle, float radius, int quality = 20) : this(start.ToVector2(), direction.ToVector2(), angle, radius, quality) { }
/// <summary> /// Converts Vector3 to 2D, then adds it to the points. /// </summary> /// <param name="point">The Point</param> public void Add(Vector3 point) { this.Points.Add(point.ToVector2()); }
/// <summary> /// Initializes a new instance of the <see cref="LinePoly" /> class. /// </summary> /// <param name="start"> /// The Start /// </param> /// <param name="end"> /// The End /// </param> /// <param name="length"> /// Length of line(will be automatically set if -1) /// </param> public LinePoly(Vector3 start, Vector3 end, float length = -1) : this(start.ToVector2(), end.ToVector2(), length) { }
/// <summary> /// Checks for if the extended Vector3 is valid. /// </summary> /// <param name="vector3"> /// SharpDX Vector3 /// </param> /// <returns> /// The <see cref="bool" />. /// </returns> public static bool IsValid(this Vector3 vector3) { return(vector3.ToVector2().IsValid()); }
void Update() { // Read input if (Input.GetButtonDown("Inventory")) { SetHUDVisable(true); } if (isOpen) { for (int slot = 1; slot <= 4; slot++) { if (hoverKey == slot - 1 && Input.GetButtonUp("Slot " + slot)) { SetHUDVisable(false); inventory.Equip(hoverKey); return; } } // Hotkeys bool allUp = true; for (int slot = 1; slot <= 4; slot++) { if (Input.GetButtonDown("Slot " + slot)) { hoverKey = slot - 1; } if (Input.GetButton("Slot "+ slot)) { allUp = false; } } if (allUp) hoverKey = -1; // Mouse if (hoverKey == -1) { mouseDelta = CalcMouseDelta(); hoverMouse = CalcSelected(mouseDelta.ToVector2()); if (hoverMouse != -1 && Input.GetMouseButtonUp(0)) { SetHUDVisable(false); inventory.Equip(hoverMouse); return; } } SetHover(hoverKey == -1 ? hoverMouse : hoverKey); // Close inventory if (Input.GetButtonUp("Inventory")) { SetHUDVisable(false); if (hoverKey != -1) inventory.Equip(hoverKey); else if (inventory.equipped != null && inventory.equipped is _CoreItem) inventory.Unequip(); } } }
/// <summary> /// Angle between a entity and a vector in degrees /// </summary> /// <param name="entity"> /// The entity. /// </param> /// <param name="vector"> /// The vector. /// </param> /// <param name="radian"> /// The radian. /// </param> /// <returns> /// The <see cref="float" />. /// </returns> public static float FindAngleBetween(this Entity entity, Vector3 vector, bool radian = false) { return(entity.Position.ToVector2().FindAngleBetween(vector.ToVector2(), radian)); }
/// <summary> /// Returns if the Vector3 position is a wall. /// </summary> /// <param name="vector3">Extended SharpDX Vector3</param> /// <returns>Is Vector3 position a wall position</returns> public static bool LSIsWall(this Vector3 vector3) { return(vector3.ToVector2().IsWall()); }
static Vector2 V2E(Vector3 from, Vector3 direction, float distance) { return(from.ToVector2() + distance * Vector3.Normalize(direction - from).ToVector2()); }
/// <summary> /// Returns the angle between two vectors. /// </summary> /// <param name="vector3">Extended SharpDX Vector3</param> /// <param name="toVector2">SharpDX Vector2</param> /// <returns>Angle between two vectors in float-units</returns> public static float AngleBetween(this Vector3 vector3, Vector2 toVector2) { return(vector3.ToVector2().AngleBetween(toVector2)); }
public static void Universe(EventArgs args) { if (!Game.IsInGame || Game.IsPaused || Game.IsWatchingGame) { return; } me = ObjectManager.LocalHero; if (me == null || me.HeroId != HeroId.npc_dota_hero_enigma) { return; } if (Game.IsKeyDown(Menu.Item("Black Hole Key!").GetValue <KeyBind>().Key) && !Game.IsChatOpen) { FindItems(); if (me.CanCast() && !me.IsChanneling()) { mousepos = Game.MousePosition; if (me.Distance2D(mousepos) <= ((blink != null /*&& blink.CanBeCasted()*/) ? (1200 + blackhole.CastRange) : blackhole.CastRange)) { if (Utils.SleepCheck("blackhole")) { if ((glimmer != null && Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(glimmer.Name)) && glimmer.CanBeCasted() && Utils.SleepCheck("glimmer") && blackhole.CanBeCasted() && me.Mana > blackhole.ManaCost + glimmer.ManaCost) { glimmer.UseAbility(me, false); Utils.Sleep(200, "glimmer"); } if (!blackhole.CanBeCasted() && blackhole.Level > 0 && (refresher != null && Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(refresher.Name)) && refresher.CanBeCasted() && Utils.SleepCheck("refresher") && me.Mana > refresher.ManaCost + blackhole.ManaCost) { refresher.UseAbility(false); Utils.Sleep(2000, "refresher"); } if ((bkb != null && Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(bkb.Name)) && bkb.CanBeCasted() && Utils.SleepCheck("bkb") && blackhole.CanBeCasted()) { bkb.UseAbility(false); Utils.Sleep(200, "bkb"); } if ((blink != null && Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(blink.Name)) && blink.CanBeCasted() && Utils.SleepCheck("blink") && me.Distance2D(mousepos) >= blackhole.CastRange && blackhole.CanBeCasted()) { blink.UseAbility(me.Distance2D(mousepos) < 1200 ? mousepos : new Vector3(me.NetworkPosition.X + 1150 * (float)Math.Cos(me.NetworkPosition.ToVector2().FindAngleBetween(mousepos.ToVector2(), true)), me.NetworkPosition.Y + 1150 * (float)Math.Sin(me.NetworkPosition.ToVector2().FindAngleBetween(mousepos.ToVector2(), true)), 100), false); Utils.Sleep(200, "blink"); } if ((veil != null && Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(veil.Name)) && veil.CanBeCasted() && Utils.SleepCheck("veil") && me.Mana > veil.ManaCost + blackhole.ManaCost && blackhole.CanBeCasted()) { veil.UseAbility(mousepos, false); Utils.Sleep(200, "veil"); } if ((midnightpulse != null && Menu.Item("Skills: ").GetValue <AbilityToggler>().IsEnabled(midnightpulse.Name)) && midnightpulse.CanBeCasted() && Utils.SleepCheck("pulse") && me.Mana > midnightpulse.ManaCost + blackhole.ManaCost && blackhole.CanBeCasted()) { midnightpulse.UseAbility(mousepos, false); Utils.Sleep(200, "pulse"); } if ((shivas != null && Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(shivas.Name)) && shivas.CanBeCasted() && Utils.SleepCheck("shivas") && me.Mana > shivas.ManaCost + blackhole.ManaCost && blackhole.CanBeCasted()) { shivas.UseAbility(false); Utils.Sleep(200, "shivas"); } } if ((!blink.CanBeCasted() || me.Distance2D(mousepos) <= blackhole.CastRange || (blink != null && !Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(blink.Name))) && (!veil.CanBeCasted() || me.Mana < veil.ManaCost + blackhole.ManaCost || (veil != null && !Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(veil.Name))) && (!midnightpulse.CanBeCasted() || me.Mana < midnightpulse.ManaCost + blackhole.ManaCost || (midnightpulse != null && !Menu.Item("Skills: ").GetValue <AbilityToggler>().IsEnabled(midnightpulse.Name))) && (!bkb.CanBeCasted() || (bkb != null && !Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(bkb.Name))) && (!shivas.CanBeCasted() || me.Mana < shivas.ManaCost + blackhole.ManaCost || (shivas != null && !Menu.Item("Items: ").GetValue <AbilityToggler>().IsEnabled(shivas.Name)))) { target = ObjectManager.GetEntities <Hero>().FirstOrDefault(x => x.IsAlive && !x.IsIllusion && x.IsValid && x.NetworkPosition.Distance2D(mousepos) < 420 && x.Team != me.Team); if (Menu.Item("Safe Black Hole").GetValue <bool>()) { if (target != null) { SafeBlackHole = true; } else { SafeBlackHole = false; } } else { SafeBlackHole = true; } if ((blackhole != null && Menu.Item("Skills: ").GetValue <AbilityToggler>().IsEnabled(blackhole.Name)) && blackhole.CanBeCasted() && Utils.SleepCheck("blackhole") && SafeBlackHole) { blackhole.UseAbility(mousepos, false); Utils.Sleep(2000, "blackhole"); } } } else { if (me.CanMove()) { me.Move(mousepos, false); } } } } }
/// <summary> /// Converts the points to 2D, then returns the projection of the Vector2 on the segment. /// </summary> /// <param name="point">Point</param> /// <param name="segmentStart">Start of Segment</param> /// <param name="segmentEnd">End of Segment</param> /// <returns><see cref="ProjectionInfo" /> containing the projection.</returns> public static ProjectionInfo ProjectOn(this Vector3 point, Vector3 segmentStart, Vector3 segmentEnd) { return(point.ToVector2().ProjectOn(segmentStart.ToVector2(), segmentEnd.ToVector2())); }
//Special Movements public Vector3 FindZigZagTargetLocation(Vector3 vTargetLocation, float fDistanceOutreach, bool bRandomizeDistance = false, bool bRandomizeStart = false) { var rndNum = new Random(int.Parse(Guid.NewGuid().ToString().Substring(0, 8), NumberStyles.HexNumber)); float iFakeStart = 0; //K: bRandomizeStart is for boss and elite, they usually jump around, make obstacles, let you Incapacitated. // you usually have to move back and forth to hit them if (bRandomizeStart) { iFakeStart = rndNum.Next(18) * 5; } if (bRandomizeDistance) { fDistanceOutreach += rndNum.Next(18); } float fDirectionToTarget = FindDirection(Bot.Character.Data.Position, vTargetLocation); float fHighestWeight = float.NegativeInfinity; Vector3 vBestLocation = Vector3.Zero; bool bFoundSafeSpotsFirstLoop = false; float fAdditionalRange = 0f; //K: Direction is more important than distance for (int iMultiplier = 1; iMultiplier <= 2; iMultiplier++) { if (iMultiplier == 2) { if (bFoundSafeSpotsFirstLoop) { break; } fAdditionalRange = 150f; if (bRandomizeStart) { iFakeStart = 30f + (rndNum.Next(16) * 5); } else { iFakeStart = (rndNum.Next(17) * 5); } } float fRunDistance = fDistanceOutreach; for (float iDegreeChange = iFakeStart; iDegreeChange <= 30f + fAdditionalRange; iDegreeChange += 5) { float iPosition = iDegreeChange; //point to target is better, otherwise we have to avoid obstacle first if (iPosition > 105f) { iPosition = 90f - iPosition; } else if (iPosition > 30f) { iPosition -= 15f; } else { iPosition = 15f - iPosition; } float fPointToTarget = iPosition; iPosition += fDirectionToTarget; if (iPosition < 0) { iPosition = 360f + iPosition; } if (iPosition >= 360f) { iPosition = iPosition - 360f; } Vector3 vThisZigZag = MathEx.GetPointAt(Bot.Character.Data.Position, fRunDistance, MathEx.ToRadians(iPosition)); if (fPointToTarget <= 30f || fPointToTarget >= 330f) { vThisZigZag.Z = vTargetLocation.Z; } else if (fPointToTarget <= 60f || fPointToTarget >= 300f) { //K: we are trying to find position that we can circle around the target // but we shouldn't run too far away from target vThisZigZag.Z = (vTargetLocation.Z + Bot.Character.Data.Position.Z) / 2; fRunDistance = fDistanceOutreach - 5f; } else { //K: don't move too far if we are not point to target, we just try to move // this can help a lot when we are near stairs fRunDistance = 8f; } bool bCanRayCast = MGP.CanStandAt(vThisZigZag); // Give weight to each zigzag point, so we can find the best one to aim for if (bCanRayCast) { const bool bAnyAvoidance = false; // Starting weight is 1000f float fThisWeight = 1000f; if (iMultiplier == 2) { fThisWeight -= 80f; } if (Bot.Character.Data.ShouldFlee && ObjectCache.Objects.IsPointNearbyMonsters(vThisZigZag, Bot.Settings.Fleeing.FleeMaxMonsterDistance)) { continue; } if (ObjectCache.Obstacles.Navigations.Any(obj => obj.Obstacletype.Value != ObstacleType.Monster && obj.TestIntersection(Bot.Character.Data.Position, vThisZigZag, false))) { continue; } float distanceToTarget = vTargetLocation.Distance2D(Bot.Character.Data.Position); fThisWeight += (distanceToTarget * 10f); // Use this one if it's more weight, or we haven't even found one yet, or if same weight as another with a random chance if (fThisWeight > fHighestWeight) { fHighestWeight = fThisWeight; vBestLocation = new Vector3(vThisZigZag.X, vThisZigZag.Y, MGP.GetHeight(vThisZigZag.ToVector2())); if (!bAnyAvoidance) { bFoundSafeSpotsFirstLoop = true; } } } // Can we raycast to the point at minimum? } // Loop through degrees } // Loop through multiplier return(vBestLocation); }
public Vector3 GetRelativePosition(Vector3 worldPosition) { var v2Diff = worldPosition.ToVector2() - Min; return(new Vector3(v2Diff.X, v2Diff.Y, worldPosition.Z)); }
/// <summary> /// Resets usage variables and sets the target location or target ID depending on what condition passed. /// </summary> /// <param name="ability"></param> /// <param name="obj"></param> /// <param name="Destructible"></param> public static void SetupAbilityForUse(ref Skill ability, CacheObject obj, bool Destructible = false) { ability.MinimumRange = ability.Range; ability.TargetPosition_ = Vector3.Zero; ability._targetAcdguid = -1; ability.WaitLoopsBefore_ = ability.WaitVars.PreLoops; ability.WaitLoopsAfter_ = ability.WaitVars.PostLoops; ability.CanCastFlags = PowerManager.CanCastFlags.None; ability.SuccessUsed_ = null; ability.Target_ = null; ability.preActivationFinished = false; ability.ActivationFinished = false; ability.postActivationFinished = false; //Destructible Setup if (Destructible) { if (!ability.IsRanged) { ability.MinimumRange = 8f; } else { ability.MinimumRange = 30f; } bool LocationalAttack = (CacheIDLookup.hashDestructableLocationTarget.Contains(obj.SNOID) || DateTime.Now.Subtract(PowerCacheLookup.dictAbilityLastFailed[ability.Power]).TotalMilliseconds < 1000); if (LocationalAttack) { Vector3 attacklocation = obj.Position; if (!ability.IsRanged) { //attacklocation=MathEx.CalculatePointFrom(FunkyGame.Hero.Class_.Data.Position,Bot.Target.CurrentTarget.Position, 0.25f); attacklocation = MathEx.GetPointAt(FunkyGame.Hero.Position, 0.50f, Navigation.Navigation.FindDirection(FunkyGame.Hero.Position, obj.Position, true)); } else { attacklocation = MathEx.GetPointAt(obj.Position, 1f, Navigation.Navigation.FindDirection(obj.Position, FunkyGame.Hero.Position, true)); } attacklocation.Z = Navigation.Navigation.MGP.GetHeight(attacklocation.ToVector2()); ability.TargetPosition = attacklocation; } else { if (obj.AcdGuid.HasValue) { ability.TargetACDGUID = obj.AcdGuid.Value; } } return; } if (ability.LastConditionPassed == ConditionCriteraTypes.Cluster) { CacheUnit ClusterUnit; //Cluster Target -- Aims for Centeroid Unit if (ObjectCache.CheckFlag(ability.ExecutionType, SkillExecutionFlags.ClusterTarget) && CheckClusterConditions(ability.LastClusterConditionSuccessful)) //Cluster ACDGUID { ClusterUnit = FunkyGame.Targeting.Cache.Clusters.AbilityClusterCache(ability.LastClusterConditionSuccessful)[0].GetNearestUnitToCenteroid(); if (ClusterUnit.AcdGuid.HasValue) { ability.TargetACDGUID = ClusterUnit.AcdGuid.Value; } ability.Target_ = ClusterUnit; return; } //Cluster Location -- Aims for Center of Cluster if (ObjectCache.CheckFlag(ability.ExecutionType, SkillExecutionFlags.ClusterLocation) && CheckClusterConditions(ability.LastClusterConditionSuccessful)) //Cluster Target Position { ability.TargetPosition = (Vector3)FunkyGame.Targeting.Cache.Clusters.AbilityClusterCache(ability.LastClusterConditionSuccessful)[0].Midpoint; return; } //Cluster Location Nearest if (ObjectCache.CheckFlag(ability.ExecutionType, SkillExecutionFlags.ClusterLocationNearest) && CheckClusterConditions(ability.LastClusterConditionSuccessful)) //Cluster Target Position { ability.TargetPosition = FunkyGame.Targeting.Cache.Clusters.AbilityClusterCache(ability.LastClusterConditionSuccessful)[0].ListUnits[0].Position; return; } //Cluster Target Nearest -- Gets nearest unit in cluster as target. if (ObjectCache.CheckFlag(ability.ExecutionType, SkillExecutionFlags.ClusterTargetNearest) && CheckClusterConditions(ability.LastClusterConditionSuccessful)) //Cluster Target Position { ClusterUnit = FunkyGame.Targeting.Cache.Clusters.AbilityClusterCache(ability.LastClusterConditionSuccessful)[0].ListUnits[0]; if (ClusterUnit.AcdGuid.HasValue) { ability.TargetACDGUID = ClusterUnit.AcdGuid.Value; } ability.Target_ = ClusterUnit; return; } } if (ObjectCache.CheckFlag(ability.ExecutionType, SkillExecutionFlags.Location)) //Current Target Position { ability.TargetPosition = obj.Position; ability.Target_ = (CacheUnit)obj; } else if (ObjectCache.CheckFlag(ability.ExecutionType, SkillExecutionFlags.Self)) //Current Bot Position { ability.TargetPosition = FunkyGame.Hero.Position; } else if (ObjectCache.CheckFlag(ability.ExecutionType, SkillExecutionFlags.ZigZagPathing)) //Zig-Zag Pathing { FunkyGame.Navigation.vPositionLastZigZagCheck = FunkyGame.Hero.Position; if (FunkyGame.Hero.Class.ShouldGenerateNewZigZagPath()) { FunkyGame.Hero.Class.GenerateNewZigZagPath(); } ability.TargetPosition = FunkyGame.Navigation.vSideToSideTarget; } else if (ObjectCache.CheckFlag(ability.ExecutionType, SkillExecutionFlags.Target)) //Current Target ACDGUID { if (obj is CacheUnit) { ability.Target_ = (CacheUnit)obj; } if (obj.AcdGuid.HasValue) { ability.TargetACDGUID = obj.AcdGuid.Value; } } }
public Vector3 GetRelativePosition(Vector3 worldPosition) { var v2Diff = worldPosition.ToVector2() - Min; return new Vector3(v2Diff.X, v2Diff.Y, worldPosition.Z); }
/// <summary> /// Extends a Vector2 to a Vector3. /// </summary> /// <param name="vector2">Extended SharpDX Vector2 (From)</param> /// <param name="toVector3">SharpDX Vector3 (To)</param> /// <param name="distance">Distance (float units)</param> /// <returns>Extended Vector2</returns> public static Vector2 Extend(this Vector2 vector2, Vector3 toVector3, float distance) { return(vector2 + distance * (toVector3.ToVector2() - vector2).Normalized()); }
/// <summary> /// Initializes a new instance of the <see cref="CirclePoly" /> class. /// </summary> /// <param name="center"> /// The Center /// </param> /// <param name="radius"> /// The Radius /// </param> /// <param name="quality"> /// The Quality /// </param> public CirclePoly(Vector3 center, float radius, int quality = 20) : this(center.ToVector2(), radius, quality) { }
/// <summary> /// Calculates the squared distance between two vectors. /// </summary> /// <param name="vector2">Extended SharpDX Vector2</param> /// <param name="toVector3">SharpDX Vector3</param> /// <returns>The squared distance between the two vectors.</returns> public static float DistanceSquared(this Vector2 vector2, Vector3 toVector3) { return(Vector2.DistanceSquared(vector2, toVector3.ToVector2())); }
/// <summary> /// Returns if the Vector3 is in range of the spell. /// </summary> /// <param name="point"> /// Vector3 point /// </param> /// <param name="otherRange"> /// The Range /// </param> /// <returns> /// The <see cref="bool" />. /// </returns> public bool IsInRange(Vector3 point, float otherRange = -1) { return(this.IsInRange(point.ToVector2(), otherRange)); }
/// <summary> /// Initializes a new instance of the <see cref="Rectangle" /> class. /// </summary> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="width">The width.</param> public Rectangle(Vector3 start, Vector3 end, float width) : this(start.ToVector2(), end.ToVector2(), width) { }
public static int CountAllyMinions(this Vector3 position, float range) { return(GameObjects.AllyMinions.Count(m => m.LSIsInRange(position.ToVector2(), range) && m.IsValid)); }
/// <summary> /// Calculates the distance between the extended Vector3 and a Vector3. /// </summary> /// <param name="vector3">SharpDX Vector3 (From)</param> /// <param name="toVector3">SharpDX Vector3 (To)</param> /// <returns>Float Units</returns> public static float Distance(this Vector3 vector3, Vector3 toVector3) { return(vector3.ToVector2().Distance(toVector3)); }
public void DrawPoint(Vector3 point, float overrideZ, float size, Color color, float[,] matrix) { point = point.Transform(matrix); Vector2 min = (point.ToVector2() - new Vector2(size)).ClampVector2(Vector2.Zero, ScreenSize.ToVector2()); Vector2 max = (point.ToVector2() + new Vector2(size)).ClampVector2(Vector2.Zero, ScreenSize.ToVector2()); if (overrideZ == 0) overrideZ = point.Z; for (int xp = (int)min.X; xp < max.X; xp++) for (int yp = (int)min.Y; yp < max.Y; yp++) DrawPoint(new Vector3(xp ,yp, overrideZ), color, Matrix.GetIdentity()); }
/// <summary> /// Calculates the squared distance between two vectors. /// </summary> /// <param name="vector3">Extended SharpDX Vector3</param> /// <param name="toVector2">SharpDX Vector2</param> /// <returns>The squared distance between the two vectors.</returns> public static float DistanceSquared(this Vector3 vector3, Vector2 toVector2) { return(vector3.ToVector2().DistanceSquared(toVector2)); }
/// <summary> /// Gets if the Vector3 is inside the polygon. /// </summary> /// <param name="point">The Point</param> /// <returns>Whether the Vector3 is inside the polygon</returns> public bool IsInside(Vector3 point) { return !this.IsOutside(point.ToVector2()); }
/// <summary> /// Returns if the angle is orthogonal. /// </summary> /// <param name="vector3">Extended SharpDX Vector3</param> /// <param name="toVector2">SharpDX Vector2</param> /// <returns>Returns if the angle is orthogonal</returns> public static bool IsOrthogonal(Vector3 vector3, Vector2 toVector2) { return(vector3.ToVector2().IsOrthogonal(toVector2)); }
/// <summary> /// Returns a list of predicted minion positions. /// </summary> /// <param name="minions"> /// Given Minion List /// </param> /// <param name="delay"> /// Skill-shot Delay /// </param> /// <param name="width"> /// Skill-shot Width /// </param> /// <param name="speed"> /// Skill-shot Speed /// </param> /// <param name="from"> /// The From /// </param> /// <param name="range"> /// Skill-shot Range /// </param> /// <param name="collision"> /// Has Collision Flag /// </param> /// <param name="stype"> /// Skill-shot Type /// </param> /// <param name="rangeCheckFrom"> /// Range check from Vector3 source /// </param> /// <returns> /// List of Points in <see cref="Vector2" /> type /// </returns> public static List<Vector2> GetMinionsPredictedPositions( List<Obj_AI_Base> minions, float delay, float width, float speed, Vector3 from, float range, bool collision, SkillshotType stype, Vector3 rangeCheckFrom = new Vector3()) { from = from.ToVector2().IsValid() ? from : ObjectManager.Player.ServerPosition; return (from minion in minions select Movement.GetPrediction( new PredictionInput { Unit = minion, Delay = delay, Radius = width, Speed = speed, From = @from, Range = range, Collision = collision, Type = stype, RangeCheckFrom = rangeCheckFrom }) into pos where pos.Hitchance >= HitChance.High select pos.UnitPosition.ToVector2()).ToList(); }
/// <summary> /// Returns whether the given position is under a enemy turret /// </summary> /// <param name="position">Extended SharpDX Vector3</param> /// <returns>Is Position under a turret</returns> public static bool IsUnderEnemyTurret(this Vector3 position) { return(position.ToVector2().IsUnderEnemyTurret()); }