Created
May 19, 2020 11:51
-
-
Save krjan02/dd3a3d0cc22ea6fcce3675524785f99f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Vector2 RotatePoint(Vector2 pointToRotate, Vector2 centerPoint, float angle, bool angleInRadians = false) | |
{ | |
if (!angleInRadians) | |
angle = (float)(angle * (3.14159265358979323846f / 180.f)); | |
float cosTheta = (float)cos(angle); | |
float sinTheta = (float)sin(angle); | |
Vector2 returnVec( | |
cosTheta * (pointToRotate.x - centerPoint.x) + sinTheta * (pointToRotate.y - centerPoint.y), | |
sinTheta * (pointToRotate.x - centerPoint.x) - cosTheta * (pointToRotate.y - centerPoint.y) | |
); | |
returnVec += centerPoint; | |
return returnVec; | |
} | |
static float NormalizeVector2D(Vector2& v) | |
{ | |
float l = v.len(); | |
if (l != 0.0f) | |
v /= l; | |
else | |
v.x = v.y = 0.0f; | |
return l; | |
} | |
float m_x, m_y, m_w, m_h; | |
Vector2 ScaleToRadar(Vector3 localPos,Vector3 enemyPos,Vector3 localViewAngle) | |
{ | |
Vector2 radarCentre((m_x + m_w / 2) - 2, (m_y + m_h / 2) - 2); | |
Vector3 enemyPos3D = enemyPos; | |
Vector2 enemyPos2D(enemyPos3D.x, enemyPos3D.y); | |
Vector3 localPos3D = localPos; | |
Vector2 localPos2D(localPos3D.x, localPos3D.y); | |
Vector2 screenPos = localPos2D - enemyPos2D; | |
float distance = screenPos.len() * (0.02f * 100); // Distance | |
// distance = min(distance, m_x); circle radar | |
NormalizeVector2D(screenPos); | |
screenPos *= distance; | |
screenPos += radarCentre; | |
return RotatePoint(screenPos, radarCentre, localViewAngle.y + 90); | |
} | |
bool IsInRadarBounds(Vector2 position) | |
{ | |
const int offset = 5; | |
return (position.x > m_x + offset - 3 && position.x < m_x - offset + m_w && position.y > m_y + offset - 3 && position.y < m_y - offset + m_h); | |
} | |
double vis::draw_radar() | |
{ | |
m_h = 300; | |
m_w = 300; | |
m_x = 100; | |
m_y = 100; | |
const int titleBarOffset = 12; | |
Vector4 col = Vector4(espColors::fTeamESPBoxColor[0] * 255, espColors::fTeamESPBoxColor[1] * 255, espColors::fTeamESPBoxColor[2] * 255, 100); | |
Vector4 col2 = Vector4(espColors::fEnemyESPBoxColor[0] * 255, espColors::fEnemyESPBoxColor[1] * 255, espColors::fEnemyESPBoxColor[2] * 255, 255); | |
rnd::get()->DrawBoxFilled(Vector2(m_x - 1, m_y), Vector2(m_w + 2, 1 + titleBarOffset), col, 0); | |
rnd::get()->DrawBox(Vector2(m_x - 1, m_y), Vector2(m_w + 2, m_h + 1 + titleBarOffset), col,0,1); | |
m_y += titleBarOffset; | |
rnd::get()->DrawBox(Vector2(m_x, m_y), Vector2(m_w, m_h), col, 0, 1); | |
rnd::get()->DrawBoxFilled(Vector2(m_x, m_y), Vector2(m_w, m_h), col2, 0); | |
rnd::get()->DrawLine(Vector2(m_x + m_w / 2, m_y), Vector2(m_x + m_w / 2, m_y + m_h), col, 0); | |
rnd::get()->DrawLine(Vector2(m_x, m_y + m_h / 2), Vector2(m_x + m_w, m_y + m_h / 2), col, 0); | |
entity* local = new entity(game::local_player); | |
bool isTeam = false; | |
for (int i = 0; i < game::entity_count; ++i) | |
{ | |
entity* e = new entity(i); | |
if (!e->is_valid()) | |
continue; | |
pos player_pos = e->locations(); | |
pos local_player_pos = local->locations(); | |
Vector3 calculated_euler = ggrenderer::calculate_euler(local->get_angles().get()); | |
Vector2 screenPos = ScaleToRadar(player_pos.N00000136, local_player_pos.N00000136,calculated_euler); | |
if (IsInRadarBounds(screenPos)) | |
{ | |
rnd::get()->DrawBoxFilled(Vector2(screenPos.x, screenPos.y), Vector2(5, 5), col2, 0); | |
} | |
} | |
m_y -= titleBarOffset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment