This code can be used to create this nice-looking bounding boxes around players. Credits are going to r00t/Daru for most parts of the code.
Please give credits to me and/or to outside persons (if there are any listed) if you use this or any other code snippet on this website.
Unreal Tournament 99 & Tactical Ops
void DrawBoundingBox(UCanvas* Canvas, APawn* Target)
{
static TCHAR StrTemp[MAX_PATH];
FVector X,Y,Z,E,D,F,top,bottom;
float width, Left, Right, Top, Bot;
FColor Color = GetTeamColor(Target);
GetAxes(MyCameraRotation,X,Y,Z);
D = Target->Location - MyCameraLocation;
E = D /= D.Size();
if(Dot(E,X) <= cos(90 * PI / 180))
return;
top = Target->Location;
top.Z += Target->CollisionHeight * 1.1;
top = WorldToScreen(Canvas,top);
bottom = Target->Location;
bottom.Z -= Target->CollisionHeight * 1.1;
bottom = WorldToScreen(Canvas,bottom);
width = (top.Y - bottom.Y) * 0.25;
Left = top.X + width;
Right = top.X - width;
Top = top.Y;
Bot = bottom.Y;
Canvas->Color = GetTeamColor(Target);
DrawTile( Left, Top, 1, Bot-Top, Canvas->Color);
DrawTile( Left, Bot,1+Right-Left, 1, Canvas->Color);
DrawTile(Right, Top, 1, Bot-Top, Canvas->Color);
DrawTile( Left, Top, Right-Left, 1, Canvas->Color);
//Draw PlayerInformation
F = Target->Location - MyCameraLocation;
appSprintf(StrTemp,L"%s",
Target->PlayerReplicationInfo->PlayerName);
DrawText(Canvas,StrTemp,Right + 3,Top,GetTeamColor(Target));
appSprintf(StrTemp,L"H:%d",Target->Health);
DrawText(Canvas,StrTemp,Right + 3,Top + 8,
GetTeamColor(Target));
appSprintf(StrTemp, TEXT("D:%.0f"),F.Size() / 48);
DrawText(Canvas,StrTemp,Right + 3,Top + 16,
GetTeamColor(Target));
}
UT2004
void DrawBoundingBox (UCanvas* Canvas,APawn* Target)
{
FVector X,Y,Z,D,E,top,bottom;;
float width, Left, Right, Top, Bot;
GetAxes(MyCameraRotation,X,Y,Z);
D = Target->Location - MyCameraLocation;
E = D /= D.Size();
if(Dot(E,X) <= cos(90 * PI / 180))
return;
top = Target->Location;
top.Z += Target->CollisionHeight;
top = WorldToScreen(Canvas,top);
bottom = Target->Location;
bottom.Z -= Target->CollisionHeight;
bottom = WorldToScreen(Canvas,bottom);
width = ((top.Y - bottom.Y) / 4);
Left = top.X + width;
Right = top.X - width;
Top = top.Y;
Bot = bottom.Y;
Target->bNoTeamBeacon = 1;
Canvas->pCanvasUtil->DrawLine(Left, Top, Left, Bot,
Canvas->DrawColor);
Canvas->pCanvasUtil->DrawLine(Left, Bot, Right, Bot,
Canvas->DrawColor);
Canvas->pCanvasUtil->DrawLine(Right, Bot, Right, Top,
Canvas->DrawColor);
Canvas->pCanvasUtil->DrawLine(Right, Top, Left, Top,
Canvas->DrawColor);
Canvas->pCanvasUtil->DrawLine(Top, Top, Top, Top,
Canvas->DrawColor);
//Draw PlayerInformation
FVector F = Target->Location - MyCameraLocation;
static TCHAR StrTemp[MAX_PATH];
appSprintf(StrTemp,L"%s",
Target->PlayerReplicationInfo->PlayerName);
DrawText(Canvas,StrTemp,Right + 3,Top,Canvas->DrawColor);
appSprintf(StrTemp,L"H:%d",Target->Health);
DrawText(Canvas,StrTemp,Right + 3,Top + 8,Canvas->DrawColor);
appSprintf(StrTemp, TEXT("D:%.0f"),F.Size() / 48);
DrawText(Canvas,StrTemp,Right + 3,Top +16,Canvas->DrawColor);
}
++ Additional ++
FVector WorldToScreen (UCanvas* Canvas, FVector WorldLocation)
{
FVector X,Y,Z,D,Out;
GetAxes(MyCameraRotation,X,Y,Z);
D = WorldLocation - MyCameraLocation;
#if UT2004
Out.X = (Canvas->ClipX/2)+( Dot(D,Y))*((Canvas->ClipX/2)/
tan(PC->FovAngle*PI/360))/Dot(D,X);
Out.Y = (Canvas->ClipY/2)+(-Dot(D,Z))*((Canvas->ClipX/2)/
tan(PC->FovAngle*PI/360))/Dot(D,X);
#else
Out.X = (Canvas->ClipX/2)+( Dot(D,Y))*((Canvas->ClipX/2)/
tan(Me->FovAngle*PI/360))/Dot(D,X);
Out.Y = (Canvas->ClipY/2)+(-Dot(D,Z))*((Canvas->ClipX/2)/
tan(Me->FovAngle*PI/360))/Dot(D,X);
#endif
Out.Z = 0;
return Out;
}
