summaryrefslogtreecommitdiffstats
path: root/src/atragmx.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/atragmx.c79
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}, */
+ /* ); */
}
}