diff options
| author | hybrid <hybrid@hybridlabs.pro> | 2026-07-25 15:58:46 +0300 |
|---|---|---|
| committer | hybrid <hybrid@hybridlabs.pro> | 2026-07-25 15:58:46 +0300 |
| commit | 884bac2a767bf5bf77413c055a6484a7ea87700c (patch) | |
| tree | 56121d3f5930d5cde2e292c99c9fb81590a2d7a7 /src/atragmx.c | |
| parent | dc980b5ae0ca61eae3386a9ee6cbfe835a598b95 (diff) | |
| download | a3catragmx-884bac2a767bf5bf77413c055a6484a7ea87700c.tar.gz a3catragmx-884bac2a767bf5bf77413c055a6484a7ea87700c.tar.bz2 a3catragmx-884bac2a767bf5bf77413c055a6484a7ea87700c.zip | |
Diffstat (limited to 'src/atragmx.c')
| -rw-r--r-- | src/atragmx.c | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/src/atragmx.c b/src/atragmx.c index c9cebae..07cd580 100644 --- a/src/atragmx.c +++ b/src/atragmx.c @@ -7,6 +7,7 @@ #include "constants.h" #include "atragmx.h" #include "ace.h" +#include "vector.h" ATragMXSolution *ATragMXCalcSolution(ATragMXContext *ctx, ace_config *ace) { @@ -34,19 +35,19 @@ ATragMXSolution *ATragMXCalcSolution(ATragMXContext *ctx, ace_config *ace) { struct { double tx; double tz; - double last_pos[3]; - double pos[3]; - double velocity[3]; - double accel[3]; + Vec3 last_pos; + Vec3 pos; + Vec3 velocity; + Vec3 accel; double speed; - double gravity[3]; + Vec3 gravity; double deltaT; } bullet = { .gravity = { - [0] = 0.0, - [1] = sin(ctx->gun.scope_angle + ctx->target.inclination_angle) + .x = 0.0, + .y = sin(ctx->gun.scope_angle + ctx->target.inclination_angle) * -GRAVITY, - [2] = cos(ctx->gun.scope_angle + ctx->target.inclination_angle) + .z = cos(ctx->gun.scope_angle + ctx->target.inclination_angle) * -GRAVITY }, .deltaT = 1.0 / ctx->sim_steps, @@ -57,7 +58,7 @@ ATragMXSolution *ATragMXCalcSolution(ATragMXContext *ctx, ace_config *ace) { Windage windage; double lead; double time_of_flight; - double true_velocity[3]; + Vec3 true_velocity; double true_speed; double v_coriolis; double v_coriolis_deflection; @@ -77,20 +78,20 @@ ATragMXSolution *ATragMXCalcSolution(ATragMXContext *ctx, ace_config *ace) { .range_card = NULL, }; - double wind1[3] = { - [0] = cos(270 - ctx->atmosphere.wind_dir * 30) + Vec3 wind1 = { + .x = cos(270 - ctx->atmosphere.wind_dir * 30) * ctx->atmosphere.wind_speed[0], - [1] = sin(270 - ctx->atmosphere.wind_dir * 30) + .y = sin(270 - ctx->atmosphere.wind_dir * 30) * ctx->atmosphere.wind_speed[0], - [2] = 0 + .z = 0 }; - double wind2[3] = { - [0] = cos(270 - ctx->atmosphere.wind_dir * 30) + Vec3 wind2 = { + .x = cos(270 - ctx->atmosphere.wind_dir * 30) * ctx->atmosphere.wind_speed[1], - [1] = sin(270 - ctx->atmosphere.wind_dir * 30) + .y = sin(270 - ctx->atmosphere.wind_dir * 30) * ctx->atmosphere.wind_speed[1], - [2] = 0 + .z = 0 }; double wind_drift = 0.0; @@ -111,44 +112,32 @@ ATragMXSolution *ATragMXCalcSolution(ATragMXContext *ctx, ace_config *ace) { * sin(ctx->target.direction); } - memcpy(bullet.pos, - (double[3]){0.0, - 0.0, - -(ctx->gun.bore_height / 100.0)}, - sizeof(bullet.pos)); - - memcpy(bullet.velocity, - (double[3]){0.0, - cos(ctx->gun.scope_angle) * ctx->gun.muzzle_velocity, - sin(ctx->gun.scope_angle) * ctx->gun.muzzle_velocity}, - sizeof(bullet.pos)); + bullet.pos.x = 0.0; + bullet.pos.y = 0.0; + bullet.pos.z = -(ctx->gun.bore_height / 100.0); + + bullet.velocity.x = 0.0; + bullet.velocity.y = cos(ctx->gun.scope_angle) * ctx->gun.muzzle_velocity; + bullet.velocity.z = sin(ctx->gun.scope_angle) * ctx->gun.muzzle_velocity; while (local_solution.time_of_flight < 15 - && bullet.pos[1] < ctx->target.range) { + && bullet.pos.y < ctx->target.range) { // calculate magnitude of bullet.velocity - bullet.speed = hypot(bullet.velocity[0], - hypot(bullet.velocity[1], bullet.velocity[2])); - - memcpy(local_solution.true_velocity, - (double[3]){bullet.velocity[0] - wind1[0], - bullet.velocity[1] - wind1[1], - bullet.velocity[2] - wind1[2]}, - sizeof(local_solution.true_velocity)); + bullet.speed = vec3_magnitude(bullet.velocity); + local_solution.true_velocity = vec3_diff(bullet.velocity, wind1); - local_solution.true_speed = hypot(local_solution.true_velocity[0], - hypot(local_solution.true_velocity[1], - local_solution.true_velocity[2])); + local_solution.true_speed = vec3_magnitude(local_solution.true_velocity); if (ace->ballistics->enabled) { double data = retard(ctx->gun.drag_model, ctx->gun.ballistic_coef, ctx->gun.muzzle_velocity, ctx->atmosphere.temperature); - memcpy(bullet.accel, - (double[3]){bullet.accel[0] != 0 ? -data : 0, - bullet.accel[1] != 0 ? -data : 0, - bullet.accel[2] != 0 ? -data : 0}, - + /* memcpy(bullet.accel, */ + /* (double[3]){bullet.accel[0] != 0 ? -data : 0, */ + /* bullet.accel[1] != 0 ? -data : 0, */ + /* bullet.accel[2] != 0 ? -data : 0}, */ + /* ); */ } } |
