GetNorthVector() public static method

public static GetNorthVector ( Vessel vessel ) : UnityEngine.Vector3d
vessel Vessel
return UnityEngine.Vector3d
Beispiel #1
0
        public float GetHeadingFromVessel(Vessel vessel)
        {
            var up    = vessel.upAxis;
            var north = VesselUtils.GetNorthVector(vessel);

            var targetWorldCoords = vessel.mainBody.GetWorldSurfacePosition(Lat, Lng, vessel.altitude);

            var vector   = Vector3d.Exclude(vessel.upAxis, targetWorldCoords - vessel.GetWorldPos3D()).normalized;
            var headingQ = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(Quaternion.LookRotation(vector, up)) * Quaternion.LookRotation(north, up));

            return(headingQ.eulerAngles.y);
        }
Beispiel #2
0
        public override void Execute(SharedObjects shared)
        {
            double pitchAboveHorizon = GetDouble(shared.Cpu.PopValue());
            double degreesFromNorth = GetDouble(shared.Cpu.PopValue());

            Vessel currentVessel = shared.Vessel;
            var q = UnityEngine.Quaternion.LookRotation(VesselUtils.GetNorthVector(currentVessel), currentVessel.upAxis);
            q *= UnityEngine.Quaternion.Euler(new UnityEngine.Vector3((float)-pitchAboveHorizon, (float)degreesFromNorth, 0));

            Direction result = new Direction(q);
            shared.Cpu.PushStack(result);
        }
