コード例 #1
0
ファイル: VesselTarget.cs プロジェクト: jonored/KOS
 public override Vector GetPosition()
 {
     return(new Vector(Vessel.findWorldCenterOfMass() - CurrentVessel.findWorldCenterOfMass()));
 }
コード例 #2
0
ファイル: VesselTarget.cs プロジェクト: jonored/KOS
 // TODO: We will need to replace with the same thing Orbitable:DISTANCE does
 // in order to implement the orbit solver later.
 public ScalarValue GetDistance()
 {
     return(Vector3d.Distance(CurrentVessel.findWorldCenterOfMass(), Vessel.findWorldCenterOfMass()));
 }
コード例 #3
0
 // TODO: We will need to replace with the same thing Orbitable:DISTANCE does
 // in order to implement the orbit solver later.
 public double GetDistance()
 {
     return(Vector3d.Distance(CurrentVessel.GetWorldPos3D(), Vessel.GetWorldPos3D()));
 }
コード例 #4
0
 override public Vector GetPosition()
 {
     return(new Vector(Vessel.GetWorldPos3D() - CurrentVessel.GetWorldPos3D()));
 }
コード例 #5
0
        // GUI
        private void WindowGUI(int windowID)
        {
            if (null == this.CurrentVessel)
            {
                return;
            }

            #region General GUI
            // General GUI window information
            GUIStyle mySty = new GUIStyle(GUI.skin.button);
            mySty.normal.textColor   = mySty.focused.textColor = Color.white;
            mySty.hover.textColor    = mySty.active.textColor = Color.yellow;
            mySty.onNormal.textColor = mySty.onFocused.textColor = mySty.onHover.textColor = mySty.onActive.textColor = Color.green;
            mySty.padding            = new RectOffset(2, 2, 2, 2);

            // Buoyancy -, current %, and + buttons
            GUILayout.BeginHorizontal();
            if (GUILayout.RepeatButton("-", mySty))
            {
                TargetBuoyantVessel  -= 0.002f;
                ToggleAltitudeControl = false;
            }
            TargetBuoyantVessel = Mathf.Clamp01(TargetBuoyantVessel);

            GUILayout.Label("        " + Mathf.RoundToInt(TargetBuoyantVessel * 100) + "%");

            if (GUILayout.RepeatButton("+", mySty))
            {
                TargetBuoyantVessel  += 0.002f;
                ToggleAltitudeControl = false;
            }
            GUILayout.EndHorizontal();

            // Slider control.  Also is set by the other controls.
            GUILayout.BeginHorizontal();
            {
                float temp = TargetBuoyantVessel;
                TargetBuoyantVessel = GUILayout.HorizontalSlider(TargetBuoyantVessel, 0f, 1f);
                if (temp != TargetBuoyantVessel)
                {
                    ToggleAltitudeControl = false;
                }
            }
            GUILayout.EndHorizontal();

            TargetBuoyantVessel = Mathf.Clamp01(TargetBuoyantVessel);
            #endregion

            #region Toggle Altitude
            // Altitude control.  Should be deactivated when pressing any other unrelated control.
            GUILayout.BeginHorizontal();
            {
                string toggleAltitudeControlString = "Altitude Control Off";
                if (ToggleAltitudeControl)
                {
                    toggleAltitudeControlString = "Altitude Control On";
                }
                ToggleAltitudeControl = GUILayout.Toggle(ToggleAltitudeControl, toggleAltitudeControlString);
            }
            GUILayout.EndHorizontal();
            #endregion

            if (ToggleAltitudeControl)
            {
                #region Altitude Control
                willReset1 = true;

                // Vertical Velocity -, target velocity, and + buttons
                GUILayout.BeginHorizontal();
                GUILayout.Label("Target Vertical Velocity");
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("--", mySty))
                {
                    TargetVerticalVelocity -= 0.1f;
                }
                if (GUILayout.Button("-", mySty))
                {
                    TargetVerticalVelocity -= 0.1f;
                }
                if (GUILayout.Button(TargetVerticalVelocity.ToString("00.0") + " m/s", mySty))
                {
                    TargetVerticalVelocity = 0;
                }
                if (GUILayout.Button("+", mySty))
                {
                    TargetVerticalVelocity += 0.1f;
                }
                if (GUILayout.RepeatButton("++", mySty))
                {
                    TargetVerticalVelocity += 0.1f;
                }
                GUILayout.EndHorizontal();
                #endregion
            }
            else
            {
                TargetVerticalVelocity = 0;
                if (willReset1)
                {
                    resetGUIsize = true;
                    willReset1   = false;
                }
            }

            if (Envelopes.Count > 1)
            {
                GUILayout.BeginHorizontal();
                string toggleAutoPitchString = "Auto Pitch Off";
                if (ToggleAutoPitch)
                {
                    toggleAutoPitchString = "Auto Pitch On";
                }
                ToggleAutoPitch = GUILayout.Toggle(ToggleAutoPitch, toggleAutoPitchString);
                GUILayout.EndHorizontal();
            }

            if (ToggleAutoPitch)
            {
                willReset4 = true;
            }
            else
            {
                if (willReset4)
                {
                    resetGUIsize = true;
                    willReset4   = false;
                }
            }

            if (ToggleAutoPitch)
            {
                willReset2 = true;

#if DEBUG
                DisplayHologram = GUILayout.Toggle(DisplayHologram, "Display Hologram at " + LineOffsetMultiplier.ToString("F1"));
                if (DisplayHologram)
                {
                    LineOffsetMultiplier = GUILayout.HorizontalSlider(LineOffsetMultiplier, -20f, 20f);
                }
#endif
            }
            else
            {
                DisplayHologram = false;
                if (willReset2)
                {
                    resetGUIsize = true;
                    willReset2   = false;
                }
            }

            if (AnchorPresent)
            {
                GUILayout.BeginHorizontal();
                string toggleAnchor = "Anchor Inactive";
                if (AnchorOn)
                {
                    toggleAnchor = "Anchor Active";
                }
                AnchorOn = GUILayout.Toggle(AnchorOn, toggleAnchor);
                string toggleAutoAnchor = "Auto Anchor Off";
                if (AutoAnchor)
                {
                    toggleAutoAnchor = "Auto Anchor On";
                }
                AutoAnchor = GUILayout.Toggle(AutoAnchor, toggleAutoAnchor);
                GUILayout.EndHorizontal();
            }

            if (resetGUIsize)
            {
                // Reset window size
                windowPos.Set(windowPos.x, windowPos.y, 10, 10);
                resetGUIsize = false;
            }

            #region Debug
            // Debug info


            GUILayout.BeginHorizontal();
            GUILayout.Label("Buoyancy - Weight: " + (TotalBuoyancy - (CurrentVessel.GetTotalMass() * FlightGlobals.getGeeForceAtPosition(CurrentVessel.GetWorldPos3D()).magnitude)).ToString("0.00"));
            GUILayout.EndHorizontal();

            //GUILayout.BeginHorizontal();
            //GUILayout.Label("Angle from Up: " + (ContAngle(heading, up, up)).ToString("0.0"));
            //GUILayout.EndHorizontal();

            //GUILayout.BeginHorizontal();
            //GUILayout.Label("Front Torque: " + (totalTorqueP).ToString("0.0"));
            //GUILayout.EndHorizontal();

            //GUILayout.BeginHorizontal();
            //GUILayout.Label("Rear Torque: " + (totalTorqueN).ToString("0.0"));
            //GUILayout.EndHorizontal();

            //GUILayout.BeginHorizontal();
            //GUILayout.Label("Front B: " + (targetBuoyancyP).ToString("0.00"));
            //GUILayout.EndHorizontal();

            //GUILayout.BeginHorizontal();
            //GUILayout.Label("Rear B: " + (targetBuoyancyN).ToString("0.00"));
            //GUILayout.EndHorizontal();

                #if DEBUG
            int x = 0;
            foreach (HLEnvelopePartModule envelope in Envelopes)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Env" + x + " Location: " + (envelope.eDistanceFromCoM).ToString("0.00"));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Env" + x + " Buoyancy: " + (envelope.buoyantForce.magnitude).ToString("0.00"));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Env" + x + " Specific Volume: " + (envelope.specificVolumeFractionEnvelope).ToString("0.00"));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Env" + x + " targetPitchBuoyancy: " + (envelope.targetPitchBuoyancy).ToString("0.00"));
                GUILayout.EndHorizontal();
                //GUILayout.BeginHorizontal();
                //GUILayout.Label("Env" + x + " targetBoyantForceFractionCompressor: " + (envelope.targetBoyantForceFractionCompressor).ToString("0.00"));
                //GUILayout.EndHorizontal();

                x += 1;
            }
                #endif
            #endregion

            GUI.DragWindow(new Rect(0, 0, 500, 20));
        }
