Skip to content

Commit

Permalink
move aoa rating into airplane data struct
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Jul 11, 2023
1 parent 4e86d3c commit 0da809d
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 56 deletions.
60 changes: 55 additions & 5 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,20 @@ static FA18C: AirplaneInfo = AirplaneInfo {
z: -7.237348,
},
glide_slope: 3.5,
plane_type: "FA18C",
aoa_rating: |aoa: f64| -> Aoa {
// https://forums.vrsimulations.com/support/index.php/Navigation_Tutorial_Flight#Angle_of_Attack_Bracket
if aoa <= 6.9 {
Aoa::Fast
} else if aoa <= 7.4 {
Aoa::SlightlyFast
} else if aoa < 8.8 {
Aoa::OnSpeed
} else if aoa < 9.3 {
Aoa::SlightlySlow
} else {
Aoa::Slow
}
},
};

static F14: AirplaneInfo = AirplaneInfo {
Expand All @@ -151,7 +164,22 @@ static F14: AirplaneInfo = AirplaneInfo {
z: -6.563727,
},
glide_slope: 3.5,
plane_type: "F14",
aoa_rating: |aoa: f64| -> Aoa {
// https://www.heatblur.se/F-14Manual/cockpit.html?highlight=aoa#approach-indexer
// aoa degrees for tomcat calculated by degrees=((units/1.0989) - 3.01) from units in manual based off conversation found here:
// https://forum.dcs.world/topic/228893-aoa-units-to-degrees-conversion/#:~:text=Which%20makes%20around%201%20unit%3D1%2C67%20degrees.
if aoa <= 9.7 {
Aoa::Fast
} else if aoa <= 10.2 {
Aoa::SlightlyFast
} else if aoa < 11.1 {
Aoa::OnSpeed
} else if aoa < 11.6 {
Aoa::SlightlySlow
} else {
Aoa::Slow
}
},
};

static T45: AirplaneInfo = AirplaneInfo {
Expand All @@ -161,7 +189,20 @@ static T45: AirplaneInfo = AirplaneInfo {
z: -4.782536,
},
glide_slope: 3.5,
plane_type: "T45",
aoa_rating: |aoa: f64| -> Aoa {
// same as FA18C, so potentially wrong
if aoa <= 6.9 {
Aoa::Fast
} else if aoa <= 7.4 {
Aoa::SlightlyFast
} else if aoa < 8.8 {
Aoa::OnSpeed
} else if aoa < 9.3 {
Aoa::SlightlySlow
} else {
Aoa::Slow
}
},
};

#[derive(Debug)]
Expand Down Expand Up @@ -202,13 +243,22 @@ impl CarrierInfo {
}

#[derive(Debug)]
pub enum Aoa {
Fast,
SlightlyFast,
OnSpeed,
SlightlySlow,
Slow,
}

#[derive(Debug, PartialEq)]
pub struct AirplaneInfo {
/// Hook position relative to the object's origin.
pub hook: DVec3,
/// The optimal glide slope in degrees.
pub glide_slope: f64,
/// The type of aircraft used to select proper on speed color.
pub plane_type: &'static str,
/// A function that returns its current AOA rating.
pub aoa_rating: fn(aoa: f64) -> Aoa,
}

