aboutsummaryrefslogtreecommitdiff
path: root/GdiRadarLib/GdiRadar.cpp
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2019-10-20 14:21:09 +0200
committerToni Uhlig <matzeton@googlemail.com>2019-10-20 14:21:09 +0200
commit9f04512d6a0750f36e5eee9bad64dc2d0aee4be2 (patch)
tree7809d60b5a48b85b635a5788d6fee75b0e6e2a4d /GdiRadarLib/GdiRadar.cpp
parent7ebf530e858114f02a46171917a17bcd0855d699 (diff)
radar can now draw view angles of entities
Diffstat (limited to 'GdiRadarLib/GdiRadar.cpp')
-rw-r--r--GdiRadarLib/GdiRadar.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/GdiRadarLib/GdiRadar.cpp b/GdiRadarLib/GdiRadar.cpp
index ccb23ce..89e6912 100644
--- a/GdiRadarLib/GdiRadar.cpp
+++ b/GdiRadarLib/GdiRadar.cpp
@@ -41,12 +41,19 @@ struct gdi_radar_context
UINT64 GameMapWidth;
UINT64 GameMapHeight;
size_t reservedEntities;
+ bool drawAngles;
struct gdi_radar_drawing drawing;
std::vector<struct entity> entities;
};
+static inline void getEndPoint(float angle, int len, int start_x,
+ int start_y, int *end_x, int *end_y) {
+ *end_x = (int)(start_x + len * cos(angle));
+ *end_y = (int)(start_y + len * sin(angle));
+}
+
static void draw_entity(struct gdi_radar_context * const ctx, struct entity * const ent)
{
#if 0
@@ -58,6 +65,19 @@ static void draw_entity(struct gdi_radar_context * const ctx, struct entity * co
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
#endif
+ float frealx = ent->pos[0] * ((float)ctx->drawing.GameMapWindowWidth / ctx->GameMapWidth);
+ float frealy = ent->pos[1] * ((float)ctx->drawing.GameMapWindowHeight / ctx->GameMapHeight);
+ int realx = (int)frealx;
+ int realy = (int)frealy;
+
+ if (ctx->drawAngles) {
+ int endx = 0, endy = 0;
+ getEndPoint(ent->angle, 15, realx, realy, &endx, &endy);
+ SelectObject(ctx->drawing.hdc, ctx->drawing.DefaultPen);
+ POINT lines[] = { { realx, realy }, { endx, endy } };
+ Polyline(ctx->drawing.hdc, lines, 2);
+ }
+
switch (ent->color) {
case EC_BLUE:
SelectObject(ctx->drawing.hdc, ctx->drawing.BlueBrush);
@@ -70,10 +90,6 @@ static void draw_entity(struct gdi_radar_context * const ctx, struct entity * co
break;
}
- float frealx = ent->pos[0] * ((float)ctx->drawing.GameMapWindowWidth / ctx->GameMapWidth);
- float frealy = ent->pos[1] * ((float)ctx->drawing.GameMapWindowHeight / ctx->GameMapHeight);
- int realx = (int)frealx;
- int realy = (int)frealy;
Ellipse(ctx->drawing.hdc, realx - 5, realy - 5, realx + 5, realy + 5);
}
@@ -210,6 +226,7 @@ struct gdi_radar_context * const
result->maximumRedrawFails = cfg->maximumRedrawFails;
result->reservedEntities = cfg->reservedEntities;
result->entities.reserve(result->reservedEntities);
+ result->drawAngles = cfg->drawAngles;
/* other */
result->wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));