コード例 #6
0
ファイル: VesselTarget.cs プロジェクト: silky/KOS
        public override object GetSuffix(string suffixName)
        {
            switch (suffixName)
            {
            case "CONTROL":
                return(FlightControlManager.GetControllerByVessel(Vessel));

            case "DIRECTION":
                var vector = (Vessel.GetWorldPos3D() - CurrentVessel.GetWorldPos3D());
                return(new Direction(vector, false));

            case "DISTANCE":
                return((float)GetDistance());

            case "BEARING":
                return(VesselUtils.GetTargetBearing(CurrentVessel, Vessel));

            case "HEADING":
                return(VesselUtils.GetTargetHeading(CurrentVessel, Vessel));

            case "PROGRADE":
                return(GetPrograde());

            case "RETROGRADE":
                return(GetRetrograde());

            case "MAXTHRUST":
                return(VesselUtils.GetMaxThrust(Vessel));

            case "VELOCITY":
                return(new VesselVelocity(Vessel));

            case "GEOPOSITION":
                return(new GeoCoordinates(Vessel));

            case "LATITUDE":
                return(VesselUtils.GetVesselLattitude(Vessel));

            case "LONGITUDE":
                return(VesselUtils.GetVesselLongitude(Vessel));

            case "FACING":
                return(GetFacing());

            case "UP":
                return(new Direction(Vessel.upAxis, false));

            case "NORTH":
                return(new Direction(VesselUtils.GetNorthVector(Vessel), false));

            case "BODY":
                return(new BodyTarget(Vessel.mainBody, Vessel));

            case "ANGULARMOMENTUM":
                return(new Direction(Vessel.angularMomentum, true));

            case "ANGULARVEL":
                return(new Direction(Vessel.angularVelocity, true));

            case "MASS":
                return(Vessel.GetTotalMass());

            case "VERTICALSPEED":
                return(Vessel.verticalSpeed);

            case "SURFACESPEED":
                return(Vessel.horizontalSrfSpeed);

            case "AIRSPEED":
                return
                    ((Vessel.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(Vessel.GetWorldPos3D()))
                     .magnitude);       //the velocity of the vessel relative to the air);

            case "VESSELNAME":
                return(Vessel.vesselName);

            case "ALTITUDE":
                return(Vessel.altitude);

            case "APOAPSIS":
                return(Vessel.orbit.ApA);

            case "PERIAPSIS":
                return(Vessel.orbit.PeA);

            case "SENSORS":
                return(new VesselSensors(Vessel));

            case "TERMVELOCITY":
                return(VesselUtils.GetTerminalVelocity(Vessel));

            case "LOADED":
                return(Vessel.loaded);

            case "OBT":
                return(new OrbitInfo(Vessel));

            case "SRFPROGRADE":
                return(GetSurfacePrograde());
            }

            // Is this a resource?
            double dblValue;

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

            return(base.GetSuffix(suffixName));
        }