本文整理汇总了C#中Vessel.GetFwdVector方法的典型用法代码示例。如果您正苦于以下问题:C# Vessel.GetFwdVector方法的具体用法?C# Vessel.GetFwdVector怎么用?C# Vessel.GetFwdVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vessel
的用法示例。
在下文中一共展示了Vessel.GetFwdVector方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: GetTorque
//from kOS
public static Vector3d GetTorque(Vessel vessel, float thrust)
{
Vector3 centerOfMass = vessel.CoM;
Vector3 rollaxis = vessel.ReferenceTransform.up;
rollaxis.Normalize ();
Vector3 pitchaxis = vessel.GetFwdVector ();
pitchaxis.Normalize ();
float pitch = 0.0f;
float yaw = 0.0f;
float roll = 0.0f;
//reaction wheel torque
foreach(ModuleReactionWheel wheel in vessel.FindPartModulesImplementing<ModuleReactionWheel>())
{
if (wheel == null) continue;
pitch += wheel.PitchTorque;
yaw += wheel.YawTorque;
roll += wheel.RollTorque;
}
//rcs torque
if (vessel.ActionGroups [KSPActionGroup.RCS])
{
foreach(ModuleRCS rcs in vessel.FindPartModulesImplementing<ModuleRCS>())
{
if (rcs == null || !rcs.rcsEnabled) continue;
Vector3 relCoM = rcs.part.Rigidbody.worldCenterOfMass - centerOfMass;
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);
}
}
}
return new Vector3d(pitch, roll, yaw);
}