コード例 #1
0
        public override void OnCenterOfThrustQuery(CenterOfThrustQuery qry)
        {
            base.OnCenterOfThrustQuery(qry);

            if (HighLogic.LoadedSceneIsEditor)
            {
                qry.pos = EditorMarker_CoM.findCenterOfMass(EditorLogic.RootPart);
            }
        }
コード例 #2
0
 private string GetCenterOfMass()
 {
     if (EditorLogic.RootPart)
     {
         return(EditorMarker_CoM.findCenterOfMass(EditorLogic.RootPart).ToString("F4"));
     }
     else
     {
         return("No vessel");
     }
 }
コード例 #3
0
        void UpdateSegmentsInEditor()
        {
            comCheckCntr++;
            if (comCheckCntr > 15)
            {
                comCheckCntr = 0;

                oCoM = CoM;
                CoM  = (EditorMarker_CoM)FindObjectOfType(typeof(EditorMarker_CoM));
                if (CoM != oCoM)
                {
                    //UpdateSegments();
                    //updateSegmentsIn = -1;
                    updateSegmentsIn = 5;
                }
            }
            if (leftClick)
            {
                if (enableEngineerReport-- == 0)
                {
                    EngineersReport.Instance.appLauncherButton.Enable();
                }
                if (enableEngineerReport == -3)
                {
                    EngineersReport.Instance.appLauncherButton.onHover();
                }
                if (enableEngineerReport == -6)
                {
                    EngineersReport.Instance.appLauncherButton.onLeftClick();
                    // Following needed because it will be toggled by the "onLeftClick()" method below
                    leftClick = !leftClick;
                }
            }
            if (updateSegmentsIn-- == 0)
            {
                UpdateSegments();
                if (leftClick)
                {
                    GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartTweaked, part);

                    EngineersReport.Instance.appLauncherButton.Disable();
                    enableEngineerReport = 3;
                }
            }
        }
コード例 #4
0
        private void SetCoMTarget()
        {
            // We are depending on the CoM indicator for the location of the CoM which is a bit rubbish :( There ust be a better way of doing this!
            EditorMarker_CoM coM = (EditorMarker_CoM)FindObjectOfType(typeof(EditorMarker_CoM));

            if (coM == null)
            {
                // There is no CoM indicator. Spawn an instruction screen or something
                _osd.Error("To set the target CoM, first turn on the CoM Marker");
            }
            else
            {
                // get the location of the centre of mass
                //print("Com position: " + CoM.transform.position);
                Vector3 vecCom = coM.transform.position;
                //print("vecCom: " + vecCom);

                RotationInEditor = part.transform.rotation;
                //print("Part position: " + part.transform.position);
                Vector3 vecPartLocation = part.transform.position;
                //print("vecPartLocation: " + vecPartLocation);

                // What really interests us is the location fo the CoM relative to the part that is the balancer
                VecFuelBalancerCoMTarget = vecCom - vecPartLocation;
                //print("vecFuelBalancerCoMTarget: " + this.vecFuelBalancerCoMTarget + "rotationInEditor: " + this.rotationInEditor);

                // Set up the marker if we have not already done this.
                if (null == SavedCoMMarker)
                {
                    //print("Setting up the CoM marker - this should have happened on Startup!");
                    CreateSavedComMarker();
                }

                _osd.Success("The CoM has been set");

                // TODO remove - Diagnostics
                {
                    //print("EditorLogic.VesselRotation : " + EditorLogic.VesselRotation);
                }
            }
            //print("Setting the targetCoM location for fuel balancing.");
        }
コード例 #5
0
        private bool SetCoMTarget()
        {
            if (part == null || part.transform == null)
            {
                return(false);
            }

            // if (HighLogic.LoadedSceneIsEditor)
            {
                Log.Info("Part position: " + part.transform.position);
                Vector3 vecPartLocation = part.transform.position;
                Vector3 vecCom;
                if (HighLogic.LoadedSceneIsEditor)
                {
                    vecCom = EditorMarker_CoM.findCenterOfMass(EditorLogic.RootPart);
                }
                else
                {
                    var b = vessel.CoM - part.transform.position;
                    vecCom = Quaternion.Inverse(part.transform.rotation * Quaternion.Inverse(RotationInEditor)) * b;
                    VecFuelBalancerCoMTarget = vecCom;

                    return(true);
                }

                // What really interests us is the location of the CoM relative to the part that is the balancer
                VecFuelBalancerCoMTarget = vecCom - vecPartLocation;
            }
            // Set up the marker if we have not already done this.
            if (null == SavedCoMMarker)
            {
                //Log.Info("Setting up the CoM marker - this should have happened on Startup!");
                CreateMarkers("SetCoMTarget, part: " + part.partInfo.title);
            }
            //RotationInEditor = tmpRotation;
            return(true);
        }
コード例 #6
0
ファイル: GraphWindow.cs プロジェクト: fat-lobyte/CorrectCoL
        static void calculate_moments()
        {
            double.TryParse(alt_str, out altitude);
            float.TryParse(speed_str, out speed);
            //float.TryParse(pitch_ctrl_str, out pitch_ctrl);
            //pitch_ctrl = Mathf.Max(-1.0f, Mathf.Min(1.0f, pitch_ctrl));
            //EditorLogic.RootPart.vessel.ctrlState.pitch = pitch_ctrl;

            // update CoM
            CoM = EditorMarker_CoM.findCenterOfMass(EditorLogic.RootPart);

            // wet cycles
            for (int i = 0; i < AoA_net.Count; i++)
            {
                float   aoa        = AoA_net[i];
                float   lift       = 0.0f;
                float   drag       = 0.0f;
                Vector3 sum_torque = get_torque_aoa(aoa, ref lift, ref drag);
                wet_lift[i] = lift;
                wet_drag[i] = drag;
                if (drag != 0.0f)
                {
                    LtD[i] = lift / drag;
                }
                else
                {
                    LtD[i] = 0.0f;
                }
                wet_torques_aoa[i] = Vector3.Dot(sum_torque, EditorLogic.RootPart.partTransform.right);
            }

            for (int i = 0; i < AoA_net.Count; i++)
            {
                float   aoa        = AoA_net[i];
                Vector3 sum_torque = get_torque_sideslip(aoa);
                wet_torques_sideslip[i] = Vector3.Dot(sum_torque, EditorLogic.RootPart.partTransform.forward);
            }

            // dry the ship by choosing dry CoM
            float smass = 0.0f;

            wet_mass = 0.0f;
            CoM      = dry_CoM_recurs(EditorLogic.RootPart, ref smass, ref wet_mass);
            CoM      = CoM / smass;

            // dry cycles
            for (int i = 0; i < AoA_net.Count; i++)
            {
                float   aoa        = AoA_net[i];
                float   lift       = 0.0f;
                float   drag       = 0.0f;
                Vector3 sum_torque = get_torque_aoa(aoa, ref lift, ref drag);
                dry_torques_aoa[i] = Vector3.Dot(sum_torque, EditorLogic.RootPart.partTransform.right);
            }

            for (int i = 0; i < AoA_net.Count; i++)
            {
                float   aoa        = AoA_net[i];
                Vector3 sum_torque = get_torque_sideslip(aoa);
                dry_torques_sideslip[i] = Vector3.Dot(sum_torque, EditorLogic.RootPart.partTransform.forward);
            }
        }