Beispiel #3
0
        public override object GetSuffix(string suffixName)
        {
            if (suffixName == "DIRECTION")
            {
                var vector = (target.GetWorldPos3D() - context.Vessel.GetWorldPos3D());
                return(new Direction(vector, false));
            }

            if (suffixName == "DISTANCE")
            {
                return((float)GetDistance());
            }
            if (suffixName == "BEARING")
            {
                return(VesselUtils.GetTargetBearing(context.Vessel, target));
            }
            if (suffixName == "HEADING")
            {
                return(VesselUtils.GetTargetHeading(context.Vessel, target));
            }
            if (suffixName == "PROGRADE")
            {
                return(GetPrograde());
            }
            if (suffixName == "RETROGRADE")
            {
                return(GetRetrograde());
            }
            if (suffixName == "MAXTHRUST")
            {
                return(VesselUtils.GetMaxThrust(target));
            }
            if (suffixName == "VELOCITY")
            {
                return(new VesselVelocity(target));
            }
            if (suffixName == "GEOPOSITION")
            {
                return(new GeoCoordinates(target));
            }
            if (suffixName == "LATITUDE")
            {
                return(VesselUtils.GetVesselLattitude(target));
            }
            if (suffixName == "LONGITUDE")
            {
                return(VesselUtils.GetVesselLongitude(target));
            }
            if (suffixName == "FACING")
            {
                return(GetFacing());
            }
            if (suffixName == "UP")
            {
                return(new Direction(target.upAxis, false));
            }
            if (suffixName == "NORTH")
            {
                return(new Direction(VesselUtils.GetNorthVector(target), false));
            }
            if (suffixName == "BODY")
            {
                return(target.mainBody.bodyName);
            }
            if (suffixName == "ANGULARMOMENTUM")
            {
                return(new Direction(target.angularMomentum, true));
            }
            if (suffixName == "ANGULARVEL")
            {
                return(new Direction(target.angularVelocity, true));
            }
            if (suffixName == "MASS")
            {
                return(target.GetTotalMass());
            }
            if (suffixName == "VERTICALSPEED")
            {
                return(target.verticalSpeed);
            }
            if (suffixName == "SURFACESPEED")
            {
                return(target.horizontalSrfSpeed);
            }
            if (suffixName == "AIRSPEED")
            {
                return((target.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(target.GetWorldPos3D())).magnitude);                          //the velocity of the vessel relative to the air);
            }
            if (suffixName == "VESSELNAME")
            {
                return(target.vesselName);
            }
            if (suffixName == "ALTITUDE")
            {
                return(target.altitude);
            }
            if (suffixName == "APOAPSIS")
            {
                return(target.orbit.ApA);
            }
            if (suffixName == "PERIAPSIS")
            {
                return(target.orbit.PeA);
            }
            if (suffixName == "SENSOR")
            {
                return(new VesselSensors(target));
            }
            if (suffixName == "TERMVELOCITY")
            {
                return(VesselUtils.GetTerminalVelocity(target));
            }

            // Is this a resource?
            double dblValue;

            if (VesselUtils.TryGetResource(target, suffixName, out dblValue))
            {
                return(dblValue);
            }

            return(base.GetSuffix(suffixName));
        }
        public override void AddTo(BindingManager manager)
        {
            manager.AddGetter("VESSELNAME", delegate(CPU cpu) { return(cpu.Vessel.vesselName); });
            manager.AddSetter("VESSELNAME", delegate(CPU cpu, object value) { cpu.Vessel.vesselName = value.ToString(); });

            manager.AddGetter("ALTITUDE", delegate(CPU cpu) { return((float)cpu.Vessel.altitude); });
            manager.AddGetter("ALT:RADAR", delegate(CPU cpu) { return((float)cpu.Vessel.heightFromTerrain); });
            manager.AddGetter("MISSIONTIME", delegate(CPU cpu) { return((float)cpu.Vessel.missionTime); });
            manager.AddGetter("STATUS", delegate(CPU cpu) { return(cpu.Vessel.situation.ToString().Replace("_", " ")); });
            manager.AddGetter("APOAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.ApA); });
            manager.AddGetter("PERIAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.PeA); });

            manager.AddGetter("ALT:APOAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.ApA); });
            manager.AddGetter("ALT:PERIAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.PeA); });
            manager.AddGetter("ETA:APOAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.timeToAp); });
            manager.AddGetter("ETA:PERIAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.timeToPe); });

            manager.AddGetter("VELOCITY", delegate(CPU cpu) { return(cpu.Vessel.obt_velocity); });
            manager.AddGetter("ANGULARMOMENTUM", delegate(CPU cpu) { return(new Direction(cpu.Vessel.angularMomentum, true)); });
            manager.AddGetter("ANGULARVEL", delegate(CPU cpu) { return(new Direction(cpu.Vessel.angularVelocity, true)); });
            manager.AddGetter("MASS", delegate(CPU cpu) { return(cpu.Vessel.GetTotalMass()); });
            manager.AddGetter("VERTICALSPEED", delegate(CPU cpu) { return((float)cpu.Vessel.verticalSpeed); });
            manager.AddGetter("SURFACESPEED", delegate(CPU cpu) { return((float)cpu.Vessel.horizontalSrfSpeed); });

            manager.AddGetter("BODY", delegate(CPU cpu) { return(cpu.Vessel.mainBody.bodyName); });
            manager.AddGetter("LATITUDE", delegate(CPU cpu) { return((float)cpu.Vessel.latitude); });
            manager.AddGetter("LONGITUDE", delegate(CPU cpu) { return((float)cpu.Vessel.longitude); });

            manager.AddGetter("HEADING", delegate(CPU cpu) { return(VesselUtils.GetHeading(cpu.Vessel)); });

            manager.AddGetter("NORTH", delegate(CPU cpu) { return(new Direction(VesselUtils.GetNorthVector(cpu.Vessel), false)); });
            manager.AddGetter("UP", delegate(CPU cpu) { return(new Direction(cpu.Vessel.upAxis, false)); });

            manager.AddGetter("NODE", delegate(CPU cpu) {
                var vessel = cpu.Vessel;
                if (!vessel.patchedConicSolver.maneuverNodes.Any())
                {
                    throw new kOSException("No maneuver nodes present!");
                }
                var up     = (vessel.findLocalMOI(vessel.findWorldCenterOfMass()) - vessel.mainBody.position).normalized;
                var fwd    = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(cpu.Vessel.orbit);
                var rotRef = Quaternion.LookRotation(fwd, up);

                Direction d = new Direction();
                d.Rotation  = rotRef;
                return(d);
            });

            manager.AddGetter("MAG:NODE", delegate(CPU cpu) {
                var vessel = cpu.Vessel;
                var orbit  = vessel.orbit;
                if (!vessel.patchedConicSolver.maneuverNodes.Any())
                {
                    throw new kOSException("No maneuver nodes present!");
                }
                var mag = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit).magnitude;

                return((float)mag);
            });

            manager.AddGetter("ETA:NODE", delegate(CPU cpu) {
                var vessel = cpu.Vessel;
                if (!vessel.patchedConicSolver.maneuverNodes.Any())
                {
                    throw new kOSException("No maneuver nodes present!");
                }
                var time     = vessel.patchedConicSolver.maneuverNodes[0].UT;
                var currTime = Planetarium.GetUniversalTime();

                return((float)(time - currTime));
            });

            manager.AddGetter("PROGRADE", delegate(CPU cpu)
            {
                var vessel = cpu.Vessel;
                var up     = (vessel.findLocalMOI(vessel.findWorldCenterOfMass()) - vessel.mainBody.position).normalized;

                Direction d = new Direction();
                d.Rotation  = Quaternion.LookRotation(cpu.Vessel.orbit.GetVel().normalized, up);
                return(d);
            });

            manager.AddGetter("RETROGRADE", delegate(CPU cpu)
            {
                var vessel = cpu.Vessel;
                var up     = (vessel.findLocalMOI(vessel.findWorldCenterOfMass()) - vessel.mainBody.position).normalized;

                Direction d    = new Direction();
                var vesselRoll = cpu.Vessel.GetTransform().eulerAngles.y;
                d.Rotation     = Quaternion.LookRotation(cpu.Vessel.orbit.GetVel().normalized * -1, up);
                return(d);
            });

            manager.AddGetter("FACING", delegate(CPU cpu)
            {
                var facing = cpu.Vessel.transform.up;
                return(new Direction(new Vector3d(facing.x, facing.y, facing.z).normalized, false));
            });

            manager.AddGetter("MAXTHRUST", delegate(CPU cpu)
            {
                return(VesselUtils.GetMaxThrust(cpu.Vessel));
            });

            manager.AddGetter("AV", delegate(CPU cpu) { return(cpu.Vessel.transform.InverseTransformDirection(cpu.Vessel.rigidbody.angularVelocity)); });

            manager.AddGetter("STAGE", delegate(CPU cpu) { return(new StageValues(cpu.Vessel)); });
        }