summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/ballistics.h17
-rw-r--r--include/constants.h4
-rw-r--r--include/context.h1
-rw-r--r--include/misc.h19
-rw-r--r--include/vector.h43
5 files changed, 79 insertions, 5 deletions
diff --git a/include/ballistics.h b/include/ballistics.h
index ab68c3f..7ba4248 100644
--- a/include/ballistics.h
+++ b/include/ballistics.h
@@ -19,4 +19,21 @@ double retard(DragFunction drag_function,
double velocity,
double temperature);
+typedef struct RangeCardRecord RangeCardRecord;
+struct RangeCardRecord {
+ size_t n;
+ double range;
+ double elevation;
+ Windage windage;
+ double lead;
+ double time_of_flight;
+ double bullet_speed;
+ double kinetic_energy;
+};
+typedef struct RangeCard RangeCard;
+struct RangeCard {
+ RangeCardRecord *card;
+ size_t records;
+};
+
#endif
diff --git a/include/constants.h b/include/constants.h
index 026ff7b..f367e4b 100644
--- a/include/constants.h
+++ b/include/constants.h
@@ -11,4 +11,8 @@ static const double STD_AIR_DENSITY_ICAO = 1.22498;
static const double STD_AIR_DENSITY_ASM = 1.20886;
static const double BC_CONVERSION_FACTOR = 0.00068418;
+static const double rangeCardStartRange = 200;
+static const double rangeCardIncrement = 50;
+static const double rangeCardEndRange = 2000;
+
#endif
diff --git a/include/context.h b/include/context.h
index 5dfad31..dd207bb 100644
--- a/include/context.h
+++ b/include/context.h
@@ -21,6 +21,7 @@ typedef struct {
double ballistic_coef;
DragFunction drag_model;
double twist_dir;
+ double air_friction;
} GunConfig;
typedef struct {
diff --git a/include/misc.h b/include/misc.h
new file mode 100644
index 0000000..a0b235c
--- /dev/null
+++ b/include/misc.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <stdbool.h>
+
+#include "misc.h"
+#include "vector.h"
+
+#define MRAD_IN_DEG 17.45329252
+
+double linearConversion(double min_from,
+ double max_from,
+ double value,
+ double min_to,
+ double max_to,
+ bool clip);
+
+static inline double MRAD_TO_DEG(double d) {
+ return d / MRAD_IN_DEG;
+}
diff --git a/include/vector.h b/include/vector.h
index 72e6523..07d44cd 100644
--- a/include/vector.h
+++ b/include/vector.h
@@ -1,9 +1,42 @@
#pragma once
-#include "vector.h"
+
+#include <math.h>
typedef struct { double x, y, z; } Vec3;
-static inline double vec3_magnitude(Vec3 v);
-static inline Vec3 vec3_diff(Vec3 a, Vec3 b);
-static inline Vec3 vec3_normalize(Vec3 v);
-static inline Vec3 vec3_mul(Vec3 v, double n);
+static inline double vec3_magnitude(Vec3 v) {
+ return hypot(v.x, hypot(v.y, v.z));
+}
+
+static inline Vec3 vec3_diff(Vec3 a, Vec3 b) {
+ return (Vec3){.x = a.x - b.x,
+ .y = a.y - b.y,
+ .z = a.z - b.z};
+}
+
+static inline Vec3 vec3_normalize(Vec3 v) {
+ if (v.x == 0.0 || v.y == 0.0 || v.z == 0.0)
+ return (Vec3){.x = 0.0,
+ .y = 0.0,
+ .z = 0.0};
+
+ double len = sqrt(v.x * v.x
+ + v.y * v.y
+ + v.z * v.z);
+ return (Vec3){.x = v.x / len,
+ .y = v.y / len,
+ .z = v.z / len};
+}
+
+static inline Vec3 vec3_mul(Vec3 v, double n) {
+ return (Vec3) {.x = v.x * n,
+ .y = v.y * n,
+ .z = v.z * n};
+}
+
+static inline Vec3 vec3_add(Vec3 a, Vec3 b) {
+ return (Vec3) {.x = a.x + b.x,
+ .y = a.y + b.y,
+ .z = a.z + b.z};
+}
+