本文整理汇总了C#中Vessel.findWorldCenterOfMass方法的典型用法代码示例。如果您正苦于以下问题:C# Vessel.findWorldCenterOfMass方法的具体用法?C# Vessel.findWorldCenterOfMass怎么用?C# Vessel.findWorldCenterOfMass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vessel
的用法示例。
在下文中一共展示了Vessel.findWorldCenterOfMass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunCalculations
public void RunCalculations(
Vessel vessel,
Quaternion gymbal)
{
ManeuverPresent = false;
// Calculations thanks to Mechjeb
Vector3d CoM = vessel.findWorldCenterOfMass();
Vector3d velocityVesselOrbit = vessel.orbit.GetVel();
Vector3d velocityVesselOrbitUnit = velocityVesselOrbit.normalized;
Vector3d velocityVesselSurface = velocityVesselOrbit - vessel.mainBody.getRFrmVel(CoM);
Vector3d velocityVesselSurfaceUnit = velocityVesselSurface.normalized;
ProgradeOrbit = gymbal * velocityVesselOrbitUnit;
ProgradeSurface = gymbal * velocityVesselSurfaceUnit;
PatchedConicSolver patchedConicSolver = vessel.patchedConicSolver;
if (patchedConicSolver == null)
return;
if (patchedConicSolver.maneuverNodes == null)
return;
if (patchedConicSolver.maneuverNodes.Count > 0)
{
var manuever = patchedConicSolver.maneuverNodes[0];
ManeuverApplied = manuever.DeltaV != Vector3d.zero;
Vector3d burnVector = manuever.GetBurnVector(vessel.orbit);
ManeuverPlus = gymbal * burnVector.normalized;
ManeuverPresent = true;
}
}
示例2: RunCalculations
public void RunCalculations(
Vessel vessel,
Quaternion gymbal)
{
// Calculations thanks to Mechjeb
Vector3d CoM = vessel.findWorldCenterOfMass();
Vector3d up = (CoM - vessel.mainBody.position).normalized;
Vector3d velocityVesselOrbit = vessel.orbit.GetVel();
Vector3d velocityVesselOrbitUnit = velocityVesselOrbit.normalized;
Vector3d radialPlus = Vector3d.Exclude(velocityVesselOrbit, up).normalized;
Vector3d velocityVesselSurface = velocityVesselOrbit - vessel.mainBody.getRFrmVel(CoM);
Vector3d velocityVesselSurfaceUnit = velocityVesselSurface.normalized;
RadialPlus = gymbal * radialPlus;
NormalPlus = gymbal * -Vector3d.Cross(radialPlus, velocityVesselOrbitUnit);
ProgradeOrbit = gymbal * velocityVesselOrbitUnit;
ProgradeSurface = gymbal * velocityVesselSurfaceUnit;
if (vessel.patchedConicSolver.maneuverNodes.Count > 0)
{
Vector3d burnVector = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(vessel.orbit);
ManeuverPlus = gymbal * burnVector.normalized;
ManeuverPresent = true;
}
else
{
ManeuverPresent = false;
}
}
示例3: List
public void List(Vessel around, float maxRange)
{
vessels.Clear();
distances.Clear();
Vector3 p = Vector3.zero, p1 = Vector3.zero;
try
{
p = around.findWorldCenterOfMass();
}
catch
{
// Debug.Log( "NearestVessels: findWorldCenterOfMass failed for vessel "
// + around.vesselName );
return;
}
maxRange *= maxRange;
foreach (Vessel v in FlightGlobals.Vessels)
{
if (v == around)
continue;
try
{
p1 = v.findWorldCenterOfMass();
}
catch
{
// Sometimes debris become 'invisible' for an unknown reason.
// findWorldCenterOfMass then fails horribly.
// Debug.Log( "NearestVessels: findWorldCenterOfMass failed for vessel "
// + v.vesselName );
continue;
}
float d = (p1 - p).sqrMagnitude;
if (d > maxRange)
continue;
bool added = false;
for (int i = 0; i < distances.Count; i++)
if (d < distances[i])
{
distances.Insert(i, d);
vessels.Insert(i, v);
added = true;
break;
}
if (!added)
{
distances.Add(d);
vessels.Add(v);
}
}
}
示例4: TransferDeltaV
public static double TransferDeltaV(CelestialBody target, Vessel vessel)
{
double radius = target.referenceBody.Radius;
double u = target.referenceBody.gravParameter;
//double d_alt = Altitude_of_Target(target, 0);
double d_alt = 12000000;
double alt = (vessel.mainBody.GetAltitude (vessel.findWorldCenterOfMass ())) + radius;
double v = Math.Sqrt (u / alt) * (Math.Sqrt ((2 * d_alt) / (alt + d_alt)) - 1);
return Math.Abs ((Math.Sqrt (u / alt) + v) - vessel.orbit.GetVel ().magnitude);
}
示例5: PhaseAngleAtTransfer
//phase angle when transfer should start
public static double PhaseAngleAtTransfer(CelestialBody target, Vessel vessel)
{
double target_alt = AltitudeOfTarget (target, Planetarium.GetUniversalTime ());
double origin_alt = vessel.mainBody.GetAltitude (vessel.findWorldCenterOfMass ());
double u = target.referenceBody.gravParameter;
double th = Math.PI * Math.Sqrt (Math.Pow (origin_alt + target_alt, 3) / (8 * u));
double phase = (180 - Math.Sqrt (u / target_alt) * (th / target_alt) * (180 / Math.PI));
while (phase < 0)
phase += 360;
return phase % 360;
}
示例6: updateHeadingPitchRollField
//Borrowed from MechJeb2 & Telemachus
public static Quaternion updateHeadingPitchRollField(Vessel v)
{
Vector3d CoM, north, up;
Quaternion rotationSurface;
CoM = v.findWorldCenterOfMass();
up = (CoM - v.mainBody.position).normalized;
north = Vector3d.Exclude(up, (v.mainBody.position + v.mainBody.transform.up * (float)v.mainBody.Radius) - CoM).normalized;
rotationSurface = Quaternion.LookRotation(north, up);
return Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(v.GetTransform().rotation) * rotationSurface);
}
示例7: GetTorque
public static Vector3d GetTorque(Vessel vessel, float thrust)
{
var centerOfMass = vessel.findWorldCenterOfMass();
var rollaxis = vessel.transform.up;
rollaxis.Normalize ();
var pitchaxis = vessel.GetFwdVector ();
pitchaxis.Normalize ();
float pitch = 0.0f;
float yaw = 0.0f;
float roll = 0.0f;
foreach (Part part in vessel.parts)
{
var relCoM = part.Rigidbody.worldCenterOfMass - centerOfMass;
foreach (PartModule module in part.Modules)
{
var wheel = module as ModuleReactionWheel;
if (wheel == null) continue;
pitch += wheel.PitchTorque;
yaw += wheel.YawTorque;
roll += wheel.RollTorque;
}
if (vessel.ActionGroups [KSPActionGroup.RCS])
{
foreach (PartModule module in part.Modules) {
var rcs = module as ModuleRCS;
if (rcs == null || !rcs.rcsEnabled) continue;
bool enoughfuel = rcs.propellants.All(p => (int) (p.totalResourceAvailable) != 0);
if (!enoughfuel) continue;
foreach (Transform thrustdir in rcs.thrusterTransforms)
{
float rcsthrust = rcs.thrusterPower;
//just counting positive contributions in one direction. This is incorrect for asymmetric thruster placements.
roll += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(relCoM, thrustdir.up), rollaxis), 0.0f);
pitch += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(Vector3.Cross(relCoM, thrustdir.up), rollaxis), pitchaxis), 0.0f);
yaw += Mathf.Max(rcsthrust * Vector3.Dot(Vector3.Cross(Vector3.Cross(relCoM, thrustdir.up), rollaxis), Vector3.Cross(rollaxis,pitchaxis)),0.0f);
}
}
}
pitch += (float)GetThrustTorque(part, vessel) * thrust;
yaw += (float)GetThrustTorque (part, vessel) * thrust;
}
return new Vector3d(pitch, roll, yaw);
}
示例8: GetTrueAltitude
/// <summary>
/// Get true altitude above terrain (from MuMech lib)
/// Also from: http://kerbalspaceprogram.com/forum/index.php?topic=10324.msg161923#msg161923
/// </summary>
public static double GetTrueAltitude(Vessel vessel)
{
Vector3 CoM = vessel.findWorldCenterOfMass();
Vector3 up = (CoM - vessel.mainBody.position).normalized;
double altitudeASL = vessel.mainBody.GetAltitude(CoM);
double altitudeTrue = 0.0;
RaycastHit sfc;
if (Physics.Raycast(CoM, -up, out sfc, (float)altitudeASL + 10000.0F, 1 << 15))
altitudeTrue = sfc.distance;
else if (vessel.mainBody.pqsController != null)
altitudeTrue = vessel.mainBody.GetAltitude(CoM) - (vessel.mainBody.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis(vessel.mainBody.GetLongitude(CoM), Vector3d.down) * QuaternionD.AngleAxis(vessel.mainBody.GetLatitude(CoM), Vector3d.forward) * Vector3d.right) - vessel.mainBody.pqsController.radius);
else
altitudeTrue = vessel.mainBody.GetAltitude(CoM);
return altitudeTrue;
}
示例9: GetEffectiveInertia
public static Vector3d GetEffectiveInertia(Vessel vessel, Vector3d torque)
{
var CoM = vessel.findWorldCenterOfMass();
var MoI = vessel.findLocalMOI(CoM);
var angularVelocity = Quaternion.Inverse(vessel.transform.rotation) * vessel.rigidbody.angularVelocity;
var angularMomentum = new Vector3d(angularVelocity.x * MoI.x, angularVelocity.y * MoI.y, angularVelocity.z * MoI.z);
var retVar = Vector3d.Scale
(
Sign(angularMomentum) * 2.0f,
Vector3d.Scale(Pow(angularMomentum, 2), Inverse(Vector3d.Scale(torque, MoI)))
);
retVar.y *= 10;
return retVar;
}
示例10: GetEffectiveInertia
public static Vector3d GetEffectiveInertia(Vessel vessel, Vector3d torque)
{
var centerOfMass = vessel.findWorldCenterOfMass();
var momentOfInertia = vessel.findLocalMOI(centerOfMass);
var angularVelocity = Quaternion.Inverse(vessel.ReferenceTransform.rotation) * vessel.rigidbody.angularVelocity;
var angularMomentum = new Vector3d(angularVelocity.x * momentOfInertia.x, angularVelocity.y * momentOfInertia.y, angularVelocity.z * momentOfInertia.z);
var retVar = Vector3d.Scale
(
Sign(angularMomentum) * 2.0f,
Vector3d.Scale(Pow(angularMomentum, 2), Inverse(Vector3d.Scale(torque, momentOfInertia)))
);
retVar.y *= 10;
return retVar;
}
示例11: GetTorque
public static Vector3d GetTorque(Vessel vessel, float thrust)
{
var CoM = vessel.findWorldCenterOfMass();
float pitchYaw = 0;
float roll = 0;
foreach (Part part in vessel.parts)
{
var relCoM = part.Rigidbody.worldCenterOfMass - CoM;
if (part is CommandPod)
{
pitchYaw += Math.Abs(((CommandPod)part).rotPower);
roll += Math.Abs(((CommandPod)part).rotPower);
}
if (part is RCSModule)
{
float max = 0;
foreach (float power in ((RCSModule)part).thrusterPowers)
{
max = Mathf.Max(max, power);
}
pitchYaw += max * relCoM.magnitude;
}
foreach (PartModule module in part.Modules)
{
if (module is ModuleReactionWheel)
{
pitchYaw += ((ModuleReactionWheel)module).PitchTorque;
roll += ((ModuleReactionWheel)module).RollTorque;
}
}
pitchYaw += (float)GetThrustTorque(part, vessel) * thrust;
}
return new Vector3d(pitchYaw, roll, pitchYaw);
}
示例12: getSrfRotation
//credits to r4m0n -- modified
private Quaternion getSrfRotation(Vessel vessel)
{
Vector3d CoM;
Vector3d MoI;
Vector3d up;
Quaternion rotationSurface;
Quaternion rotationVesselSurface;
CoM = vessel.findWorldCenterOfMass();
MoI = vessel.findLocalMOI(CoM);
up = (CoM - vessel.mainBody.position).normalized;
// Vector3d north = Vector3.Exclude(up, (vessel.mainBody.position + vessel.mainBody.transform.up * (float)vessel.mainBody.Radius) - CoM).normalized;
Vector3d north = Vector3.ProjectOnPlane((vessel.mainBody.position + vessel.mainBody.transform.up * (float)vessel.mainBody.Radius) - CoM, up).normalized;
rotationSurface = Quaternion.LookRotation(north, up);
rotationVesselSurface = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vessel.transform.rotation) * rotationSurface);
//y = heading, x = pitch in degrees
return rotationVesselSurface;
}
示例13: GetTorque
public static Vector3d GetTorque(Vessel vessel, float thrust)
{
var centerOfMass = vessel.findWorldCenterOfMass();
float pitchYaw = 0;
float roll = 0;
foreach (Part part in vessel.parts)
{
var relCoM = part.Rigidbody.worldCenterOfMass - centerOfMass;
var pod = part as CommandPod;
if (pod != null)
{
pitchYaw += Math.Abs(pod.rotPower);
roll += Math.Abs(pod.rotPower);
}
var rcsModule = part as RCSModule;
if (rcsModule != null)
{
float max = rcsModule.thrusterPowers.Aggregate<float, float>(0, Mathf.Max);
pitchYaw += max * relCoM.magnitude;
}
foreach (PartModule module in part.Modules)
{
var wheel = module as ModuleReactionWheel;
if (wheel == null) continue;
pitchYaw += wheel.PitchTorque;
roll += wheel.RollTorque;
}
pitchYaw += (float)GetThrustTorque(part, vessel) * thrust;
}
return new Vector3d(pitchYaw, roll, pitchYaw);
}
示例14: GetTerminalVelocity
public static double GetTerminalVelocity(Vessel vessel)
{
if(vessel.mainBody.GetAltitude(vessel.findWorldCenterOfMass()) > RealMaxAtmosphereAltitude(vessel.mainBody)) return double.PositiveInfinity;
double DensityOfAir = FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(vessel.findWorldCenterOfMass(), vessel.mainBody));
return Math.Sqrt(2 * (double)FlightGlobals.getGeeForceAtPosition(vessel.findWorldCenterOfMass()).magnitude * vessel.GetTotalMass() / ( GetMassDrag(vessel) * FlightGlobals.DragMultiplier * DensityOfAir ));
}
示例15: OnVesselGoOffRails
private void OnVesselGoOffRails(Vessel vessel)
{
if (vessel.situation != Vessel.Situations.LANDED || vessel.situation != Vessel.Situations.SPLASHED)
{
if (vessel.ActionGroups[KSPActionGroup.SAS] && vessel.IsControllable) //vessel.Autopilot.Enabled does not work at this point!
{
//Reset locked heading
vessel.Autopilot.SAS.lockedHeading = vessel.ReferenceTransform.rotation;
//Set relative rotation if there is a reference
if (data.reference[vessel.id.ToString()] != null)
{
vessel.SetRotation(Quaternion.FromToRotation(data.direction[vessel.id.ToString()], data.reference[vessel.id.ToString()].GetTransform().position - vessel.transform.position) * data.rotation[vessel.id.ToString()]);
}
}
else
{
Vector3 av = data.momentum[vessel.id.ToString()];
Vector3 COM = vessel.findWorldCenterOfMass();
Quaternion rotation;
rotation = vessel.ReferenceTransform.rotation;
//Applying force on every part
foreach (Part p in vessel.parts)
{
try
{
if (p.rigidbody == null) continue;
p.rigidbody.AddTorque(rotation * av, ForceMode.VelocityChange);
p.rigidbody.AddForce(Vector3.Cross(rotation * av, (p.rigidbody.position - COM)), ForceMode.VelocityChange);
}
catch (NullReferenceException nre)
{
Debug.Log("[PR] NullReferenceException in OnVesselGoOffRails: " + nre.Message);
}
}
}
}
}