MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / DrawCompass

Method DrawCompass

engine/Poseidon/UI/InGame/InGameUIDraw.cpp:1090–1161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1088}
1089
1090void InGameUI::DrawCompass(EntityAI* vehicle)
1091{
1092 // Texture *textureDef = GLOB_SCENE->Preloaded(TextureWhite);
1093 Texture* texture;
1094 MipInfo mip;
1095 const int w = GLOB_ENGINE->Width2D();
1096 const int h = GLOB_ENGINE->Height2D();
1097
1098 Texture* corner = GLOB_SCENE->Preloaded(Corner);
1099 DrawFrame(corner, bgColor, Rect2DPixel(coX * w, coY * h, coW * w, coH * h));
1100
1101 // Vector3Val dir = vehicle->Direction();
1102 Camera& cam = *GLOB_SCENE->GetCamera();
1103 Vector3Val dir = cam.Direction();
1104
1105 // avoid singularity when heading up
1106 float xAngle;
1107 if (fabs(dir.X()) + fabs(dir.Z()) > 1e-3)
1108 {
1109 xAngle = atan2(dir.X(), dir.Z());
1110 }
1111 else
1112 {
1113 xAngle = 0;
1114 }
1115 xAngle *= 2 * INV_H_PI;
1116 for (int i = -2; i <= 2; i++)
1117 {
1118 float xLeft = xAngle + i;
1119 int xBase = toIntFloor(xLeft);
1120 if (xLeft - xBase >= 1.0)
1121 {
1122 xBase++;
1123 }
1124 int xBaseMod4 = xBase & (4 - 1);
1125 xLeft = xLeft + (xBaseMod4 - xBase);
1126 xBase = xBaseMod4;
1127 Poseidon::PreloadedTexture seg[4] = {Compass180, Compass270, Compass000, Compass090};
1128 texture = GLOB_SCENE->Preloaded(seg[xBase]);
1129 float xOffset = xLeft - xBase;
1130 mip = GLOB_ENGINE->TextBank()->UseMipmap(texture, 0, 0);
1131 float xScreen = (coX + 0.5 * coW + 0.25 * coW * (i - xOffset)) * w;
1132 GLOB_ENGINE->Draw2D(mip, compassColor, Rect2DPixel(xScreen, coY * h, 0.25 * coW * w, coH * h),
1133 Rect2DPixel(coX * w, coY * h, coW * w, coH * h));
1134 // GLOB_ENGINE->TextBank()->ReleaseMipmap();
1135 }
1136
1137 Rect2DPixel compassClip(coX * w, 0, coW * w, h);
1138 float ySize = coH * h * 0.5;
1139 float xSize = ySize * w / h * (3.0 / 4);
1140 float xPos = (coX + coW * 0.5) * w;
1141 PackedColor col = compassDirColor;
1142 GLOB_ENGINE->DrawLine(Line2DPixel(xPos, coY * h, xPos + xSize, coY * h - ySize), col, col, compassClip);
1143 GLOB_ENGINE->DrawLine(Line2DPixel(xPos, coY * h, xPos - xSize, coY * h - ySize), col, col, compassClip);
1144
1145 int weapon = vehicle->SelectedWeapon();
1146 if (weapon >= 0)
1147 {

Callers

nothing calls this directly

Calls 15

DrawFrameFunction · 0.85
fabsFunction · 0.85
Line2DPixelClass · 0.85
GetCameraMethod · 0.80
SelectedWeaponMethod · 0.80
Rect2DPixelClass · 0.50
Width2DMethod · 0.45
Height2DMethod · 0.45
PreloadedMethod · 0.45
DirectionMethod · 0.45
XMethod · 0.45
ZMethod · 0.45

Tested by

no test coverage detected