public void ApplyForce(FARAeroSection.PartData pd, Vector3 localVel, Vector3 forceVector, Vector3 torqueVector) { double tmp = 0.0005 * Vector3.SqrMagnitude(localVel); double dynamicPressurekPa = tmp * atmDensity; double dragFactor = dynamicPressurekPa * Mathf.Max(PhysicsGlobals.DragCurvePseudoReynolds.Evaluate(atmDensity * Vector3.Magnitude(localVel)), 1.0f); double liftFactor = dynamicPressurekPa; Vector3 localVelNorm = Vector3.Normalize(localVel); Vector3 localForceTemp = Vector3.Dot(localVelNorm, forceVector) * localVelNorm; Vector3 partLocalForce = localForceTemp * (float)dragFactor + (forceVector - localForceTemp) * (float)liftFactor; forceVector = pd.aeroModule.part.transform.TransformDirection(partLocalForce); torqueVector = pd.aeroModule.part.transform.TransformDirection(torqueVector * (float)dynamicPressurekPa); if (float.IsNaN(forceVector.x) || float.IsNaN(torqueVector.x)) { return; } Vector3 centroid = pd.aeroModule.part.transform.TransformPoint(pd.centroidPartSpace - pd.aeroModule.part.CoMOffset); center.AddForce(centroid, forceVector); center.AddTorque(torqueVector); }
private void CalculateTotalAeroForce() { aeroForces.ClearAll(); if (_vessel.dynamicPressurekPa <= 0.00001) { return; } if (_currentAeroModules != null) { for (int i = 0; i < _currentAeroModules.Count; i++) { FARAeroPartModule m = _currentAeroModules[i]; if ((object)m != null) { aeroForces.AddForce(m.transform.position, m.totalWorldSpaceAeroForce); aeroForces.AddTorque(m.worldSpaceTorque); } } } /* * for (int i = 0; i < _LEGACY_currentWingAeroModel.Count; i++) * { * FARWingAerodynamicModel w = _LEGACY_currentWingAeroModel[i]; * if ((object)w == null) * continue; * totalAeroForceVector += w.worldSpaceForce; * aeroForces.AddForce(w.AerodynamicCenter, w.worldSpaceForce); * * totalAeroForceVector += w.worldSpaceForce; * totalAeroTorqueVector += Vector3.Cross(w.AerodynamicCenter - _vessel.CoM, w.worldSpaceForce); * } * * for(int i = 0; i < _vessel.parts.Count; i++) * { * Part p = _vessel.parts[i]; * totalAeroForceVector += -p.dragVectorDir * p.dragScalar; // dragVectorDir is actually the velocity vector direction * } */ }
private void CalculateTotalAeroForce() { aeroForces.ClearAll(); if (_vessel.dynamicPressurekPa <= 0.00001) { return; } if (_currentAeroModules == null) { return; } foreach (FARAeroPartModule m in _currentAeroModules) { if (m is null) { continue; } aeroForces.AddForce(m.transform.position, m.totalWorldSpaceAeroForce); aeroForces.AddTorque(m.worldSpaceTorque); } }