forked from totalschaden/copilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.cs
35 lines (31 loc) · 1.39 KB
/
Helper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using SharpDX;
using ExileCore.PoEMemory.MemoryObjects;
namespace CoPilot;
public static class Helper
{
internal static Random random = new Random();
private static Camera Camera => CoPilot.Instance.GameController.Game.IngameState.Camera;
internal static float MoveTowards(float cur, float tar, float max)
{
if (Math.Abs(tar - cur) <= max)
return tar;
return cur + Math.Sign(tar - cur) * max;
}
internal static Vector2 WorldToValidScreenPosition(Vector3 worldPos)
{
var windowRect = CoPilot.Instance.GameController.Window.GetWindowRectangle();
var screenPos = Camera.WorldToScreen(worldPos);
var result = screenPos + windowRect.Location;
var edgeBounds = 50;
if (!windowRect.Intersects(new RectangleF(result.X, result.Y, edgeBounds, edgeBounds)))
{
//Adjust for offscreen entity. Need to clamp the screen position using the game window info.
if (result.X < windowRect.TopLeft.X) result.X = windowRect.TopLeft.X + edgeBounds;
if (result.Y < windowRect.TopLeft.Y) result.Y = windowRect.TopLeft.Y + edgeBounds;
if (result.X > windowRect.BottomRight.X) result.X = windowRect.BottomRight.X - edgeBounds;
if (result.Y > windowRect.BottomRight.Y) result.Y = windowRect.BottomRight.Y - edgeBounds;
}
return result;
}
}