-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib_navball.ks
More file actions
50 lines (37 loc) · 965 Bytes
/
lib_navball.ks
File metadata and controls
50 lines (37 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// A library of functions to calculate navball-based directions:
// This file is distributed under the terms of the MIT license, (c) the KSLib team
@lazyglobal off.
function east_for {
parameter ves.
return vcrs(ves:up:vector, ves:north:vector).
}
function compass_for {
parameter ves.
local pointing is ves:facing:forevector.
local east is east_for(ves).
local trig_x is vdot(ves:north:vector, pointing).
local trig_y is vdot(east, pointing).
local result is arctan2(trig_y, trig_x).
if result < 0 {
return 360 + result.
} else {
return result.
}
}
function pitch_for {
parameter ves.
return 90 - vang(ves:up:vector, ves:facing:forevector).
}
function roll_for {
parameter ves.
local raw is vang(ves:up:vector, ves:facing:starvector).
if vang(ves:up:vector, ves:facing:topvector) > 90 {
if raw > 90 {
return raw - 270.
} else {
return raw + 90.
}
} else {
return 90 - raw.
}
}.