本文整理汇总了C#中Vessel.GetWorldPos3D方法的典型用法代码示例。如果您正苦于以下问题:C# Vessel.GetWorldPos3D方法的具体用法?C# Vessel.GetWorldPos3D怎么用?C# Vessel.GetWorldPos3D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vessel
的用法示例。
在下文中一共展示了Vessel.GetWorldPos3D方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckOccult
public static string CheckOccult(Vessel vessel)
{
foreach (CelestialBody bodyC in FlightGlobals.Bodies)
{
if (!bodyDist.ContainsKey(bodyC))
print("Could not find body " + bodyC.bodyName);
if (bodyDist[bodyC] < Vector3d.Distance(FlightGlobals.ship_position, vessel.GetWorldPos3D()) && Vector3d.Angle((vessel.GetWorldPos3D() - FlightGlobals.ship_position).normalized, bodyAngle[bodyC]) < bodySize[bodyC])
return bodyC.name;
}
return "";
}
示例2: HasTransferPath
// Finds if the path between beacons passes too close to a planet or is within its gravity well.
public KeyValuePair<string, CelestialBody> HasTransferPath(Vessel vOrigin, Vessel vDestination, double gLimit)
{
// Cribbed with love from RemoteTech. I have no head for vectors.
var returnPair = new KeyValuePair<string, CelestialBody>("start", vOrigin.mainBody);
Vector3d opos = vOrigin.GetWorldPos3D();
Vector3d dpos = vDestination.GetWorldPos3D();
foreach (CelestialBody rock in FlightGlobals.Bodies)
{
Vector3d bodyFromOrigin = rock.position - opos;
Vector3d destFromOrigin = dpos - opos;
if (Vector3d.Dot(bodyFromOrigin, destFromOrigin) <= 0) continue;
Vector3d destFromOriginNorm = destFromOrigin.normalized;
if (Vector3d.Dot(bodyFromOrigin, destFromOriginNorm) >= destFromOrigin.magnitude) continue;
Vector3d lateralOffset = bodyFromOrigin - Vector3d.Dot(bodyFromOrigin, destFromOriginNorm) * destFromOriginNorm;
double limbo = Math.Sqrt((6.673E-11 * rock.Mass) / gLimit) - rock.Radius; // How low can we go?
string limbotype = "Gravity";
if (limbo < rock.Radius + rock.Radius * 0.25)
{
limbo = rock.Radius + rock.Radius * .025;
limbotype = "Proximity";
}
if (lateralOffset.magnitude < limbo)
{
returnPair = new KeyValuePair<string, CelestialBody>(limbotype, rock);
//print("Lateral Offset was " + lateralOffset.magnitude + "m and needed to be " + limbo + "m, failed due to " + limbotype + " check for " + rock.name + ".");
return returnPair;
}
}
if (FlightGlobals.getGeeForceAtPosition(vDestination.GetWorldPos3D()).magnitude > gLimit) return new KeyValuePair<string, CelestialBody>("Gravity", vDestination.mainBody);
returnPair = new KeyValuePair<string, CelestialBody>("OK", null);
return returnPair;
}
示例3: GetNearbyVessels
public static List<Vessel> GetNearbyVessels(int range, bool includeSelf, Vessel thisVessel, bool landedOnly = true)
{
try
{
var vessels = new List<Vessel>();
foreach (var v in FlightGlobals.Vessels.Where(
x => x.mainBody == thisVessel.mainBody
&& (x.Landed || !landedOnly)))
{
if (v == thisVessel && !includeSelf) continue;
var posCur = thisVessel.GetWorldPos3D();
var posNext = v.GetWorldPos3D();
var distance = Vector3d.Distance(posCur, posNext);
if (distance < range)
{
vessels.Add(v);
}
}
return vessels;
}
catch (Exception ex)
{
Debug.Log(String.Format("[MKS] - ERROR in GetNearbyVessels - {0}", ex.Message));
return new List<Vessel>();
}
}
示例4: VesselState
public Vector3d velocity; // velocity in world frame relatively to the reference body
public VesselState(Vessel vessel)
{
referenceBody = vessel.orbit.referenceBody;
time = Planetarium.GetUniversalTime();
position = vessel.GetWorldPos3D() - referenceBody.position;
velocity = vessel.obt_velocity;
}
示例5: GetDistanceToKerbinSurface
public static float GetDistanceToKerbinSurface(Vessel vessel)
{
foreach (var body in FlightGlobals.fetch.bodies)
{
if (body.name.ToUpper() == "KERBIN") return (float)Vector3d.Distance(body.position, vessel.GetWorldPos3D()) - 600000; // Kerbin radius = 600,000
}
throw new kOSException("Planet Kerbin not found!");
}
示例6: GetHeadingFromVessel
public float GetHeadingFromVessel(Vessel vessel)
{
var up = vessel.upAxis;
var north = VesselUtils.GetNorthVector(vessel);
var targetWorldCoords = vessel.mainBody.GetWorldSurfacePosition(Lat, Lng, vessel.altitude);
var vector = Vector3d.Exclude(vessel.upAxis, targetWorldCoords - vessel.GetWorldPos3D()).normalized;
var headingQ = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(Quaternion.LookRotation(vector, up)) * Quaternion.LookRotation(north, up));
return headingQ.eulerAngles.y;
}
示例7: GetDistanceToHome
public static double GetDistanceToHome(Vessel vessel)
{
foreach ( var body in FlightGlobals.fetch.bodies.Where(
body => body.name.ToUpper() == "KERBIN" ||
body.name.ToUpper() == "EARTH"))
{
return Vector3d.Distance(body.position, vessel.GetWorldPos3D()) - body.Radius;
// Kerbin radius = 600,000
}
throw new Exception("Planet Kerbin or Earth not found!");
}
示例8: isClose
public bool isClose (Vessel vessel, double range = 200.0)
{
var pos = vessel.GetWorldPos3D ();
Debug.Log (String.Format ("[EL ST] isClose {0}", range));
range *= range;
foreach (Vessel stake in stakes) {
var stake_pos = stake.GetWorldPos3D ();
var offs = pos - stake_pos;
Debug.Log (String.Format ("[EL ST] isClose {0} {1} {2} {3}", pos, stake_pos, Vector3d.Dot (offs, offs), range));
if (Vector3d.Dot (offs, offs) < range) {
return true;
}
}
return false;
}
示例9: VesselCheck
public static void VesselCheck(Vessel shipToCheck)
{
if (Vector3d.Distance(shipToCheck.GetWorldPos3D(), FlightGlobals.ship_position) < DistantObjectSettings.DistantVessel.maxDistance && !shipToCheck.loaded)
{
if (!vesselIsBuilt.ContainsKey(shipToCheck))
{
meshListLookup.Add(shipToCheck, new List<GameObject>());
vesselIsBuilt.Add(shipToCheck, false);
watchList.Add(shipToCheck);
if (DistantObjectSettings.debugMode)
{
print("DistObj: Adding new definition for " + shipToCheck.vesselName);
}
}
DrawVessel(shipToCheck);
}
else
{
if (!vesselIsBuilt.ContainsKey(shipToCheck))
{
meshListLookup.Add(shipToCheck, new List<GameObject>());
vesselIsBuilt.Add(shipToCheck, false);
watchList.Add(shipToCheck);
if (DistantObjectSettings.debugMode)
{
print("DistObj: Adding new definition for " + shipToCheck.vesselName);
}
}
CheckErase(shipToCheck);
}
}
示例10: DistanceFrom
public float DistanceFrom(Vessel Vessel)
{
return (float)Vector3d.Distance(Vessel.GetWorldPos3D(), Body.GetWorldSurfacePosition(Lat, Lng, Vessel.altitude));
}
示例11: GetTerminalManeuveringTarget
public static Vector3 GetTerminalManeuveringTarget(Vector3 targetPosition, Vessel missileVessel, float radarAlt)
{
Vector3 upDirection = -FlightGlobals.getGeeForceAtPosition(missileVessel.GetWorldPos3D()).normalized;
Vector3 planarDirectionToTarget = Vector3.ProjectOnPlane(targetPosition-missileVessel.transform.position, upDirection).normalized;
Vector3 crossAxis = Vector3.Cross(planarDirectionToTarget, upDirection).normalized;
float sinAmplitude = Mathf.Clamp(Vector3.Distance(targetPosition, missileVessel.transform.position)-650, 0, 4500);
Vector3 targetSin = (Mathf.Sin(1.5f*Time.time) * sinAmplitude * crossAxis)+targetPosition;
Vector3 finalTarget;
if(Vector3.Distance(targetPosition,missileVessel.transform.position) > (1000+GetRadarAltitude(missileVessel)))
{
finalTarget = GetCruiseTarget(targetSin, missileVessel, radarAlt);
}
else if(!GetBallisticGuidanceTarget(targetSin, missileVessel, true, out finalTarget))
{
finalTarget = GetAirToGroundTarget(targetSin, missileVessel, 6);
}
return finalTarget;
}
示例12: writeVesselUpdateToFile
private void writeVesselUpdateToFile(KSP.IO.FileStream out_stream, Vessel vessel)
{
if (!vessel || !vessel.mainBody)
return;
//Create a KLFVesselUpdate from the vessel data
KLFVesselUpdate update = new KLFVesselUpdate();
update.vesselName = vessel.vesselName;
update.ownerName = playerName;
update.id = vessel.id;
Vector3 pos = vessel.mainBody.transform.InverseTransformPoint(vessel.GetWorldPos3D());
Vector3 dir = vessel.mainBody.transform.InverseTransformDirection(vessel.transform.up);
Vector3 vel = vessel.mainBody.transform.InverseTransformDirection(vessel.GetObtVelocity());
for (int i = 0; i < 3; i++)
{
update.localPosition[i] = pos[i];
update.localDirection[i] = dir[i];
update.localVelocity[i] = vel[i];
}
update.situation = vessel.situation;
if (vessel == FlightGlobals.ActiveVessel)
update.state = Vessel.State.ACTIVE;
else if (vessel.isCommandable)
update.state = Vessel.State.INACTIVE;
else
update.state = Vessel.State.DEAD;
update.timeScale = Planetarium.TimeScale;
update.bodyName = vessel.mainBody.bodyName;
//Serialize the update
byte[] update_bytes = KSP.IO.IOUtils.SerializeToBinary(update);
//Write the length of the serialized to the stream
writeIntToStream(out_stream, update_bytes.Length);
//Write the serialized update to the stream
out_stream.Write(update_bytes, 0, update_bytes.Length);
}
示例13: getVesselDetail
//.........这里部分代码省略.........
if (module is ModuleRCS)
{
ModuleRCS rcs = (ModuleRCS)module;
if (rcs.requiresFuel)
{
has_rcs = true;
if (!rcs_fuel_densities.ContainsKey(rcs.resourceName))
rcs_fuel_densities.Add(rcs.resourceName, PartResourceLibrary.Instance.GetDefinition(rcs.resourceName).density);
}
}
if (module is ModuleParachute)
{
ModuleParachute parachute = (ModuleParachute)module;
if (parachute.deploymentState == ModuleParachute.deploymentStates.DEPLOYED)
parachutes_open = true;
}
}
}
//Determine how much fuel this vessel has and can hold
float fuel_capacity = 0.0f;
float fuel_amount = 0.0f;
float rcs_capacity = 0.0f;
float rcs_amount = 0.0f;
foreach (Part part in vessel.parts)
{
if (part != null && part.Resources != null)
{
foreach (PartResource resource in part.Resources)
{
float density = 0.0f;
//Check that this vessel can use this type of resource as fuel
if (has_engines && fuel_densities.TryGetValue(resource.resourceName, out density))
{
fuel_capacity += ((float)resource.maxAmount) * density;
fuel_amount += ((float)resource.amount) * density;
}
if (has_rcs && rcs_fuel_densities.TryGetValue(resource.resourceName, out density))
{
rcs_capacity += ((float)resource.maxAmount) * density;
rcs_amount += ((float)resource.amount) * density;
}
}
}
}
if (has_engines && fuel_capacity > 0.0f)
detail.percentFuel = (byte)Math.Round(fuel_amount / fuel_capacity * 100);
else
detail.percentFuel = byte.MaxValue;
if (has_rcs && rcs_capacity > 0.0f)
detail.percentRCS = (byte)Math.Round(rcs_amount / rcs_capacity * 100);
else
detail.percentRCS = byte.MaxValue;
}
//Determine vessel activity
if (parachutes_open)
detail.activity = Activity.PARACHUTING;
//Check if the vessel is aerobraking
if (vessel.orbit != null && vessel.orbit.referenceBody != null
&& vessel.orbit.referenceBody.atmosphere && vessel.orbit.altitude < vessel.orbit.referenceBody.maxAtmosphereAltitude)
{
//Vessel inside its body's atmosphere
switch (vessel.situation)
{
case Vessel.Situations.LANDED:
case Vessel.Situations.SPLASHED:
case Vessel.Situations.SUB_ORBITAL:
case Vessel.Situations.PRELAUNCH:
break;
default:
//If the apoapsis of the orbit is above the atmosphere, vessel is aerobraking
if (vessel.situation == Vessel.Situations.ESCAPING || (float)vessel.orbit.ApA > vessel.orbit.referenceBody.maxAtmosphereAltitude)
detail.activity = Activity.AEROBRAKING;
break;
}
}
//Check if the vessel is docking
if (detail.activity == Activity.NONE && FlightGlobals.fetch.VesselTarget != null && FlightGlobals.fetch.VesselTarget is ModuleDockingNode
&& Vector3.Distance(vessel.GetWorldPos3D(), FlightGlobals.fetch.VesselTarget.GetTransform().position) < DOCKING_TARGET_RANGE)
detail.activity = Activity.DOCKING;
return detail;
}
示例14: StartStationaryCamera
void StartStationaryCamera()
{
Debug.Log ("flightCamera position init: "+flightCamera.transform.position);
if(FlightGlobals.ActiveVessel != null)
{
hasDied = false;
vessel = FlightGlobals.ActiveVessel;
cameraUp = -FlightGlobals.getGeeForceAtPosition(vessel.GetWorldPos3D()).normalized;
if(FlightCamera.fetch.mode == FlightCamera.Modes.ORBITAL || (FlightCamera.fetch.mode == FlightCamera.Modes.AUTO && FlightCamera.GetAutoModeForVessel(vessel) == FlightCamera.Modes.ORBITAL))
{
cameraUp = Vector3.up;
}
flightCamera.transform.parent = cameraParent.transform;
flightCamera.setTarget(null);
cameraParent.transform.position = vessel.transform.position+vessel.rb_velocity*Time.fixedDeltaTime;
manualPosition = Vector3.zero;
hasTarget = (camTarget != null) ? true : false;
Vector3 rightAxis = -Vector3.Cross(vessel.srf_velocity, vessel.upAxis).normalized;
//Vector3 upAxis = flightCamera.transform.up;
if(autoFlybyPosition)
{
setPresetOffset = false;
Vector3 velocity = vessel.srf_velocity;
if(referenceMode == ReferenceModes.Orbit) velocity = vessel.obt_velocity;
Vector3 clampedVelocity = Mathf.Clamp((float) vessel.srfSpeed, 0, maxRelV) * velocity.normalized;
float clampedSpeed = clampedVelocity.magnitude;
float sideDistance = Mathf.Clamp(20 + (clampedSpeed/10), 20, 150);
float distanceAhead = Mathf.Clamp(4 * clampedSpeed, 30, 3500);
flightCamera.transform.rotation = Quaternion.LookRotation(vessel.transform.position - flightCamera.transform.position, cameraUp);
if(referenceMode == ReferenceModes.Surface && vessel.srfSpeed > 0)
{
flightCamera.transform.position = vessel.transform.position + (distanceAhead * vessel.srf_velocity.normalized);
}
else if(referenceMode == ReferenceModes.Orbit && vessel.obt_speed > 0)
{
flightCamera.transform.position = vessel.transform.position + (distanceAhead * vessel.obt_velocity.normalized);
}
else
{
flightCamera.transform.position = vessel.transform.position + (distanceAhead * vessel.vesselTransform.up);
}
if(flightCamera.mode == FlightCamera.Modes.FREE || FlightCamera.GetAutoModeForVessel(vessel) == FlightCamera.Modes.FREE)
{
flightCamera.transform.position += (sideDistance * rightAxis) + (15 * cameraUp);
}
else if(flightCamera.mode == FlightCamera.Modes.ORBITAL || FlightCamera.GetAutoModeForVessel(vessel) == FlightCamera.Modes.ORBITAL)
{
flightCamera.transform.position += (sideDistance * FlightGlobals.getUpAxis()) + (15 * Vector3.up);
}
}
else if(manualOffset)
{
setPresetOffset = false;
float sideDistance = manualOffsetRight;
float distanceAhead = manualOffsetForward;
flightCamera.transform.rotation = Quaternion.LookRotation(vessel.transform.position - flightCamera.transform.position, cameraUp);
if(referenceMode == ReferenceModes.Surface && vessel.srfSpeed > 4)
{
flightCamera.transform.position = vessel.transform.position + (distanceAhead * vessel.srf_velocity.normalized);
}
else if(referenceMode == ReferenceModes.Orbit && vessel.obt_speed > 4)
{
flightCamera.transform.position = vessel.transform.position + (distanceAhead * vessel.obt_velocity.normalized);
}
else
{
flightCamera.transform.position = vessel.transform.position + (distanceAhead * vessel.vesselTransform.up);
}
if(flightCamera.mode == FlightCamera.Modes.FREE || FlightCamera.GetAutoModeForVessel(vessel) == FlightCamera.Modes.FREE)
{
flightCamera.transform.position += (sideDistance * rightAxis) + (manualOffsetUp * cameraUp);
}
else if(flightCamera.mode == FlightCamera.Modes.ORBITAL || FlightCamera.GetAutoModeForVessel(vessel) == FlightCamera.Modes.ORBITAL)
{
flightCamera.transform.position += (sideDistance * FlightGlobals.getUpAxis()) + (manualOffsetUp * Vector3.up);
}
}
else if(setPresetOffset)
{
flightCamera.transform.position = presetOffset;
//setPresetOffset = false;
//.........这里部分代码省略.........
示例15: StartPathingCam
void StartPathingCam()
{
vessel = FlightGlobals.ActiveVessel;
cameraUp = -FlightGlobals.getGeeForceAtPosition(vessel.GetWorldPos3D()).normalized;
if(FlightCamera.fetch.mode == FlightCamera.Modes.ORBITAL || (FlightCamera.fetch.mode == FlightCamera.Modes.AUTO && FlightCamera.GetAutoModeForVessel(vessel) == FlightCamera.Modes.ORBITAL))
{
cameraUp = Vector3.up;
}
cameraParent.transform.position = vessel.transform.position+vessel.rb_velocity*Time.fixedDeltaTime;
cameraParent.transform.rotation = vessel.transform.rotation;
flightCamera.transform.parent = cameraParent.transform;
flightCamera.setTarget(null);
cameraToolActive = true;
}