Jump to content

How to know the spaceship orientation


Recommended Posts

I don't speak english fluently

HI !

I would like to know how to obtain the spaceship orientation (pitch, yaw, roll) for display a custom navball on my dashboard. I found this code here but it doesn't works very well (it indicates the same orientation for differents orientations) :

private Quaternion updateHeadingPitchRollField (Vessel v)
{
    Vector3d CoM, north, up;
    Quaternion rotationSurface;
    CoM = v.CoM;
    up = (CoM - v.mainBody.position).normalized;
    north = Vector3d.Exclude(up, (v.mainBody.position + v.mainBody.transform.up * (float)v.mainBody.Radius) - CoM).normalized;
    rotationSurface = Quaternion.LookRotation(north, up);
    return Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(v.GetTransform().rotation) * rotationSurface);
}

Quaternion attitude = updateHeadingPitchRollField(ActiveVessel);

float pitch = (float) ((attitude.eulerAngles.x > 180) ? (360.0 - attitude.eulerAngles.x) : -attitude.eulerAngles.x);
float yaw = (float) attitude.eulerAngles.y;
float roll = (float) ((attitude.eulerAngles.z > 180) ? (attitude.eulerAngles.z - 360.0) : attitude.eulerAngles.z);

And if it possible, I would like to know also, how to obtain the orientation of the prograde, the normal, the radial-in, the maneuver and the target. I apologies for all these questions but  I didn't found a complete documentation on the subject.

Thanks.

Link to comment
Share on other sites

Well, I've never tried anything like this but I can imagine vessel.mainbody is going to be needed to find out which body is the dominant force and then vessel.gforce to get a vector 3 pointing toward the center of that mainbody.  That should be a good starting place.

Link to comment
Share on other sites

I said some bullexcrementss.

The code that I showed works very well. It just that I didn't know how to correctly interpret the returned data. So now, its works fine but I still don't know how to do the same with the prograd, retrograd, target, etc.. Thanks angain for your help.

NB : Nice censorbot btw XD

Edited by TheRedColossus
adding an NB
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...