public override void OnCenterOfThrustQuery(CenterOfThrustQuery qry) { base.OnCenterOfThrustQuery(qry); if (HighLogic.LoadedSceneIsEditor) { qry.pos = EditorMarker_CoM.findCenterOfMass(EditorLogic.RootPart); } }
private string GetCenterOfMass() { if (EditorLogic.RootPart) { return(EditorMarker_CoM.findCenterOfMass(EditorLogic.RootPart).ToString("F4")); } else { return("No vessel"); } }
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); }
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); } }