Closed Gaiiden closed 9 years ago
Ok looks like the roll_for()
function is using the angle between the up vector and the vessel starboard vector without taking into account the pitch.
For a quick fix replace the line
local raw is vang(ves:up:vector, ves:facing:starvector).
with
local raw is vang(vxcl(ship:facing:vector,ship:up:vector, ves:facing:starvector).
It will give slightly odd results when the facing and up vectors are aligned but i will try and find a way round that in the main code.
If i can i may use the existing pitch_for()
function to exclude some of the result, if not it will just be a small dead zone.
edit: to see the issue / change add the below code to the main loop:
local old_vec is vecdrawargs(
v(0,0,0),
ship:up:vector,
red,
"before change",
2,
true
).
local star_vec is vecdrawargs(
v(0,0,0),
ship:facing:starvector,
blue,
"ves star",
2,
true
).
local new_vec is vecdrawargs(
v(0,0,0),
vxcl(ship:facing:vector,ship:up:vector):normalized,
green,
"after change",
2,
true
).
It will give slightly odd results when the facing and up vectors are aligned but i will try and find a way round that in the main code.
That's correct behavior. It's true gimbal lock. Imagine if you have an airplane going straight up. There is not enough information to know your heading and roll at the same time, because one alters the other. i.e. pitch 90, compass 90, roll 0 gives the identical orientation as pitch 90, compass 45, roll -45 or pitch 90, compass 0, roll -90, etc. It's all of the above at once: pure information loss.
quick fix - thx TDW! Thanks also for the clarification Dunbaratu
using this code pasted straight in from the lib:
Here are the results:
good initially:
gets thrown off quick though:
discrepancy increases quickly:
sudden jump at around -26deg to triple digits:
gradually goes back to correct on the other side:
Craft used was an AIES Nova core hooked onto IR rotatotron and hinge in order to roll and pitch. Solar panels and batteries for power