engine-c: vehicle tread/wheel roll via Unit.anim

This commit is contained in:
local-model/engine-L2-grok-4.5 2026-09-19 12:50:15 +02:00
parent 48960b11fa
commit 8b55fa687a
No known key found for this signature in database
3 changed files with 149 additions and 4 deletions

View file

@ -220,6 +220,88 @@ static void draw_unit_shadow(SDL_Renderer *ren, int cx, int cy, int rad) {
}
}
static int live_unit_wheeled(UnitType t) {
return t == UT_BUGGY || t == UT_JEEP || t == UT_HARVESTER
|| t == UT_BEAST || t == UT_MISSILE || t == UT_MEDIC;
}
static int live_unit_tracked(UnitType t) {
return t == UT_TANK || t == UT_RAVAGER;
}
static int live_unit_rolling(UnitType t) {
return live_unit_wheeled(t) || live_unit_tracked(t);
}
/* Spoke (wheeled) / hash (tracked) on tyre discs; phase = Unit.anim rad.
* Local 30×30 chassis coords match snapshot LX/LY, scaled to live sz. */
static void live_tyre_mark(SDL_Renderer *ren, int cx, int cy, int rad,
float phase, int wheeled) {
int n = wheeled ? 4 : 3;
float step = (float)(2.0 * M_PI / (double)n);
float r0 = wheeled ? rad * 0.30f : rad * 0.55f;
float r1 = rad * 0.90f;
SDL_SetRenderDrawColor(ren, 205, 200, 180, 240);
for (int i = 0; i < n; i++) {
float a = phase + i * step;
int x1 = cx + (int)(cosf(a) * r0);
int y1 = cy + (int)(sinf(a) * r0);
int x2 = cx + (int)(cosf(a) * r1);
int y2 = cy + (int)(sinf(a) * r1);
SDL_RenderDrawLine(ren, x1, y1, x2, y2);
}
}
static void live_draw_tyre_marks(SDL_Renderer *ren, Unit *u, int cx, int cy, int sz) {
if (!live_unit_rolling(u->type)) return;
float c = cosf(u->heading), s = sinf(u->heading);
float sc = (float)sz / 30.0f;
float ph = u->anim;
#define LTX(lx, ly) (cx + (int)((((lx)-15)*sc)*c - (((ly)-15)*sc)*s))
#define LTY(lx, ly) (cy + (int)((((lx)-15)*sc)*s + (((ly)-15)*sc)*c))
#define LRAD(n) ((int)((n) * sc + 0.5f))
switch (u->type) {
case UT_BUGGY:
live_tyre_mark(ren, LTX(8,7), LTY(8,7), LRAD(4), ph, 1);
live_tyre_mark(ren, LTX(22,7), LTY(22,7), LRAD(4), ph, 1);
live_tyre_mark(ren, LTX(8,23), LTY(8,23), LRAD(4), ph, 1);
live_tyre_mark(ren, LTX(22,23),LTY(22,23),LRAD(4), ph, 1);
break;
case UT_TANK:
live_tyre_mark(ren, LTX(8,23), LTY(8,23), LRAD(4), ph, 0);
live_tyre_mark(ren, LTX(22,23),LTY(22,23),LRAD(4), ph, 0);
break;
case UT_HARVESTER:
live_tyre_mark(ren, LTX(8,23), LTY(8,23), LRAD(4), ph, 1);
live_tyre_mark(ren, LTX(22,23),LTY(22,23),LRAD(4), ph, 1);
break;
case UT_JEEP:
live_tyre_mark(ren, LTX(9,22), LTY(9,22), LRAD(4), ph, 1);
live_tyre_mark(ren, LTX(21,22),LTY(21,22),LRAD(4), ph, 1);
break;
case UT_BEAST:
live_tyre_mark(ren, LTX(9,21), LTY(9,21), LRAD(3), ph, 1);
live_tyre_mark(ren, LTX(14,22),LTY(14,22),LRAD(3), ph, 1);
live_tyre_mark(ren, LTX(19,21),LTY(19,21),LRAD(3), ph, 1);
live_tyre_mark(ren, LTX(23,22),LTY(23,22),LRAD(3), ph, 1);
break;
case UT_RAVAGER:
live_tyre_mark(ren, LTX(7,23), LTY(7,23), LRAD(4), ph, 0);
live_tyre_mark(ren, LTX(23,23),LTY(23,23),LRAD(4), ph, 0);
break;
case UT_MISSILE:
live_tyre_mark(ren, LTX(9,23), LTY(9,23), LRAD(4), ph, 1);
live_tyre_mark(ren, LTX(21,23),LTY(21,23),LRAD(4), ph, 1);
break;
case UT_MEDIC:
live_tyre_mark(ren, LTX(10,24),LTY(10,24),LRAD(4), ph, 1);
live_tyre_mark(ren, LTX(20,24),LTY(20,24),LRAD(4), ph, 1);
break;
default: break;
}
#undef LTX
#undef LTY
#undef LRAD
}
void render_units(Game *g) {
for (int i = 0; i < g->unit_count; i++) {
Unit *u = &g->units[i];
@ -234,6 +316,8 @@ void render_units(Game *g) {
draw_unit_shadow(g->ren, cx, cy, sz / 4 + 4);
SDL_Texture *tex = g->spr.unit[u->type][u->faction];
draw_tex_world(g, tex, u->x, u->y, sz, sz, u->heading, 255);
/* rotating spokes / tread hashes (parity with snapshot tyre_mark) */
live_draw_tyre_marks(g->ren, u, cx, cy, sz);
/* cream heading tick (parity with snapshot LX/LY overlay) */
{
float tick = (float)(sz / 2 + 6);