コード例 #1
0
        /// <summary>
        /// Is the selected reference attitude valid?
        /// </summary>
        /// <param name="reference"></param>
        /// <returns></returns>
        private bool ValidReference(ReferenceAttitude reference)
        {
            if (reference == ReferenceAttitude.REF_MANEUVER_NODE)
            {
                if (node == null)
                {
                    return(false);
                }
            }
            else if (reference == ReferenceAttitude.REF_TARGET || reference == ReferenceAttitude.REF_TARGET_ORIENTATION || reference == ReferenceAttitude.REF_TARGET_RELATIVE_VEL)
            {
                if (activeTarget == null)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Configure and engage SAS.
        /// </summary>
        /// <param name="reference">Which attitude reference to apply.</param>
        /// <param name="HPR">Heading, Pitch, Roll</param>
        internal bool EngageAttitudePilot(ReferenceAttitude reference, Vector3 HPR)
        {
            if (!ValidReference(reference))
            {
                return(false);
            }

            if (!EngageSAS())
            {
                return(false);
            }

            relativeHPR         = HPR;
            relativeOrientation = Quaternion.AngleAxis(relativeHPR.x, Vector3.up) * Quaternion.AngleAxis(-relativeHPR.y, Vector3.right) * Quaternion.AngleAxis(-relativeHPR.z, Vector3.forward) * Quaternion.Euler(90, 0, 0);

            activeReference = reference;

            attitudePilotEngaged = true;

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Return the rotation that
        /// </summary>
        /// <param name="reference"></param>
        /// <returns></returns>
        internal Quaternion getReferenceAttitude(ReferenceAttitude reference)
        {
            Quaternion referenceQuat = Quaternion.identity;

            switch (reference)
            {
            case ReferenceAttitude.REF_INERTIAL:
                referenceQuat = Quaternion.identity;
                break;

            case ReferenceAttitude.REF_ORBIT_PROGRADE:
                referenceQuat = Quaternion.LookRotation(prograde, radialOut);
                break;

            case ReferenceAttitude.REF_ORBIT_HORIZONTAL:
                referenceQuat = Quaternion.LookRotation(Vector3.ProjectOnPlane(prograde, up), up);
                break;

            case ReferenceAttitude.REF_SURFACE_PROGRADE:
                referenceQuat = Quaternion.LookRotation(surfacePrograde, up);
                break;

            case ReferenceAttitude.REF_SURFACE_HORIZONTAL:
                referenceQuat = Quaternion.LookRotation(Vector3.ProjectOnPlane(surfacePrograde, up), up);
                break;

            case ReferenceAttitude.REF_SURFACE_NORTH:
                referenceQuat = Quaternion.LookRotation(vessel.north, up);
                break;

            case ReferenceAttitude.REF_TARGET:
                referenceQuat = Quaternion.LookRotation(targetDirection, radialOut);
                break;

            case ReferenceAttitude.REF_TARGET_RELATIVE_VEL:
                referenceQuat = Quaternion.LookRotation(targetRelativeVelocity.normalized, radialOut);
                break;

            case ReferenceAttitude.REF_TARGET_ORIENTATION:
                // TODO!!!
                referenceQuat = Quaternion.LookRotation(activeTarget.GetTransform().forward, activeTarget.GetTransform().up);
                //if (targetType == TargetType.CelestialBody)
                //{

                //}
                //else
                //{
                //    referenceQuat = Quaternion.LookRotation(targetDirection, radialOut);
                //}
                break;

            case ReferenceAttitude.REF_MANEUVER_NODE:
                // TODO: use radialOut at the time of the maneuver, not the current radialOut.  Or use the current top vector
                referenceQuat = Quaternion.LookRotation(maneuverNodeVector.normalized, radialOut);
                //referenceQuat = Quaternion.LookRotation(maneuverNodeVector.normalized, top); // This doesn't work right...
                //referenceQuat = Quaternion.LookRotation(maneuverNodeVector.normalized, vessel.GetTransform().up); // this just spins....
                break;

            case ReferenceAttitude.REF_SUN:
                referenceQuat = Quaternion.LookRotation((Planetarium.fetch.Sun.transform.position - vessel.CoM).normalized, Vector3.up);
                break;
            }

            return(referenceQuat);
        }