summaryrefslogtreecommitdiffstats
path: root/src/atragmx.c
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.pro>2026-07-11 10:15:52 +0300
committerhybrid <hybrid@hybridlabs.pro>2026-07-11 10:15:52 +0300
commit866393b70f5baddcaf9571b7240ebd4ce44bc67c (patch)
treecac69c96fc074c64af54060a044474e40e7e46ad /src/atragmx.c
parent4e6026b12eb00ea5bdd6dece2dfc97ffe8c2fc87 (diff)
downloada3catragmx-866393b70f5baddcaf9571b7240ebd4ce44bc67c.tar.gz
a3catragmx-866393b70f5baddcaf9571b7240ebd4ce44bc67c.tar.bz2
a3catragmx-866393b70f5baddcaf9571b7240ebd4ce44bc67c.zip
add: tmp commit
Diffstat (limited to '')
-rw-r--r--src/atragmx.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/atragmx.c b/src/atragmx.c
new file mode 100644
index 0000000..af68b2c
--- /dev/null
+++ b/src/atragmx.c
@@ -0,0 +1,137 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+#include "ballistics.h"
+#include "constants.h"
+#include "atragmx.h"
+#include "ace.h"
+
+ATragMXSolution *ATragMXCalcSolution(ATragMXContext *ctx, ace_config *ace) {
+
+ //
+ // init section
+ //
+
+ ATragMXSolution *sln = NULL;
+
+ if ((sln = calloc(1, sizeof(ATragMXSolution))) == NULL) {
+ perror("ATragMXSolution: malloc failed");
+ return NULL;
+ }
+
+ // local data
+
+ struct {
+ double speed1;
+ double speed2;
+ } wind = {
+ .speed1 = ctx->atmosphere.wind_speed[0],
+ .speed2 = ctx->atmosphere.wind_speed[1],
+ };
+
+ struct {
+ double tx;
+ double tz;
+ double last_pos[3];
+ double pos[3];
+ double velocity[3];
+ double accel[3];
+ double speed;
+ double gravity[3];
+ double deltaT;
+ } bullet = {
+ .gravity = {
+ [0] = 0.0,
+ [1] = sin(ctx->gun.scope_angle + ctx->target.inclination_angle)
+ * -GRAVITY,
+ [2] = cos(ctx->gun.scope_angle + ctx->target.inclination_angle)
+ * -GRAVITY
+ },
+ .deltaT = 1.0 / ctx->sim_steps,
+ };
+
+ struct {
+ double elevation;
+ Windage windage;
+ double lead;
+ double time_of_flight;
+ double true_velocity[3];
+ double true_speed;
+ double v_coriolis;
+ double v_coriolis_deflection;
+ double h_coriolis;
+ double h_coriolis_deflection;
+ double spin_drift;
+ double spin_deflection;
+ } local_solution = {0};
+
+ struct {
+ double range;
+ double true_range;
+ double range_factor;
+ double *range_card;
+ } ctx_range = {
+ .range_factor = ctx->store_range_card ? 1.0936133 : 1,
+ .range_card = NULL,
+ };
+
+ double wind1[3] = {
+ [0] = cos(270 - ctx->atmosphere.wind_dir * 30)
+ * ctx->atmosphere.wind_speed[0],
+ [1] = sin(270 - ctx->atmosphere.wind_dir * 30)
+ * ctx->atmosphere.wind_speed[0],
+ [2] = 0
+ };
+
+ double wind2[3] = {
+ [0] = cos(270 - ctx->atmosphere.wind_dir * 30)
+ * ctx->atmosphere.wind_speed[1],
+ [1] = sin(270 - ctx->atmosphere.wind_dir * 30)
+ * ctx->atmosphere.wind_speed[1],
+ [2] = 0
+ };
+
+ double wind_drift = 0.0;
+
+ if (ace->ballistics->enabled)
+ ctx->gun.ballistic_coef
+ = atmospheric_correction(
+ ctx->gun.ballistic_coef,
+ ctx->atmosphere.temperature,
+ ctx->atmosphere.barometric_pressure,
+ ctx->atmosphere.relative_humidity,
+ ctx->atmosphere.atmosphere_model);
+
+ double eoetvoes_multiplier = 0.0;
+ if (ace->ballistics->enabled) {
+ eoetvoes_multiplier = 2
+ * (0.0000729 * ctx->gun.muzzle_velocity / -GRAVITY)
+ * cos(ctx->target.latitude)
+ * 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));
+
+ while (local_solution.time_of_flight < 15
+ && bullet.pos[1] < ctx->target.range) {
+ // calculate magnitude of bullet.velocity
+ bullet.speed = hypot(bullet.velocity[0],
+ hypot(bullet.velocity[1], bullet.velocity[2]));
+
+
+ }
+
+ return sln;
+}