diff options
-rw-r--r-- | GdiRadarLib/GdiRadar.cpp | 25 | ||||
-rw-r--r-- | GdiRadarLib/GdiRadar.h | 4 | ||||
-rw-r--r-- | GdiRadarTest/GdiRadarMain.cpp | 15 |
3 files changed, 33 insertions, 11 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)); diff --git a/GdiRadarLib/GdiRadar.h b/GdiRadarLib/GdiRadar.h index 441aee2..ea3e698 100644 --- a/GdiRadarLib/GdiRadar.h +++ b/GdiRadarLib/GdiRadar.h @@ -10,6 +10,7 @@ struct gdi_radar_config { double minimumUpdateTime; UINT64 maximumRedrawFails; size_t reservedEntities; + bool drawAngles; }; struct gdi_radar_context; @@ -32,12 +33,13 @@ enum entity_color { struct entity { int pos[2]; + float angle; float health; enum entity_color color; const char *name; }; - +static float degree2radian(int a) { return (a * 0.017453292519f); } void gdi_radar_add_entity(struct gdi_radar_context * const ctx, struct entity * const ent); void gdi_radar_set_entity(struct gdi_radar_context * const ctx, size_t i, diff --git a/GdiRadarTest/GdiRadarMain.cpp b/GdiRadarTest/GdiRadarMain.cpp index 1120815..a3a8b81 100644 --- a/GdiRadarTest/GdiRadarMain.cpp +++ b/GdiRadarTest/GdiRadarMain.cpp @@ -10,7 +10,7 @@ int main() { - gdi_radar_config cfg; + gdi_radar_config cfg = {}; gdi_radar_context * ctx; cfg.className = L"BlaTest"; @@ -18,6 +18,7 @@ int main() cfg.minimumUpdateTime = 0.25f; cfg.maximumRedrawFails = 5; cfg.reservedEntities = 16; + cfg.drawAngles = true; std::cout << "Init\n"; @@ -32,15 +33,15 @@ int main() std::cout << "Radar initialize failed\n"; } - entity e1{ 0, 0, 100, entity_color::EC_RED, "test" }; + entity e1{ 0, 0, 0.0f, 100.0f, entity_color::EC_RED, "test" }; gdi_radar_add_entity(ctx, &e1); - entity e2{ 1000, 1000, 50, entity_color::EC_RED, "m0wL" }; + entity e2{ 1000, 1000, 0.0f, 50.0f, entity_color::EC_RED, "m0wL" }; gdi_radar_add_entity(ctx, &e2); - entity e3{ 500, 500, 80, entity_color::EC_RED, "whiteshirt" }; + entity e3{ 500, 500, 0.0f, 80.0f, entity_color::EC_RED, "whiteshirt" }; gdi_radar_add_entity(ctx, &e3); - entity e4{ 50, 800, 10, entity_color::EC_RED, "lowlife" }; + entity e4{ 50, 800, 0.0f, 10.0f, entity_color::EC_RED, "lowlife" }; gdi_radar_add_entity(ctx, &e4); - entity e5{ 250, 100, 0, entity_color::EC_BLACK, "dead" }; + entity e5{ 250, 100, 0.0f, 0.0f, entity_color::EC_BLACK, "dead" }; gdi_radar_add_entity(ctx, &e5); #if 0 @@ -51,9 +52,11 @@ int main() Sleep(200); e3.pos[0]++; + e3.angle -= 0.1f; gdi_radar_set_entity(ctx, 2, &e3); e4.pos[0]++; e4.pos[1]++; + e4.angle += 0.1f; gdi_radar_set_entity(ctx, 3, &e4); } while (gdi_radar_process_window_events_nonblocking(ctx)); #endif |