void CalcAngle(const float *src, const float *dst, float *angles)
{
float delta[3] = { (src[0]-dst[0]), (src[1]-dst[1]), (src[2]-dst[2]) };
float hyp = (float)sqrt(delta[0]*delta[0] + delta[1]*delta[1]);
angles[0] = (float)(atan(delta[2] / hyp) * (180 / M_PI));
angles[1] = (float)(atan(delta[1] / delta[0]) * (180 / M_PI));
angles[2] = 0.0f;
if(delta[0] >= 0.0f) { angles[1] += 180.0f; }
}
void MakeVector(float *angle, float *vector)
{
float pitch;
float yaw;
float tmp;
pitch = (float)(angle[0] * M_PI/180);
yaw = (float)(angle[1] * M_PI/180);
tmp = (float)cos(pitch);
vector[0] = (float) (-tmp * -cos(yaw));
vector[1] = (float) (sin(yaw)*tmp);
vector[2] = (float) -sin(pitch);
}
float GetFOVDistPlus(float *angle, float *src, float *dst)
{
float fov = 0.0f;
float ang[3];
float aim[3];
float cross = 0.0f;
// we get direction from the cross product...
// cross.x = (A.y) * (B.z) - (B.y) * (A.z)
// cross.y = (A.z) * (B.x) - (B.z) * (A.x)
// cross.z = (A.x) * (B.y) - (B.x) * (A.y)
CalcAngle(src, dst, ang);
MakeVector(angle, aim);
MakeVector(ang, ang);
// cross[0] = (aim[1] * ang[2]) - (ang[1] * aim[2]);
// cross[1] = (aim[2] * ang[0]) - (ang[2] * aim[0]);
// cross[2] = (aim[0] * ang[1]) - (ang[0] * aim[1]);
cross = (aim[0] * ang[1]) - (ang[0] * aim[1]);
float mag_s = sqrt(SQUARE(aim[0]) + SQUARE(aim[1]));
float mag_d = sqrt(SQUARE(ang[0]) + SQUARE(ang[1]));
float u_dot_v = aim[0]*ang[0] + aim[1]*ang[1];
fov = acos(u_dot_v / (mag_s*mag_d)) * (180 / M_PI);
if(cross >= 0.0f) { fov *= -1.0f; }
return fov;
}
void DrawRadar()
{
int x = Local.viewport[2];
int y = Local.viewport[3];
int w = Local.viewport[2] / 100;
float ang[3];
Aimbot.GetViewAngles(ang);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ub(0, 0, 0, 128);
glBegin(GL_QUADS);
glVertex2i(0, 0); //top
glVertex2i(x, 0);
glVertex2i(x, w);
glVertex2i(0, w);
glVertex2i(0, w); //left
glVertex2i(w, w);
glVertex2i(w, y-w);
glVertex2i(0, y-w);
glVertex2i(x-w, w); //right
glVertex2i(x, w);
glVertex2i(x, y-w);
glVertex2i(x-w, y-w);
glVertex2i(0, y-w); //bottom
glVertex2i(x, y-w);
glVertex2i(x, y);
glVertex2i(0, y);
glEnd();
for(int ax=0; ax < Player.size(); ax++)
{
if(!Player[ax].valid) { continue; }
int r,g,b;
Player[ax].team->GetColours(r, g, b);
float dist = GetFOVDistPlus(ang, Local.origin, Player[ax].ent->origin);
float rx = 0.0f;
float ry = 0.0f;
int ix = 0;
int iy = 0;
if(dist >= -45.0f && dist <= +45.0f) //on top
{
ry = (float)w / 2.0f;
rx = (dist+45.0f) / 90.0f * (float)x;
}
else if(dist < -45.0f && dist > -135.0f) //on left
{
rx = (float)w / 2.0f;
ry = (float)y - ((dist + 135.0f) / 90.0f * (float)y);
}
else if(dist > +45.0f && dist < +135.0f) //on right
{
rx = (float)x - ((float)w / 2.0f);
ry = (dist-45.0f)/90.0f * (float)y;
}
else //on bottom
{
ry = (float)y - ( (float)w / 2.0f);
float part = (fabs(dist)-135.0f) / 45.0f;
if(dist < 0.0f) { rx = (part*((float)x / 2.0f)); }
else { rx = (float)x - (part*((float)x / 2.0f)); }
}
ix = (int)rx;
iy = (int)ry;
int icon = (w/2) - 2;
glColor4ub(r, g, b, 200);
glBegin(GL_QUADS);
glVertex2i(ix-icon, iy-icon);
glVertex2i(ix+icon, iy-icon);
glVertex2i(ix+icon, iy+icon);
glVertex2i(ix-icon, iy+icon);
glEnd();
glColor4ub(255, 255, 255, 160);
glBegin(GL_LINE_STRIP);
glVertex2i(ix-icon, iy+icon);
glVertex2i(ix-icon, iy-icon);
glVertex2i(ix+icon, iy-icon);
glEnd();
glColor4ub(0, 0, 0, 160);
glBegin(GL_LINE_STRIP);
glVertex2i(ix+icon, iy-icon);
glVertex2i(ix+icon, iy+icon);
glVertex2i(ix-icon, iy+icon);
glEnd();
}
glEnable(GL_TEXTURE_2D);
}