本文整理汇总了C#中Vessel.findLocalMOI方法的典型用法代码示例。如果您正苦于以下问题:C# Vessel.findLocalMOI方法的具体用法?C# Vessel.findLocalMOI怎么用?C# Vessel.findLocalMOI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vessel
的用法示例。
在下文中一共展示了Vessel.findLocalMOI方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: SteerShipToward
public static void SteerShipToward(Direction targetDir, FlightCtrlState c, Vessel vessel)
{
// I take no credit for this, this is a stripped down, rearranged version of MechJeb's attitude control system
var CoM = vessel.findWorldCenterOfMass();
var MoI = vessel.findLocalMOI(CoM);
var mass = vessel.GetTotalMass();
var up = (CoM - vessel.mainBody.position).normalized;
var target = targetDir.Rotation;
var vesselR = vessel.transform.rotation;
// some validations
if (!Utils.IsValidNumber(c.mainThrottle) ||
!Utils.IsValidVector(CoM) ||
!Utils.IsValidNumber(mass) ||
!Utils.IsValidVector(up) ||
!Utils.IsValidRotation(target) ||
!Utils.IsValidRotation(vesselR))
{
return;
}
Quaternion delta;
delta = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vesselR) * target);
Vector3d deltaEuler = ReduceAngles(delta.eulerAngles);
deltaEuler.y *= -1;
Vector3d torque = GetTorque(vessel, c.mainThrottle);
Vector3d inertia = GetEffectiveInertia(vessel, torque);
Vector3d err = deltaEuler * Math.PI / 180.0F;
err += new Vector3d(inertia.x, inertia.z, inertia.y);
//err.Scale(SwapYZ(Vector3d.Scale(MoI, Inverse(torque))));
prev_err = err;
Vector3d act = 120.0f * err;
float precision = Mathf.Clamp((float)torque.x * 20f / MoI.magnitude, 0.5f, 10f);
float drive_limit = Mathf.Clamp01((float)(err.magnitude * 380.0f / precision));
act.x = Mathf.Clamp((float)act.x, -drive_limit, drive_limit);
act.y = Mathf.Clamp((float)act.y, -drive_limit, drive_limit);
act.z = Mathf.Clamp((float)act.z, -drive_limit, drive_limit);
//act = averageVector3d(averagedAct, act, 2);
c.roll = Mathf.Clamp((float)(c.roll + act.z), -drive_limit, drive_limit);
c.pitch = Mathf.Clamp((float)(c.pitch + act.x), -drive_limit, drive_limit);
c.yaw = Mathf.Clamp((float)(c.yaw + act.y), -drive_limit, drive_limit);
/*
// This revised version from 0.6 gave people problems with gravity turns. I've reverted but may try to make it work
var CoM = vessel.findWorldCenterOfMass();
var MoI = vessel.findLocalMOI(CoM);
var mass = vessel.GetTotalMass();
var up = (CoM - vessel.mainBody.position).normalized;
var target = targetDir.Rotation;
var vesselR = vessel.transform.rotation;
Quaternion delta;
delta = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vesselR) * target);
Vector3d deltaEuler = ReduceAngles(delta.eulerAngles);
deltaEuler.y *= -1;
Vector3d torque = GetTorque(vessel, c.mainThrottle);
Vector3d inertia = GetEffectiveInertia(vessel, torque);
Vector3d err = deltaEuler * Math.PI / 180.0F;
err += SwapYZ(inertia * 8);
err.Scale(SwapYZ(Vector3d.Scale(MoI * 3, Inverse(torque))));
prev_err = err;
Vector3d act = 400.0f * err;
float precision = Mathf.Clamp((float)torque.x * 20f / MoI.magnitude, 0.5f, 10f);
float drive_limit = Mathf.Clamp01((float)(err.magnitude * 450.0f / precision));
act.x = Mathf.Clamp((float)act.x, -drive_limit, drive_limit);
act.y = Mathf.Clamp((float)act.y, -drive_limit, drive_limit);
act.z = Mathf.Clamp((float)act.z, -drive_limit, drive_limit);
//act = averageVector3d(averagedAct, act, 2);
c.roll = Mathf.Clamp((float)(c.roll + act.z), -drive_limit, drive_limit);
c.pitch = Mathf.Clamp((float)(c.pitch + act.x), -drive_limit, drive_limit);
c.yaw = Mathf.Clamp((float)(c.yaw + act.y), -drive_limit, drive_limit);*/
}
示例5: SteerShipToward
public static void SteerShipToward(Direction targetDir, FlightCtrlState c, Vessel vessel)
{
// I take no credit for this, this is a stripped down, rearranged version of MechJeb's attitude control system
var centerOfMass = vessel.findWorldCenterOfMass();
var moi = vessel.findLocalMOI(centerOfMass);
var target = targetDir.Rotation;
var vesselR = vessel.transform.rotation;
Quaternion delta = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vesselR) * target);
Vector3d deltaEuler = ReduceAngles(delta.eulerAngles);
deltaEuler.y *= -1;
Vector3d torque = GetTorque(vessel, c.mainThrottle);
Vector3d inertia = GetEffectiveInertia(vessel, torque);
Vector3d err = deltaEuler * Math.PI / 180.0F;
err += new Vector3d(inertia.x, inertia.z, inertia.y);
Vector3d act = 120.0f * err;
float precision = Mathf.Clamp((float)torque.x * 20f / moi.magnitude, 0.5f, 10f);
float driveLimit = Mathf.Clamp01((float)(err.magnitude * 380.0f / precision));
act.x = Mathf.Clamp((float)act.x, -driveLimit, driveLimit);
act.y = Mathf.Clamp((float)act.y, -driveLimit, driveLimit);
act.z = Mathf.Clamp((float)act.z, -driveLimit, driveLimit);
c.roll = Mathf.Clamp((float)(c.roll + act.z), -driveLimit, driveLimit);
c.pitch = Mathf.Clamp((float)(c.pitch + act.x), -driveLimit, driveLimit);
c.yaw = Mathf.Clamp((float)(c.yaw + act.y), -driveLimit, driveLimit);
}
示例6: Update
public void Update(Vessel vessel)
{
if (vessel.rigidbody == null) return; //if we try to update before rigidbodies exist we spam the console with NullPointerExceptions.
//if (vessel.packed) return;
time = Planetarium.GetUniversalTime();
deltaT = TimeWarp.fixedDeltaTime;
CoM = vessel.findWorldCenterOfMass();
MoI = vessel.findLocalMOI(CoM);
up = (CoM - vessel.mainBody.position).normalized;
Rigidbody rigidBody = vessel.rootPart.rigidbody;
if (rigidBody != null) rootPartPos = rigidBody.position;
north = Vector3d.Exclude(up, (vessel.mainBody.position + vessel.mainBody.transform.up * (float)vessel.mainBody.Radius) - CoM).normalized;
east = vessel.mainBody.getRFrmVel(CoM).normalized;
forward = vessel.GetTransform().up;
rotationSurface = Quaternion.LookRotation(north, up);
rotationVesselSurface = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vessel.GetTransform().rotation) * rotationSurface);
velocityVesselOrbit = vessel.orbit.GetVel();
velocityVesselOrbitUnit = velocityVesselOrbit.normalized;
velocityVesselSurface = velocityVesselOrbit - vessel.mainBody.getRFrmVel(CoM);
velocityVesselSurfaceUnit = velocityVesselSurface.normalized;
velocityMainBodySurface = rotationSurface * velocityVesselSurface;
horizontalOrbit = Vector3d.Exclude(up, velocityVesselOrbit).normalized;
horizontalSurface = Vector3d.Exclude(up, velocityVesselSurface).normalized;
angularVelocity = Quaternion.Inverse(vessel.GetTransform().rotation) * vessel.rigidbody.angularVelocity;
radialPlusSurface = Vector3d.Exclude(velocityVesselSurface, up).normalized;
radialPlus = Vector3d.Exclude(velocityVesselOrbit, up).normalized;
normalPlusSurface = -Vector3d.Cross(radialPlusSurface, velocityVesselSurfaceUnit);
normalPlus = -Vector3d.Cross(radialPlus, velocityVesselOrbitUnit);
gravityForce = FlightGlobals.getGeeForceAtPosition(CoM);
localg = gravityForce.magnitude;
speedOrbital.value = velocityVesselOrbit.magnitude;
speedSurface.value = velocityVesselSurface.magnitude;
speedVertical.value = Vector3d.Dot(velocityVesselSurface, up);
speedSurfaceHorizontal.value = (velocityVesselSurface - (speedVertical * up)).magnitude;
speedOrbitHorizontal = (velocityVesselOrbit - (speedVertical * up)).magnitude;
vesselHeading.value = rotationVesselSurface.eulerAngles.y;
vesselPitch.value = (rotationVesselSurface.eulerAngles.x > 180) ? (360.0 - rotationVesselSurface.eulerAngles.x) : -rotationVesselSurface.eulerAngles.x;
vesselRoll.value = (rotationVesselSurface.eulerAngles.z > 180) ? (rotationVesselSurface.eulerAngles.z - 360.0) : rotationVesselSurface.eulerAngles.z;
altitudeASL.value = vessel.mainBody.GetAltitude(CoM);
RaycastHit sfc;
if (Physics.Raycast(CoM, -up, out sfc, (float)altitudeASL + 10000.0F, 1 << 15))
{
altitudeTrue.value = sfc.distance;
}
else if (vessel.mainBody.pqsController != null)
{
// from here: http://kerbalspaceprogram.com/forum/index.php?topic=10324.msg161923#msg161923
altitudeTrue.value = 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.value = vessel.mainBody.GetAltitude(CoM);
}
double surfaceAltitudeASL = altitudeASL - altitudeTrue;
altitudeBottom = altitudeTrue;
foreach (Part p in vessel.parts)
{
if (p.collider != null)
{
Vector3d bottomPoint = p.collider.ClosestPointOnBounds(vessel.mainBody.position);
double partBottomAlt = vessel.mainBody.GetAltitude(bottomPoint) - surfaceAltitudeASL;
altitudeBottom = Math.Max(0, Math.Min(altitudeBottom, partBottomAlt));
}
}
double atmosphericPressure = FlightGlobals.getStaticPressure(altitudeASL, vessel.mainBody);
if (atmosphericPressure < vessel.mainBody.atmosphereMultiplier * 1e-6) atmosphericPressure = 0;
atmosphericDensity = FlightGlobals.getAtmDensity(atmosphericPressure);
atmosphericDensityGrams = atmosphericDensity * 1000;
orbitApA.value = vessel.orbit.ApA;
orbitPeA.value = vessel.orbit.PeA;
orbitPeriod.value = vessel.orbit.period;
orbitTimeToAp.value = vessel.orbit.timeToAp;
if (vessel.orbit.eccentricity < 1) orbitTimeToPe.value = vessel.orbit.timeToPe;
else orbitTimeToPe.value = -vessel.orbit.meanAnomaly / (2 * Math.PI / vessel.orbit.period);
orbitLAN.value = vessel.orbit.LAN;
orbitArgumentOfPeriapsis.value = vessel.orbit.argumentOfPeriapsis;
orbitInclination.value = vessel.orbit.inclination;
orbitEccentricity.value = vessel.orbit.eccentricity;
orbitSemiMajorAxis.value = vessel.orbit.semiMajorAxis;
latitude.value = vessel.mainBody.GetLatitude(CoM);
longitude.value = MuUtils.ClampDegrees180(vessel.mainBody.GetLongitude(CoM));
if (vessel.mainBody != Planetarium.fetch.Sun)
{
Vector3d delta = vessel.mainBody.getPositionAtUT(Planetarium.GetUniversalTime() + 1) - vessel.mainBody.getPositionAtUT(Planetarium.GetUniversalTime() - 1);
//.........这里部分代码省略.........
示例7: Update
public void Update(Vessel vessel)
{
time = Planetarium.GetUniversalTime();
deltaT = TimeWarp.fixedDeltaTime;
CoM = vessel.findWorldCenterOfMass();
up = (CoM - vessel.mainBody.position).normalized;
north = Vector3d.Exclude(up, (vessel.mainBody.position + vessel.mainBody.transform.up * (float)vessel.mainBody.Radius) - CoM).normalized;
east = vessel.mainBody.getRFrmVel(CoM).normalized;
forward = vessel.transform.up;
rotationSurface = Quaternion.LookRotation(north, up);
rotationVesselSurface = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vessel.transform.rotation) * rotationSurface);
velocityVesselOrbit = vessel.orbit.GetVel();
velocityVesselOrbitUnit = velocityVesselOrbit.normalized;
velocityVesselSurface = velocityVesselOrbit - vessel.mainBody.getRFrmVel(CoM);
velocityVesselSurfaceUnit = velocityVesselSurface.normalized;
velocityMainBodySurface = rotationSurface * velocityVesselSurface;
angularVelocity = Quaternion.Inverse(vessel.transform.rotation) * vessel.rigidbody.angularVelocity;
upNormalToVelSurface = Vector3d.Exclude(velocityVesselSurfaceUnit, up).normalized;
upNormalToVelOrbit = Vector3d.Exclude(velocityVesselOrbit, up).normalized;
leftSurface = -Vector3d.Cross(upNormalToVelSurface, velocityVesselSurfaceUnit);
leftOrbit = -Vector3d.Cross(upNormalToVelOrbit, velocityVesselOrbitUnit); ;
gravityForce = FlightGlobals.getGeeForceAtPosition(CoM);
localg = gravityForce.magnitude;
speedOrbital.value = velocityVesselOrbit.magnitude;
speedSurface.value = velocityVesselSurface.magnitude;
speedVertical.value = Vector3d.Dot(velocityVesselSurface, up);
speedHorizontal.value = (velocityVesselSurface - (speedVertical * up)).magnitude;
vesselHeading.value = rotationVesselSurface.eulerAngles.y;
vesselPitch.value = (rotationVesselSurface.eulerAngles.x > 180) ? (360.0 - rotationVesselSurface.eulerAngles.x) : -rotationVesselSurface.eulerAngles.x;
vesselRoll.value = (rotationVesselSurface.eulerAngles.z > 180) ? (rotationVesselSurface.eulerAngles.z - 360.0) : rotationVesselSurface.eulerAngles.z;
altitudeASL.value = vessel.mainBody.GetAltitude(CoM);
RaycastHit sfc;
if (Physics.Raycast(CoM, -up, out sfc, (float)altitudeASL + 10000.0F, 1 << 15))
{
altitudeTrue.value = sfc.distance;
}
else
{
// from here: http://kerbalspaceprogram.com/forum/index.php?topic=10324.msg161923#msg161923
altitudeTrue.value = 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);
}
double surfaceAltitudeASL = altitudeASL - altitudeTrue;
altitudeBottom = altitudeTrue;
foreach (Part p in vessel.parts)
{
if (p.collider != null)
{
Vector3d bottomPoint = p.collider.ClosestPointOnBounds(vessel.mainBody.position);
double partBottomAlt = vessel.mainBody.GetAltitude(bottomPoint) - surfaceAltitudeASL;
altitudeBottom = Math.Max(0, Math.Min(altitudeBottom, partBottomAlt));
}
}
atmosphericDensity = FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(altitudeASL, vessel.mainBody));
orbitApA.value = vessel.orbit.ApA;
orbitPeA.value = vessel.orbit.PeA;
orbitPeriod.value = vessel.orbit.period;
orbitTimeToAp.value = vessel.orbit.timeToAp;
if (vessel.orbit.eccentricity < 1) orbitTimeToPe.value = vessel.orbit.timeToPe;
else orbitTimeToPe.value = -vessel.orbit.meanAnomaly / (2 * Math.PI / vessel.orbit.period); //orbit.timeToPe is bugged for ecc > 1 and timewarp > 2x
orbitLAN.value = vessel.orbit.LAN;
orbitArgumentOfPeriapsis.value = vessel.orbit.argumentOfPeriapsis;
orbitInclination.value = vessel.orbit.inclination;
orbitEccentricity.value = vessel.orbit.eccentricity;
orbitSemiMajorAxis.value = vessel.orbit.semiMajorAxis;
latitude.value = vessel.mainBody.GetLatitude(CoM);
longitude.value = ARUtils.clampDegrees(vessel.mainBody.GetLongitude(CoM));
radius = (CoM - vessel.mainBody.position).magnitude;
mass = thrustAvailable = thrustMinimum = massDrag = torqueRAvailable = torquePYAvailable = torqueThrustPYAvailable = 0;
MoI = vessel.findLocalMOI(CoM);
foreach (Part p in vessel.parts)
{
mass += p.mass;
massDrag += p.mass * p.maximum_drag;
MoI += p.Rigidbody.inertiaTensor;
if (((p.State == PartStates.ACTIVE) || ((Staging.CurrentStage > Staging.LastStage) && (p.inverseStage == Staging.LastStage))) && ((p is LiquidEngine) || (p is SolidRocket)))
{
if (p is LiquidEngine)
{
double usableFraction = Vector3d.Dot((p.transform.rotation * ((LiquidEngine)p).thrustVector).normalized, forward);
thrustAvailable += ((LiquidEngine)p).maxThrust * usableFraction;
thrustMinimum += ((LiquidEngine)p).minThrust * usableFraction;
if (((LiquidEngine)p).thrustVectoringCapable)
{
torqueThrustPYAvailable += Math.Sin(Math.Abs(((LiquidEngine)p).gimbalRange) * Math.PI / 180) * ((LiquidEngine)p).maxThrust * (p.Rigidbody.worldCenterOfMass - CoM).magnitude;
}
}
//.........这里部分代码省略.........
示例8: SteerShipToward
public static void SteerShipToward(Direction targetDir, FlightCtrlState c, Vessel vessel)
{
// I take no credit for this, this is a stripped down, rearranged version of MechJeb's attitude control system
var CoM = vessel.findWorldCenterOfMass();
var MoI = vessel.findLocalMOI(CoM);
var mass = vessel.GetTotalMass();
var up = (CoM - vessel.mainBody.position).normalized;
var target = targetDir.Rotation;
var vesselR = vessel.transform.rotation;
Quaternion delta;
delta = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vesselR) * target);
Vector3d deltaEuler = ReduceAngles(delta.eulerAngles);
deltaEuler.y *= -1;
Vector3d torque = GetTorque(vessel, c.mainThrottle);
Vector3d inertia = GetEffectiveInertia(vessel, torque);
Vector3d err = deltaEuler * Math.PI / 180.0F;
err += new Vector3d(inertia.x, inertia.z, inertia.y);
//err.Scale(SwapYZ(Vector3d.Scale(MoI, Inverse(torque))));
prev_err = err;
Vector3d act = 120.0f * err;
float precision = Mathf.Clamp((float)torque.x * 20f / MoI.magnitude, 0.5f, 10f);
float drive_limit = Mathf.Clamp01((float)(err.magnitude * 420.0f / precision));
act.x = Mathf.Clamp((float)act.x, -drive_limit, drive_limit);
act.y = Mathf.Clamp((float)act.y, -drive_limit, drive_limit);
act.z = Mathf.Clamp((float)act.z, -drive_limit, drive_limit);
//act = averageVector3d(averagedAct, act, 2);
c.roll = Mathf.Clamp((float)(c.roll + act.z), -drive_limit, drive_limit);
c.pitch = Mathf.Clamp((float)(c.pitch + act.x), -drive_limit, drive_limit);
c.yaw = Mathf.Clamp((float)(c.yaw + act.y), -drive_limit, drive_limit);
}