So I'm trying to find my vessel's current orientation relative to it's prograde vector so that this data can be fed to an autopilot.
This is what I have so far...
Now in theory when my vessel's nose is pointed prograde the currently active 'oapiDebugString()' should return "0.000, 0.000, 1.000".
It doesn't
Instead I get "-0.951, 0.000, 0.307". Now obviously X and Z axes got transposed somewhere but that doesn't explain why X wouldn't be +/- 1.000. What vector am I measuring if not prograde, and how do I find prograde?
ETA: The eventual purpose of this routine is to determine the offset between prograde and the vessel's thrust vector. Once I have the offset I can feed that data into the autopilot and have it align the two.
This is what I have so far...
Code:
//Vector Calculations for Guidance
VECTOR3 rVel, rPos;
GetRelativePos(GetGravityRef(), rPos);
normalise(rPos);
GetRelativeVel(GetGravityRef(), rVel);
normalise(rVel);
VECTOR3 horizon = crossp(rVel,rPos);
VECTOR3 NoseForwardVector = {0,0,1};
VECTOR3 RollVector = {1,0,0};
VECTOR3 ThrustVector = (GetThrusterDir(th_main));
MATRIX3 rotationMatrix;
GetRotationMatrix(rotationMatrix);
noseForwardVector = mul(rotationMatrix,NoseForwardVector);
double vPitch = asin(dotp(horizon,NoseForwardVector));
RollVector = mul(rotationMatrix,RollVector);
double vRoll = asin(dotp(horizon,RollVector));
// sprintf(oapiDebugString(),"Pitch %0.3f Roll %0.3f", vPitch*DEG, vRoll*DEG);
VECTOR3 input = (rVel);
input = mul(rotationMatrix,input);
normalise (input);
sprintf_s(oapiDebugString(), 255, "X, %0.3f Y %0.3f, Z %0.3f", input.x, input.y, input.z); // Debuggery
Now in theory when my vessel's nose is pointed prograde the currently active 'oapiDebugString()' should return "0.000, 0.000, 1.000".
It doesn't
Instead I get "-0.951, 0.000, 0.307". Now obviously X and Z axes got transposed somewhere but that doesn't explain why X wouldn't be +/- 1.000. What vector am I measuring if not prograde, and how do I find prograde?
ETA: The eventual purpose of this routine is to determine the offset between prograde and the vessel's thrust vector. Once I have the offset I can feed that data into the autopilot and have it align the two.
Last edited: