kOS-scripts/lib/vectors.ks
Casper V. Kristensen a664626468
Implement simple GUI.
2019-03-01 23:08:50 +01:00

82 lines
3.1 KiB
Plaintext

@LAZYGLOBAL OFF.
// Define actual_prograde, which automatically switches from SHIP:SRFPROGRADE to SHIP:PROGRADE
local function set_actual_prograde {
if NAVMODE = "SURFACE" {
print "Switched actual_prograde to surface SRFPROGRADE".
lock actual_prograde to SHIP:srfprograde.
} else {
print "Switched actual_prograde to orbit PROGRADE".
lock actual_prograde to SHIP:prograde.
}
return true. // preserve trigger
}
on NAVMODE {return set_actual_prograde().}
set_actual_prograde().
function vdraw {
//
// Wrapper for the VECDRAW-function that doesn't hide the vector by default.
//
parameter start is V(0,0,0). // vector or function. For example, pass {return UP:vector.} to automatically update the draw
parameter vector is V(0,0,0). // same as start
parameter color is RED.
parameter label is "".
parameter show is true.
parameter scale is 1.0.
parameter width is 0.2.
return vecdraw(
start,
vector,
color,
label,
scale,
show,
width
).
}
function ship_raw_to_ship_control {
//
// Translate a vector in SHIP-RAW coordinates to one in SHIP-CONTROL (STARBOARD, TOP, FORE) coordinates.
//
parameter vec.
return V(vdot(vec, FACING:starvector), // projection is correct because SHIP's FACING vectors are normalised
vdot(vec, FACING:topvector),
vdot(vec, FACING:forevector)). // Same order as SHIP:CONTROL:TRANSLATION's input
}
// ANGLES
lock actual_prograde_pitch to vang(actual_prograde:vector, UP:vector).
// // the following are all vectors, mainly for use in the roll, pitch, and angle of attack calculations
// lock rightrotation to ship:facing*r(0,90,0).
// lock right to rightrotation:vector. //right and left are directly along wings
// lock left to (-1)*right.
// lock up to ship:up:vector. //up and down are skyward and groundward
// lock down to (-1)*up.
// lock fore to ship:facing:vector. //fore and aft point to the nose and tail
// lock aft to (-1)*fore.
// lock righthor to vcrs(up,fore). //right and left horizons
// lock lefthor to (-1)*righthor.
// lock forehor to vcrs(righthor,up). //forward and backward horizons
// lock afthor to (-1)*forehor.
// lock top to vcrs(fore,right). //above the cockpit, through the floor
// lock bottom to (-1)*top.
// // the following are all angles, useful for control programs
// lock absaoa to vang(fore,srfprograde:vector). //absolute angle of attack
// lock aoa to vang(top,srfprograde:vector)-90. //pitch component of angle of attack
// lock sideslip to vang(right,srfprograde:vector)-90. //yaw component of aoa
// lock rollangle to vang(right,righthor)*((90-vang(top,righthor))/abs(90-vang(top,righthor))). //roll angle, 0 at level flight
// lock pitchangle to vang(fore,forehor)*((90-vang(fore,up))/abs(90-vang(fore,up))). //pitch angle, 0 at level flight
// lock glideslope to vang(srfprograde:vector,forehor)*((90-vang(srfprograde:vector,up))/abs(90-vang(srfprograde:vector,up))).
// lock ascentangle to vang(srfprograde:vector, forehor). //angle of surface prograde above horizon