本文整理汇总了C#中Vessel.GetObtVelocity方法的典型用法代码示例。如果您正苦于以下问题:C# Vessel.GetObtVelocity方法的具体用法?C# Vessel.GetObtVelocity怎么用?C# Vessel.GetObtVelocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vessel
的用法示例。
在下文中一共展示了Vessel.GetObtVelocity方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVelocity
/// <summary>
/// Returns the velocity of the reference frame in world-space.
/// </summary>
public static Vector3d GetVelocity(ReferenceFrame referenceFrame, Vessel vessel)
{
switch (referenceFrame) {
case ReferenceFrame.Orbital:
case ReferenceFrame.Maneuver:
return Vector3d.zero;
// Relative to the surface velocity vector
case ReferenceFrame.Surface:
return ((Vector3d)vessel.GetObtVelocity ()) - ((Vector3d)vessel.GetSrfVelocity ());
// Relative to the target's velocity vector, or relative to the orbit if there is no target
case ReferenceFrame.Target:
throw new NotImplementedException ();
// Relative to the negative surface normal of the target docking port, or relative to the target if the target is not a docking port
case ReferenceFrame.Docking:
throw new NotImplementedException ();
default:
throw new ArgumentException ("No such reference frame");
}
}
示例2: getVesselUpdate
private KMPVesselUpdate getVesselUpdate(Vessel vessel, bool forceFullUpdate = false)
{
if (vessel == null || vessel.mainBody == null)
return null;
if (vessel.id == Guid.Empty) vessel.id = Guid.NewGuid();
//Create a KMPVesselUpdate from the vessel data
KMPVesselUpdate update;
//KMPClientMain.DebugLog("Vid: " + vessel.id);
//KMPClientMain.DebugLog("foreFullUpdate: " + forceFullUpdate);
//KMPClientMain.DebugLog("ParCountsContains: " + serverVessels_PartCounts.ContainsKey(vessel.id));
//KMPClientMain.DebugLog("TimeDelta: " + ((UnityEngine.Time.realtimeSinceStartup - lastFullProtovesselUpdate) < FULL_PROTOVESSEL_UPDATE_TIMEOUT));
//KMPClientMain.DebugLog("Throttle: " + (FlightGlobals.ActiveVessel.ctrlState.mainThrottle == 0f));
//Check for new/forced update
if (!forceFullUpdate //not a forced update
&& (serverVessels_PartCounts.ContainsKey(vessel.id) ?
(vessel.id != FlightGlobals.ActiveVessel.id || (UnityEngine.Time.realtimeSinceStartup - lastFullProtovesselUpdate) < FULL_PROTOVESSEL_UPDATE_TIMEOUT) //not active vessel, or full protovessel timeout hasn't passed
: false)) //have a serverVessels_PartCounts entry
{
if ((serverVessels_PartCounts.ContainsKey(vessel.id) ? serverVessels_PartCounts[vessel.id] == vessel.Parts.Count : false) //Part count is the same
&& (sentVessels_Situations.ContainsKey(vessel.id) ? (sentVessels_Situations[vessel.id] == vessel.situation) : false)) //Situation hasn't changed
{
if (!newFlags.ContainsKey(vessel.id)) //Not an un-updated flag
update = new KMPVesselUpdate(vessel,false);
else if ((UnityEngine.Time.realtimeSinceStartup - newFlags[vessel.id]) < 65f) //Is a flag, but plaque timeout hasn't expired
update = new KMPVesselUpdate(vessel,false);
else //Is a flag, plaque timeout has expired so grab full update
{
update = new KMPVesselUpdate(vessel);
newFlags.Remove(vessel.id);
}
}
else
{
//Vessel has changed
KMPClientMain.DebugLog("Full update: " + vessel.id);
update = new KMPVesselUpdate(vessel);
serverVessels_PartCounts[vessel.id] = vessel.Parts.Count;
}
}
else
{
//New vessel or forced protovessel update
update = new KMPVesselUpdate(vessel);
if (vessel.id == FlightGlobals.ActiveVessel.id)
{
KMPClientMain.DebugLog("First or forced proto update for active vessel: " + vessel.id);
lastFullProtovesselUpdate = UnityEngine.Time.realtimeSinceStartup;
}
if (!vessel.packed) serverVessels_PartCounts[vessel.id] = vessel.Parts.Count;
}
//Track vessel situation
sentVessels_Situations[vessel.id] = vessel.situation;
//Set privacy lock
if (serverVessels_IsPrivate.ContainsKey(vessel.id)) update.isPrivate = serverVessels_IsPrivate[vessel.id];
if (vessel.vesselName.Length <= MAX_VESSEL_NAME_LENGTH)
update.name = vessel.vesselName;
else
update.name = vessel.vesselName.Substring(0, MAX_VESSEL_NAME_LENGTH);
update.player = playerName;
update.id = vessel.id;
update.tick = Planetarium.GetUniversalTime();
update.crewCount = vessel.GetCrewCount();
if (serverVessels_RemoteID.ContainsKey(vessel.id)) update.kmpID = serverVessels_RemoteID[vessel.id];
else
{
KMPClientMain.DebugLog("Generating new remote ID for vessel: " + vessel.id);
Guid server_id = Guid.NewGuid();
serverVessels_RemoteID[vessel.id] = server_id;
update.kmpID = server_id;
if (vessel.vesselType == VesselType.Flag)
{
newFlags[vessel.id] = UnityEngine.Time.realtimeSinceStartup;
}
}
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());
Vector3d o_vel = vessel.obt_velocity;
Vector3d s_vel = vessel.srf_velocity;
Quaternion rot = vessel.transform.rotation;
for (int i = 0; i < 3; i++)
{
update.pos[i] = pos[i];
update.dir[i] = dir[i];
update.vel[i] = vel[i];
update.o_vel[i] = o_vel[i];
update.s_vel[i] = s_vel[i];
}
for (int i = 0; i < 4; i++)
//.........这里部分代码省略.........
示例3: restoreVesselState
private IEnumerator<WaitForFixedUpdate> restoreVesselState(Vessel vessel, Vector3 newWorldPos, Vector3 newOrbitVel)
{
yield return new WaitForFixedUpdate();
if (newWorldPos != Vector3.zero)
{
{
Log.Debug("repositioning");
vessel.transform.position = newWorldPos;
}
if (newOrbitVel != Vector3.zero)
{
Log.Debug("updating velocity");
vessel.ChangeWorldVelocity((-1 * vessel.GetObtVelocity()) + newOrbitVel);
}
}
}
示例4: getVesselUpdate
//.........这里部分代码省略.........
//Set privacy lock
if (serverVessels_IsPrivate.ContainsKey(vessel.id)) update.isPrivate = serverVessels_IsPrivate[vessel.id];
else update.isPrivate = false;
if (vessel.vesselName.Length <= MAX_VESSEL_NAME_LENGTH)
update.name = vessel.vesselName;
else
update.name = vessel.vesselName.Substring(0, MAX_VESSEL_NAME_LENGTH);
update.player = playerName;
update.id = vessel.id;
update.tick = Planetarium.GetUniversalTime();
if (serverVessels_RemoteID.ContainsKey(vessel.id)) update.kmpID = serverVessels_RemoteID[vessel.id];
else
{
Log.Debug("Generating new remote ID for vessel: " + vessel.id);
Guid server_id = Guid.NewGuid();
serverVessels_RemoteID[vessel.id] = server_id;
update.kmpID = server_id;
if (vessel.vesselType == VesselType.Flag)
{
newFlags[vessel.id] = UnityEngine.Time.realtimeSinceStartup;
}
}
if (idOnlyUpdate) return update;
update.crewCount = vessel.GetCrewCount();
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());
Vector3d o_vel = vessel.obt_velocity;
Vector3d s_vel = vessel.srf_velocity;
Vector3 forw = vessel.mainBody.transform.InverseTransformDirection(vessel.transform.forward);
for (int i = 0; i < 3; i++)
{
update.pos[i] = pos[i];
update.dir[i] = dir[i];
update.vel[i] = vel[i];
update.o_vel[i] = o_vel[i];
update.s_vel[i] = s_vel[i];
update.rot[i] = forw[i];
}
update.w_pos[0] = vessel.orbit.LAN;
if (vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.SPLASHED)
{
update.w_pos[1] = vessel.latitude;
update.w_pos[2] = vessel.longitude;
}
//Determine situation
if ((vessel.loaded && vessel.GetTotalMass() <= 0.0) || (vessel.vesselType == VesselType.Debris && vessel.situation == Vessel.Situations.SUB_ORBITAL))
update.situation = Situation.DESTROYED;
else
{
switch (vessel.situation)
{
case Vessel.Situations.LANDED:
update.situation = Situation.LANDED;
break;
示例5: getVesselUpdate
private KLFVesselUpdate getVesselUpdate(Vessel vessel)
{
if (vessel == null || vessel.mainBody == null)
return null;
//Create a KLFVesselUpdate from the vessel data
KLFVesselUpdate update = new KLFVesselUpdate();
if (vessel.vesselName.Length <= MAX_VESSEL_NAME_LENGTH)
update.name = vessel.vesselName;
else
update.name = vessel.vesselName.Substring(0, MAX_VESSEL_NAME_LENGTH);
update.player = 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.pos[i] = pos[i];
update.dir[i] = dir[i];
update.vel[i] = vel[i];
}
//Determine situation
if (vessel.loaded && vessel.GetTotalMass() <= 0.0)
update.situation = Situation.DESTROYED;
else
{
switch (vessel.situation)
{
case Vessel.Situations.LANDED:
update.situation = Situation.LANDED;
break;
case Vessel.Situations.SPLASHED:
update.situation = Situation.SPLASHED;
break;
case Vessel.Situations.PRELAUNCH:
update.situation = Situation.PRELAUNCH;
break;
case Vessel.Situations.SUB_ORBITAL:
if (vessel.orbit.timeToAp < vessel.orbit.period / 2.0)
update.situation = Situation.ASCENDING;
else
update.situation = Situation.DESCENDING;
break;
case Vessel.Situations.ORBITING:
update.situation = Situation.ORBITING;
break;
case Vessel.Situations.ESCAPING:
if (vessel.orbit.timeToPe > 0.0)
update.situation = Situation.ENCOUNTERING;
else
update.situation = Situation.ESCAPING;
break;
case Vessel.Situations.DOCKED:
update.situation = Situation.DOCKED;
break;
case Vessel.Situations.FLYING:
update.situation = Situation.FLYING;
break;
default:
update.situation = Situation.UNKNOWN;
break;
}
}
if (vessel == FlightGlobals.ActiveVessel)
{
update.state = State.ACTIVE;
//Set vessel details since it's the active vessel
update.detail = getVesselDetail(vessel);
}
else if (vessel.isCommandable)
update.state = State.INACTIVE;
else
update.state = State.DEAD;
update.timeScale = (float)Planetarium.TimeScale;
update.bodyName = vessel.mainBody.bodyName;
return update;
}
示例6: can_store
/// <summary>
/// Checks if a vessel can be stored in the hangar right now.
/// </summary>
/// <param name="vsl">A vessel to check</param>
bool can_store(Vessel vsl)
{
if(vsl == null || vsl == vessel || !vsl.enabled || vsl.isEVA) return false;
//if hangar is not ready, return
if(hangar_state == HangarState.Inactive)
{
ScreenMessager.showMessage("Activate the hangar first", 3);
return false;
}
//check self state first
switch(FlightGlobals.ClearToSave())
{
case ClearToSaveStatus.NOT_WHILE_ABOUT_TO_CRASH:
{
ScreenMessager.showMessage("Cannot accept the vessel while about to crush", 3);
return false;
}
}
//always check relative velocity and acceleration
Vector3 rv = vessel.GetObtVelocity()-vsl.GetObtVelocity();
if(rv.magnitude > 1f)
{
ScreenMessager.showMessage("Cannot accept a vessel with a relative speed higher than 1m/s", 3);
return false;
}
Vector3 ra = vessel.acceleration - vsl.acceleration;
if(ra.magnitude > 0.1)
{
ScreenMessager.showMessage("Cannot accept an accelerating vessel", 3);
return false;
}
return true;
}
示例7: hangar_is_ready
/// <summary>
/// Checks if a vessel can be stored in the hangar right now.
/// </summary>
/// <param name="vsl">A vessel to check</param>
bool hangar_is_ready(Vessel vsl)
{
if(vsl == null || vsl == vessel || !vsl.enabled || vsl.isEVA) return false;
//if hangar is not ready, return
if(hangar_state == HangarState.Inactive)
{
ScreenMessager.showMessage("Activate the hangar first");
return false;
}
//always check relative velocity and acceleration
Vector3 rv = vessel.GetObtVelocity()-vsl.GetObtVelocity();
if(rv.sqrMagnitude > HangarConfig.Globals.MaxSqrRelVelocity)
{
ScreenMessager.showMessage("Cannot accept a moving vessel");
return false;
}
Vector3 ra = vessel.acceleration - vsl.acceleration;
if(ra.sqrMagnitude > HangarConfig.Globals.MaxSqrRelAcceleration)
{
ScreenMessager.showMessage("Cannot accept an accelerating vessel");
return false;
}
return true;
}
示例8: GetForwardNotNormalized
/// <summary>
/// Returns the forward vector for the given reference frame in world coordinates.
/// The resulting vector is not normalized.
/// </summary>
static Vector3d GetForwardNotNormalized(ReferenceFrame referenceFrame, Vessel vessel)
{
switch (referenceFrame) {
// Relative to the orbital velocity vector
//case ReferenceFrame.Orbital:
// return vessel.GetObtVelocity ();
// Relative to the surface velocity vector
//case ReferenceFrame.Surface:
// return vessel.GetSrfVelocity ();
// Relative to the surface / navball
case ReferenceFrame.Orbital:
case ReferenceFrame.Surface:
{
var up = GetUp (referenceFrame, vessel);
var exclude = vessel.mainBody.position + ((Vector3d)vessel.mainBody.transform.up) * vessel.mainBody.Radius - ((Vector3d)vessel.CoM);
return Vector3d.Exclude (up, exclude);
}
// Relative to the direction of the burn for a maneuver node, or relative to the orbit if there is no node
case ReferenceFrame.Maneuver:
{
if (vessel.patchedConicSolver.maneuverNodes.Count > 0)
return vessel.patchedConicSolver.maneuverNodes [0].GetBurnVector (vessel.orbit);
else
return GetForward (ReferenceFrame.Orbital, vessel);
}
// Relative to the target's velocity vector, or relative to the orbit if there is no target
case ReferenceFrame.Target:
{
var target = FlightGlobals.fetch.VesselTarget;
if (target != null)
return ((Vector3d)vessel.GetObtVelocity ()) - ((Vector3d)target.GetObtVelocity ());
else
return GetForward (ReferenceFrame.Orbital, vessel);
}
// Relative to the direction to the target, or relative to the orbit if there is no target
//case ReferenceFrame.Target:
// {
// var target = FlightGlobals.fetch.VesselTarget;
// if (target != null)
// // TODO: use the center of control instead of v.CoM?
// return target.GetTransform ().position - vessel.CoM;
// else
// return GetForward (ReferenceFrame.Orbital, vessel);
// }
// Relative to the negative surface normal of the target docking port, or relative to the target if the target is not a docking port
case ReferenceFrame.Docking:
throw new NotImplementedException ();
default:
throw new ArgumentException ("No such reference frame");
}
}
示例9: 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);
}
示例10: GetVesselUpdate
private KLFVesselUpdate GetVesselUpdate(Vessel ves)
{
if (ves == null || ves.mainBody == null)
return null;
//Create a KLFVesselUpdate from the vessel data
KLFVesselUpdate update = new KLFVesselUpdate();
if (ves.vesselName.Length <= MaxVesselNameLength)
update.Name = ves.vesselName;
else
update.Name = ves.vesselName.Substring(0, MaxVesselNameLength);
update.Player = PlayerName;
update.Id = ves.id;
Vector3 pos = ves.mainBody.transform.InverseTransformPoint(ves.GetWorldPos3D());
Vector3 dir = ves.mainBody.transform.InverseTransformDirection(ves.transform.up);
Vector3 vel = ves.mainBody.transform.InverseTransformDirection(ves.GetObtVelocity());
for (int i = 0; i < 3; i++)
{
update.Position[i] = pos[i];
update.Direction[i] = dir[i];
update.Velocity[i] = vel[i];
}
//Determine situation
if (ves.loaded && ves.GetTotalMass() <= 0.0)
update.Situation = Situation.Destroyed;
else
{
switch (ves.situation)
{
case Vessel.Situations.LANDED:
update.Situation = Situation.Landed;
break;
case Vessel.Situations.SPLASHED:
update.Situation = Situation.Splashed;
break;
case Vessel.Situations.PRELAUNCH:
update.Situation = Situation.Prelaunch;
break;
case Vessel.Situations.SUB_ORBITAL:
if (ves.orbit.timeToAp < ves.orbit.period / 2.0)
update.Situation = Situation.Ascending;
else
update.Situation = Situation.Descending;
break;
case Vessel.Situations.ORBITING:
update.Situation = Situation.Orbiting;
break;
case Vessel.Situations.ESCAPING:
if (ves.orbit.timeToPe > 0.0)
update.Situation = Situation.Encountering;
else
update.Situation = Situation.Escaping;
break;
case Vessel.Situations.DOCKED:
update.Situation = Situation.Docked;
break;
case Vessel.Situations.FLYING:
update.Situation = Situation.Flying;
break;
default:
update.Situation = Situation.Unknown;
break;
}
}
if (ves == FlightGlobals.ActiveVessel)
{
update.State = State.Active;
//Set vessel details since it's the active vessel
update.Detail = GetVesselDetail(ves);
}
else if (ves.isCommandable)
update.State = State.Inactive;
else
update.State = State.Dead;
update.TimeScale = (float)Planetarium.TimeScale;
update.BodyName = ves.mainBody.bodyName;
return update;
}