public ThrustInfo updateThrust() { ThrustInfo ti = new ThrustInfo(); ti.cotAll = Vector3.zero; ti.dotOther = Vector3.zero; ti.dotAligned = Vector3.zero; ti.thrustOther = 0; ti.thrustAligned = 0; foreach (Part p in vessel.Parts) { Vector3 coT = Vector3.zero; Vector3 doT = Vector3.zero; float thrust = 0; Vector3 thurstForward = Vector3.zero; ModuleEngines engine = p.Modules.OfType <ModuleEngines>().FirstOrDefault(); ModuleEnginesFX enginefx = p.Modules.OfType <ModuleEnginesFX>().Where(e => e.isEnabled).FirstOrDefault(); if (enginefx != null || engine != null) { List <Transform> thrustTransforms; ModuleGimbal gimbal = p.Modules.OfType <ModuleGimbal>().FirstOrDefault(); if (engine != null) { thrustTransforms = engine.thrustTransforms; } else // ModuleEnginesFX { thrustTransforms = enginefx.thrustTransforms; } List <Vector3> forwards; if (gimbal != null) { List <Quaternion> initRots = gimbal.initRots; forwards = new List <Vector3>(initRots.Count); for (int i = 0; i < initRots.Count; i++) { Transform tt = thrustTransforms[i]; Quaternion ori = tt.localRotation; tt.localRotation = (gimbal is ModuleGimbalAutoTrim) ? (gimbal as ModuleGimbalAutoTrim).initalRots[i] : initRots[i]; forwards.Add(tt.forward); tt.localRotation = ori; } } else { forwards = new List <Vector3>(thrustTransforms.Count); foreach (Transform thrustTransform in thrustTransforms) { forwards.Add(thrustTransform.forward); } } for (int i = 0; i < thrustTransforms.Count; i++) { foreach (Transform thrustTransform in thrustTransforms) { coT = coT + (thrustTransforms[i].position - p.transform.position); doT = doT + forwards[i]; } } coT = (coT / (float)thrustTransforms.Count) + p.transform.position; doT = doT / (float)thrustTransforms.Count; thrust = (engine != null) ? engine.finalThrust : enginefx.finalThrust; if (gimbal != null && (gimbal is ModuleGimbalAutoTrim) && (gimbal as ModuleGimbalAutoTrim).gimbalAutoTrim) { ti.dotAligned += doT * thrust; ti.thrustAligned += thrust; } else { ti.dotOther += doT * thrust; ti.thrustOther += thrust; } ti.cotAll += coT * thrust; } } ti.cotAll = ti.cotAll / (ti.thrustOther + ti.thrustAligned); ti.com = this.vessel.findWorldCenterOfMass(); return(ti); }
public ThrustInfo updateThrust() { ThrustInfo ti = new ThrustInfo(); ti.cotAll = Vector3.zero; ti.dotOther = Vector3.zero; ti.dotAligned = Vector3.zero; ti.thrustOther = 0; ti.thrustAligned = 0; foreach (Part p in vessel.Parts) { Vector3 coT = Vector3.zero; Vector3 doT = Vector3.zero; float thrust = 0; Vector3 thurstForward = Vector3.zero; ModuleEngines engine = p.Modules.OfType<ModuleEngines>().FirstOrDefault(); ModuleEnginesFX enginefx = p.Modules.OfType<ModuleEnginesFX>().Where(e => e.isEnabled).FirstOrDefault(); if (enginefx != null || engine != null) { List<Transform> thrustTransforms; ModuleGimbal gimbal = p.Modules.OfType<ModuleGimbal>().FirstOrDefault(); if (engine != null) thrustTransforms = engine.thrustTransforms; else // ModuleEnginesFX thrustTransforms = enginefx.thrustTransforms; List<Vector3> forwards; if (gimbal != null) { List<Quaternion> initRots = gimbal.initRots; forwards = new List<Vector3>(initRots.Count); for (int i = 0; i < initRots.Count; i++) { Transform tt = thrustTransforms[i]; Quaternion ori = tt.localRotation; tt.localRotation = (gimbal is ModuleGimbalAutoTrim) ? (gimbal as ModuleGimbalAutoTrim).initalRots[i] : initRots[i]; forwards.Add(tt.forward); tt.localRotation = ori; } } else { forwards = new List<Vector3>(thrustTransforms.Count); foreach (Transform thrustTransform in thrustTransforms) forwards.Add(thrustTransform.forward); } for (int i = 0; i < thrustTransforms.Count; i++) foreach (Transform thrustTransform in thrustTransforms) { coT = coT + (thrustTransforms[i].position - p.transform.position); doT = doT + forwards[i]; } coT = (coT / (float)thrustTransforms.Count) + p.transform.position; doT = doT / (float)thrustTransforms.Count; thrust = (engine != null) ? engine.finalThrust : enginefx.finalThrust; if (gimbal != null && (gimbal is ModuleGimbalAutoTrim) && (gimbal as ModuleGimbalAutoTrim).gimbalAutoTrim) { ti.dotAligned += doT * thrust; ti.thrustAligned += thrust; } else { ti.dotOther += doT * thrust; ti.thrustOther += thrust; } ti.cotAll += coT * thrust; } } ti.cotAll = ti.cotAll / (ti.thrustOther + ti.thrustAligned); ti.com = this.vessel.findWorldCenterOfMass(); return ti; }