Ejemplo n.º 1
0
        public override OrbitableVelocity GetVelocitiesAtUT(TimeStamp timeStamp)
        {
            CelestialBody parent = Body.KOSExtensionGetParentBody();

            if (parent == null) // only if Body is Sun and therefore has no parent, then do more complex work instead because KSP didn't provide a way itself
            {
                Vector3d      futureOrbitalVel;
                CelestialBody soiBody = Shared.Vessel.mainBody;
                if (soiBody.orbit != null)
                {
                    futureOrbitalVel = soiBody.orbit.GetFrameVelAtUT(timeStamp.ToUnixStyleTime());
                }
                else
                {
                    futureOrbitalVel = -1 * VesselTarget.CreateOrGetExisting(Shared.Vessel, Shared).GetVelocitiesAtUT(timeStamp).Orbital.ToVector3D();
                }
                Vector swappedVel = new Vector(futureOrbitalVel.x, futureOrbitalVel.z, futureOrbitalVel.y); // swap Y and Z because KSP API is weird.
                // Also invert directions because the above gives vel of my body rel to sun, and I want vel of sun rel to my body:
                return(new OrbitableVelocity(-swappedVel, -swappedVel));
            }

            var orbVel = new Vector(Orbit.getOrbitalVelocityAtUT(timeStamp.ToUnixStyleTime()));

            orbVel = new Vector(orbVel.X, orbVel.Z, orbVel.Y); // swap Y and Z because KSP API is weird.

            var surfVel = new Vector(Body.orbit.GetVel() - parent.getRFrmVel(Body.position));

            return(new OrbitableVelocity(orbVel, surfVel));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Calculates the position of this vessel at some future universal timestamp,
        ///   taking into account all currently predicted SOI transition patches, and also
        ///   assuming that all the planned maneuver nodes will actually be executed precisely
        ///   as planned.  Note that this cannot "see" into the future any farther than the
        ///   KSP orbit patches setting allows for.
        /// </summary>
        /// <param name="timeStamp">The time to predict for.  Although the intention is to
        ///   predict for a future time, it could be used to predict for a past time.</param>
        /// <returns>The position as a user-readable Vector in Shared.Vessel-origin raw rotation coordinates.</returns>
        public override Vector GetPositionAtUT(TimeStamp timeStamp)
        {
            string blockingTech;

            if (!Career.CanMakeNodes(out blockingTech))
            {
                throw new KOSLowTechException("use POSITIONAT on a vessel", blockingTech);
            }

            double desiredUT = timeStamp.ToUnixStyleTime();

            Orbit    patch = GetOrbitAtUT(desiredUT);
            Vector3d pos   = patch.getPositionAtUT(desiredUT);

            // This is an ugly workaround to fix what is probably a bug in KSP's API:
            // If looking at a future orbit patch around a child body of the current body, then
            // the various get{Thingy}AtUT() methods return numbers calculated incorrectly as
            // if the child body was going to remain stationary where it is now, rather than
            // taking into account where it will be later when the intercept happens.
            // This corrects for that case:
            if (Utils.BodyOrbitsBody(patch.referenceBody, Vessel.orbit.referenceBody))
            {
                Vector3d futureSOIPosNow   = patch.referenceBody.position;
                Vector3d futureSOIPosLater = patch.referenceBody.getPositionAtUT(desiredUT);
                Vector3d offset            = futureSOIPosLater - futureSOIPosNow;
                pos = pos + offset;
            }

            return(new Vector(pos - Shared.Vessel.CoMD)); // Convert to ship-centered frame.
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Calculates the velocities of this vessel at some future universal timestamp,
        ///   taking into account all currently predicted SOI transition patches, and also
        ///   assuming that all the planned maneuver nodes will actually be executed precisely
        ///   as planned.  Note that this cannot "see" into the future any farther than the
        ///   KSP orbit patches setting allows for.
        /// </summary>
        /// <param name="timeStamp">The time to predict for.  Although the intention is to
        ///   predict for a future time, it could be used to predict for a past time.</param>
        /// <returns>The orbit/surface velocity pair as a user-readable Vector in raw rotation coordinates.</returns>
        public override OrbitableVelocity GetVelocitiesAtUT(TimeStamp timeStamp)
        {
            string blockingTech;

            if (!Career.CanMakeNodes(out blockingTech))
            {
                throw new KOSLowTechException("use VELOCITYAT on a vessel", blockingTech);
            }

            double desiredUT = timeStamp.ToUnixStyleTime();

            Orbit patch = GetOrbitAtUT(desiredUT);

            Vector3d orbVel = patch.getOrbitalVelocityAtUT(desiredUT);

            // This is an ugly workaround to fix what is probably a bug in KSP's API:
            // If looking at a future orbit patch around a child body of the current body, then
            // the various get{Thingy}AtUT() methods return numbers calculated incorrectly as
            // if the child body was going to remain stationary where it is now, rather than
            // taking into account where it will be later when the intercept happens.
            // This corrects for that case:
            if (Utils.BodyOrbitsBody(patch.referenceBody, Vessel.orbit.referenceBody))
            {
                Vector3d futureBodyVel = patch.referenceBody.orbit.getOrbitalVelocityAtUT(desiredUT);
                orbVel = orbVel + futureBodyVel;
            }

            // For some weird reason orbital velocities are returned by the KSP API
            // with Y and Z swapped, so swap them back:
            orbVel = new Vector3d(orbVel.x, orbVel.z, orbVel.y);

            CelestialBody parent = patch.referenceBody;
            Vector        surfVel;

            if (parent != null)
            {
                Vector3d pos = GetPositionAtUT(timeStamp);
                surfVel = new Vector(orbVel - parent.getRFrmVel(pos + Shared.Vessel.CoMD));
            }
            else
            {
                surfVel = new Vector(orbVel.x, orbVel.y, orbVel.z);
            }

            return(new OrbitableVelocity(new Vector(orbVel), surfVel));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Get the velocity pairing of this thing in this orbit at the given
        ///   time.  Note that it does NOT take into account any
        ///   encounters or maneuver nodes - it assumes the current
        ///   orbit patch remains followed forever.
        /// </summary>
        /// <param name="timeStamp">The universal time to query for</param>
        /// <returns></returns>
        public OrbitableVelocity GetVelocityAtUT(TimeStamp timeStamp)
        {
            var orbVel = new Vector(orbit.getOrbitalVelocityAtUT(timeStamp.ToUnixStyleTime()));

            // For some weird reason orbit returns velocities with Y and Z swapped, so flip them back:
            orbVel = new Vector(orbVel.X, orbVel.Z, orbVel.Y);
            CelestialBody parent = orbit.referenceBody;
            Vector        surfVel;

            if (parent != null)
            {
                Vector3d pos = GetPositionAtUT(timeStamp);
                surfVel = new Vector(orbVel - parent.getRFrmVel(pos + Shared.Vessel.CoMD));
            }
            else
            {
                surfVel = new Vector(orbVel.X, orbVel.Y, orbVel.Z);
            }
            return(new OrbitableVelocity(orbVel, surfVel));
        }
Ejemplo n.º 5
0
 /// <summary>
 ///   Get the position of this thing in this orbit at the given
 ///   time.  Note that it does NOT take into account any
 ///   encounters or maneuver nodes - it assumes the current
 ///   orbit patch remains followed forever.
 /// </summary>
 /// <param name="timeStamp">The universal time to query for</param>
 /// <returns></returns>
 public Vector GetPositionAtUT(TimeStamp timeStamp)
 {
     return(new Vector(orbit.getPositionAtUT(timeStamp.ToUnixStyleTime()) - Shared.Vessel.CoMD));
 }
Ejemplo n.º 6
0
 public override Vector GetPositionAtUT(TimeStamp timeStamp)
 {
     return(new Vector(Body.getPositionAtUT(timeStamp.ToUnixStyleTime()) - Shared.Vessel.CoMD));
 }
Ejemplo n.º 7
0
 public Node(TimeStamp stamp, double radialOut, double normal, double prograde, SharedObjects sharedObj)
     : this(stamp.ToUnixStyleTime(), radialOut, normal, prograde, sharedObj)
 {
 }