2D Radar
i wanted to share the 2d radar
Usage :
Thanks to R4z8r for clamp function.
P.S Size is the size of the radar : example : width = 150 , height = 150
Credits by xCyniu
Code:
FVector2D WorldToRadar( FVector Location , FLOAT PosX, FLOAT PosY , INT Size )
{
/*Credits to ********* community | xCyniu | r4z8r when you use this ;)*/
FVector2D Coord;
FVector2D Return;
FLOAT cY = cos(URotationToRadians( MyCameraRotation.Yaw ));
FLOAT sY = sin(URotationToRadians( MyCameraRotation.Yaw ));
FLOAT dX = Location.X - MyCameraLocation.X;
FLOAT dY = Location.Y - MyCameraLocation.Y;
Coord.X = ( dY * cY - dX * sY ) / 150.0f;
Coord.Y = ( dX * cY + dY * sY ) / 150.0f;
Return.X = Coord.X + PosX + (Size / 2.0f);
Return.Y = -Coord.Y + PosY + (Size / 2.0f);
/*Thanks to r4z8r for clamp :)*/
if(Return.X > (PosX + Size) )
Return.X = (PosX + Size);
else if(Return.X < (PosX) )
Return.X = PosX;
if(Return.Y > (PosY + Size) )
Return.Y = (PosY + Size);
else if(Return.Y < (PosY) )
Return.Y = PosY;
return Return;
}
Code:
FVector2D Position = WorldToRadar(Target->Location, cVars.Radar.PosX, cVars.Radar.PosY,150);
P.S Size is the size of the radar : example : width = 150 , height = 150
Credits by xCyniu
