Created
March 19, 2023 19:57
-
-
Save untoldwind/28b022d58b5d27dd3965003a17e3c129 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use { Vessel } from ksp::vessel | |
use { CONSOLE } from ksp::console | |
use { sleep } from ksp::game | |
use { GlobalDirection, Vec3, vec3 } from ksp::math | |
use { acos_deg, atan2_deg } from core::math | |
use { angle_to_360, angle_to_180 } from std::utils | |
pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = { | |
CONSOLE.clear() | |
for(i in 0..100) { | |
CONSOLE.print_at(1, 0, navball(vessel).to_fixed(2)) | |
sleep(0.5) | |
} | |
} | |
sync fn navball(vessel: Vessel) -> Vec3 = { | |
let roll = 90.0 - acos_deg(vessel.up * vessel.facing.right_vector) | |
const up_angles = acos_deg(vessel.up * vessel.facing.up_vector) | |
if (up_angles > 90) roll = 180 - roll | |
const yaw = atan2_deg(vessel.east * vessel.facing.vector, vessel.north * vessel.facing.vector) | |
const pitch = 90 - acos_deg(vessel.up * vessel.facing.vector) | |
vec3(pitch, angle_to_360(yaw), angle_to_180(roll)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment