export function get_real_horizon_angle_for_frame(frame) {
var jetPitch = jetPitchFromFrame(frame) // this will get scaled pitch
var jetRoll = jetRollFromFrame(frame)
var az = Frame2Az(frame)
var el = Frame2El(frame);
return getHumanHorizonFromPitchRollAzEl(jetPitch, jetRoll, az, el)
}
export function getHumanHorizonFromPitchRollAzEl(jetPitch, jetRoll, az, el) {
// if (type == 1) {
// return jetRoll * cos(radians(az)) + jetPitch * sin(radians(az));
// } else {
// // rotate the absolute 3D coordinates of (el, az) into the frame of reference of the jet
// vec3d relative_AzElHeading = EA2XYZ(el, az, 1)
// .rotate(vec3d { 1, 0, 0 }, -radians(jetPitch)) // reverse both the order and sign of these rotations
// .rotate(vec3d { 0, 0, 1 }, radians(jetRoll));
var AzElHeading = EA2XYZ(el, az, 1)
var relative_AzElHeading = AzElHeading
.applyAxisAngle(V3(1, 0, 0), -radians(jetPitch))
.applyAxisAngle(V3(0, 0, 1), radians(jetRoll))
// // caclulcate (el, az) angles relative to the frame of reference of the jet
// auto [relative_el, relative_az] = XYZ2EA(relative_AzElHeading);
var relative_el, relative_az;
[relative_el, relative_az] = XYZ2EA(relative_AzElHeading)
//
// // compute the jet's pose in the global frame of reference
// auto jetUp = vec3d { 0, 1, 0 }
// .rotate(vec3d { 0, 0, 1 }, -radians(jetRoll))
// .rotate(vec3d { 1, 0, 0 }, radians(jetPitch));
var jetUp = V3(0, 1, 0)
.applyAxisAngle(V3(0, 0, 1), -radians(jetRoll))
.applyAxisAngle(V3(1, 0, 0), radians(jetPitch))
// auto jetRight = vec3d { 1, 0, 0 }
// .rotate(vec3d { 0, 0, 1 }, -radians(jetRoll))
// .rotate(vec3d { 1, 0, 0 }, radians(jetPitch));
var jetRight = V3(1, 0, 0)
.applyAxisAngle(V3(0, 0, 1), -radians(jetRoll))
.applyAxisAngle(V3(1, 0, 0), radians(jetPitch))
// DebugArrowV("jetUp",jetUp)
// // rotate the camera by relative_az in the wing plane so that it's looking at the object
// // the camera pitching up by relative_el has no effect on a vector pointing right
// auto camera_horizon = jetRight.rotate(jetUp, -radians(relative_az));
var camera_horizon = jetRight.applyAxisAngle(jetUp, -radians(relative_az));
// DebugArrowV("camera_horizon",camera_horizon,100,0xff0000) // red
// pointObject3DAt(gridHelperNod, camera_horizon)
// // the real horizon is a vector pointing right, perpendicular to the global viewing angle az
// auto real_horizon = vec3d { 1, 0, 0 }.rotate(vec3d { 0, 1, 0 }, -radians(az));
var real_horizon = V3(1, 0, 0).applyAxisAngle(V3(0, 1, 0), -radians(az))
// DebugArrowV("real_horizon",real_horizon,100,0x00ff00) // green
//
// // it can be shown that the real horizon vector is already in the camera plane
// // so return the angle between the camera horizon and the real horizon
// return -degrees(camera_horizon.angleTo(real_horizon));
var horizon_angle = -degrees(camera_horizon.angleTo(real_horizon))
var cross = camera_horizon.clone().cross(real_horizon)
var dot = cross.dot(AzElHeading)
if (dot < 0)
return -horizon_angle
return horizon_angle
// }
// }
}