impl AirplaneInfo {
Expand Down
105 changes: 58 additions & 47 deletions src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use plotters::style::{Color, IntoFont, RGBColor, TextStyle};
use plotters_bitmap::bitmap_pixel::RGBPixel;
use plotters_bitmap::BitMapBackend;

use crate::data::{AirplaneInfo, Aoa};
use crate::track::{Datum, Grading, TrackResult};
use crate::utils::{ft_to_nm, m_to_ft, m_to_nm, nm_to_ft, nm_to_m};

Expand Down Expand Up @@ -191,7 +192,7 @@ pub fn draw_top_view(
let mut points = Vec::new();
let mut color = THEME_AOA_ON_SPEED;
for datum in track_in_nm {
let next_color = aoa_color(datum.aoa, track.plane_type);
let next_color = aoa_color(datum.aoa, track.plane_info);
let point = (datum.x, datum.y);

if points.is_empty() {
Expand Down Expand Up @@ -261,13 +262,13 @@ pub fn draw_side_view(

// draw centerline
let lines = [
(track.glide_slope - 0.9, THEME_GUIDE_RED),
(track.glide_slope - 0.6, THEME_GUIDE_YELLOW),
(track.glide_slope - 0.25, THEME_GUIDE_GREEN),
(track.glide_slope, THEME_GUIDE_GRAY),
(track.glide_slope + 0.25, THEME_GUIDE_GREEN),
(track.glide_slope + 0.7, THEME_GUIDE_YELLOW),
(track.glide_slope + 1.5, THEME_GUIDE_RED),
(track.plane_info.glide_slope - 0.9, THEME_GUIDE_RED),
(track.plane_info.glide_slope - 0.6, THEME_GUIDE_YELLOW),
(track.plane_info.glide_slope - 0.25, THEME_GUIDE_GREEN),
(track.plane_info.glide_slope, THEME_GUIDE_GRAY),
(track.plane_info.glide_slope + 0.25, THEME_GUIDE_GREEN),
(track.plane_info.glide_slope + 0.7, THEME_GUIDE_YELLOW),
(track.plane_info.glide_slope + 1.5, THEME_GUIDE_RED),
];

for (deg, color) in lines {
Expand Down Expand Up @@ -315,7 +316,7 @@ pub fn draw_side_view(
let mut points = Vec::new();
let mut color = THEME_AOA_ON_SPEED;
for datum in track_descent {
let next_color = aoa_color(datum.aoa, track.plane_type);
let next_color = aoa_color(datum.aoa, track.plane_info);

let point = (datum.x, datum.alt);

Expand Down Expand Up @@ -352,47 +353,57 @@ fn text_style() -> TextStyle<'static> {
TextStyle::from(("sans-serif", 20).into_font()).color(&THEME_FG)
}

fn aoa_color(aoa: f64, plane_type: &'static str) -> RGBColor {
fn aoa_color(aoa: f64, plane_info: &'static AirplaneInfo) -> RGBColor {
match (plane_info.aoa_rating)(aoa) {
Aoa::Fast => THEME_AOA_FAST,
Aoa::SlightlyFast => THEME_AOA_SLIGHTLY_FAST,
Aoa::OnSpeed => THEME_AOA_ON_SPEED,
Aoa::SlightlySlow => THEME_AOA_SLIGHTLY_SLOW,
Aoa::Slow => THEME_AOA_SLOW,
}

/*
if plane_type == "F14" {
// https://www.heatblur.se/F-14Manual/cockpit.html?highlight=aoa#approach-indexer
// aoa degrees for tomcat calculated by degrees=((units/1.0989) - 3.01) from units in manual based off conversation found here:
// https://forum.dcs.world/topic/228893-aoa-units-to-degrees-conversion/#:~:text=Which%20makes%20around%201%20unit%3D1%2C67%20degrees.
if aoa <= 9.7 {
// fast
THEME_AOA_FAST
} else if aoa <= 10.2 {
// slightly fast
THEME_AOA_SLIGHTLY_FAST
} else if aoa < 11.1 {
// on speed
THEME_AOA_ON_SPEED
} else if aoa < 11.6 {
// slightly slow
THEME_AOA_SLIGHTLY_SLOW
} else {
// slow
THEME_AOA_SLOW
}
} else {
// default to FA18C
// https://forums.vrsimulations.com/support/index.php/Navigation_Tutorial_Flight#Angle_of_Attack_Bracket
if aoa <= 6.9 {
// fast
THEME_AOA_FAST
} else if aoa <= 7.4 {
// slightly fast
THEME_AOA_SLIGHTLY_FAST
} else if aoa < 8.8 {
// on speed
THEME_AOA_ON_SPEED
} else if aoa < 9.3 {
// slightly slow
THEME_AOA_SLIGHTLY_SLOW
// https://www.heatblur.se/F-14Manual/cockpit.html?highlight=aoa#approach-indexer
// aoa degrees for tomcat calculated by degrees=((units/1.0989) - 3.01) from units in manual based off conversation found here:
// https://forum.dcs.world/topic/228893-aoa-units-to-degrees-conversion/#:~:text=Which%20makes%20around%201%20unit%3D1%2C67%20degrees.
if aoa <= 9.7 {
// fast
THEME_AOA_FAST
} else if aoa <= 10.2 {
// slightly fast
THEME_AOA_SLIGHTLY_FAST
} else if aoa < 11.1 {
// on speed
THEME_AOA_ON_SPEED
} else if aoa < 11.6 {
// slightly slow
THEME_AOA_SLIGHTLY_SLOW
} else {
// slow
THEME_AOA_SLOW
}
} else {
// slow
THEME_AOA_SLOW
// default to FA18C
// https://forums.vrsimulations.com/support/index.php/Navigation_Tutorial_Flight#Angle_of_Attack_Bracket
if aoa <= 6.9 {
// fast
THEME_AOA_FAST
} else if aoa <= 7.4 {
// slightly fast
THEME_AOA_SLIGHTLY_FAST
} else if aoa < 8.8 {
// on speed
THEME_AOA_ON_SPEED
} else if aoa < 9.3 {
// slightly slow
THEME_AOA_SLIGHTLY_SLOW
} else {
// slow
THEME_AOA_SLOW
}
}
}
*/
}

struct CustomRange(WithKeyPoints<RangedCoordf64>);
Expand Down
6 changes: 2 additions & 4 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ pub enum Grading {
#[derive(Debug, PartialEq)]
pub struct TrackResult {
pub pilot_name: String,
pub glide_slope: f64,
pub grading: Grading,
pub dcs_grading: Option<String>,
pub datums: Vec<Datum>,
pub plane_type: &'static str,
pub plane_info: &'static AirplaneInfo,
}

impl Track {
Expand Down Expand Up @@ -158,11 +157,10 @@ impl Track {

TrackResult {
pilot_name: self.pilot_name,
glide_slope: self.plane_info.glide_slope,
grading,
dcs_grading: self.dcs_grading,
datums: self.datums,
plane_type: self.plane_info.plane_type,
plane_info: self.plane_info,
}
}

Expand Down

0 comments on commit 0da809d

Please sign in to comment.