本文整理汇总了C#中Vessel.findLocalCenterOfMass方法的典型用法代码示例。如果您正苦于以下问题:C# Vessel.findLocalCenterOfMass方法的具体用法?C# Vessel.findLocalCenterOfMass怎么用?C# Vessel.findLocalCenterOfMass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vessel
的用法示例。
在下文中一共展示了Vessel.findLocalCenterOfMass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVesselWorldCoM
public Vector3 GetVesselWorldCoM (Vessel v)
{
var com = v.findLocalCenterOfMass ();
return v.rootPart.partTransform.TransformPoint (com);
}
示例2: GetTorque
/// <summary>
/// Returns the torque the ship can exert around its center of mass
/// </summary>
/// <returns>The torque in N m, around the (pitch, roll, yaw) axes.</returns>
/// <param name="vessel">The ship whose torque should be measured.</param>
/// <param name="thrust">The ship's throttle setting, on a scale of 0 to 1.</param>
public static Vector3d GetTorque(Vessel vessel, float thrust)
{
// Do everything in vessel coordinates
var centerOfMass = vessel.findLocalCenterOfMass();
// Don't assume any particular symmetry for the vessel
double pitch = 0, roll = 0, yaw = 0;
foreach (Part part in vessel.parts)
{
foreach (PartModule module in part.Modules)
{
if (!module.isEnabled)
continue;
var reactionWheelModule = module as ModuleReactionWheel;
var rcsModule = module as ModuleRCS;
if (reactionWheelModule != null && reactionWheelModule.wheelState == ModuleReactionWheel.WheelState.Active)
{
pitch += reactionWheelModule.PitchTorque;
roll += reactionWheelModule.RollTorque;
yaw += reactionWheelModule.YawTorque;
}
// Is there a more direct way to see if RCS is enabled? module.isEnabled doesn't work...
else if (rcsModule != null && vessel.ActionGroups[KSPActionGroup.RCS])
{
var vesselTransform = vessel.GetTransform();
foreach (Transform thruster in rcsModule.thrusterTransforms)
{
// Avoids problems with part.Rigidbody.centerOfMass; should also give better
// support for RCS units integrated into larger parts
Vector3d thrusterOffset = vesselTransform.InverseTransformPoint(thruster.position) - centerOfMass;
/* Code by sarbian, shamelessly copied from MechJeb */
Vector3d thrusterThrust = vesselTransform.InverseTransformDirection(-thruster.up.normalized) * rcsModule.thrusterPower;
Vector3d thrusterTorque = Vector3.Cross(thrusterOffset, thrusterThrust);
/* end sarbian's code */
// This overestimates the usable torque, but that doesn't change the final behavior much
pitch += (float)Math.Abs(thrusterTorque.x);
roll += (float)Math.Abs(thrusterTorque.y);
yaw += (float)Math.Abs(thrusterTorque.z);
}
}
}
Vector3d gimbal = GetThrustTorque(part, vessel) * thrust;
pitch += gimbal.x;
roll += gimbal.y;
yaw += gimbal.z;
}
return new Vector3d(pitch, roll, yaw);
}
示例3: StoredVessel
public StoredVessel(Vessel vsl)
{
vessel = vsl.BackupVessel();
metric = new Metric(vsl);
id = vessel.vesselID;
CoM = vsl.findLocalCenterOfMass();
crew = vsl.GetVesselCrew();
resources = new VesselResources<ProtoVessel, ProtoPartSnapshot, ProtoPartResourceSnapshot>(vessel);
// fixTripLogger(); //FIXME
}