本文整理汇总了C#中CelestialBody.GetWorldSurfacePosition方法的典型用法代码示例。如果您正苦于以下问题:C# CelestialBody.GetWorldSurfacePosition方法的具体用法?C# CelestialBody.GetWorldSurfacePosition怎么用?C# CelestialBody.GetWorldSurfacePosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CelestialBody
的用法示例。
在下文中一共展示了CelestialBody.GetWorldSurfacePosition方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetWorldSurfacePostion
public static Vector3 GetWorldSurfacePostion(Vector3d geoPosition, CelestialBody body)
{
if(!body)
{
return Vector3.zero;
}
return body.GetWorldSurfacePosition(geoPosition.x, geoPosition.y, geoPosition.z);
}
示例2: RaycastGround
public static DMPRaycastPair RaycastGround(double latitude, double longitude, CelestialBody body)
{
//We can only find the ground on bodies that actually *have* ground and if we are in flight near the origin
if (!HighLogic.LoadedSceneIsFlight || FlightGlobals.fetch.activeVessel == null || body.pqsController == null)
{
return new DMPRaycastPair(-1f, Vector3.up);
}
//Math functions take radians.
double latRadians = latitude * Mathf.Deg2Rad;
double longRadians = longitude * Mathf.Deg2Rad;
//Radial vector
Vector3d surfaceRadial = new Vector3d(Math.Cos(latRadians) * Math.Cos(longRadians), Math.Sin(latRadians), Math.Cos(latRadians) * Math.Sin(longRadians));
double surfaceHeight = body.pqsController.GetSurfaceHeight(surfaceRadial) - body.pqsController.radius;
Vector3d origin = body.GetWorldSurfacePosition(latitude, longitude, surfaceHeight + 500);
//Only return the surface if it's really close.
double highestHit = double.NegativeInfinity;
Vector3 rotatedVector = Vector3.up;
if (Vector3d.Distance(FlightGlobals.fetch.activeVessel.GetWorldPos3D(), origin) < 2500)
{
//Down vector
Vector3d downVector = -body.GetSurfaceNVector(latitude, longitude);
//Magic numbers!
LayerMask groundMask = 33792;
RaycastHit[] raycastHits = Physics.RaycastAll(origin, downVector, 1000f, groundMask);
foreach (RaycastHit raycastHit in raycastHits)
{
if (raycastHit.collider == null)
{
//I don't think this is technically possible, but unity's weird enough that we should probably check this anyway.
continue;
}
if (raycastHit.collider.name == body.name)
{
continue;
}
double hitAltitude = body.GetAltitude(raycastHit.point);
if ((hitAltitude > highestHit) && (!body.ocean || hitAltitude > 0))
{
highestHit = hitAltitude;
rotatedVector = Quaternion.Inverse(body.rotation) * raycastHit.normal;
}
}
}
if (highestHit == double.NegativeInfinity)
{
return new DMPRaycastPair(-1f, Vector3.up);
}
else
{
return new DMPRaycastPair(highestHit, rotatedVector);
}
}
示例3: DrawWaypoint
public static void DrawWaypoint(CelestialBody targetBody, double latitude, double longitude, double altitude, string id, int seed, float alpha = -1.0f)
{
// Translate to scaled space
Vector3d localSpacePoint = targetBody.GetWorldSurfacePosition(latitude, longitude, altitude);
Vector3d scaledSpacePoint = ScaledSpace.LocalToScaledSpace(localSpacePoint);
// Don't draw if it's behind the camera
Camera camera = MapView.MapIsEnabled ? PlanetariumCamera.Camera : FlightCamera.fetch.mainCamera;
Vector3 cameraPos = ScaledSpace.ScaledToLocalSpace(camera.transform.position);
if (Vector3d.Dot(camera.transform.forward, scaledSpacePoint.normalized) < 0.0)
{
return;
}
// Translate to screen position
Vector3 screenPos = camera.WorldToScreenPoint(new Vector3((float)scaledSpacePoint.x, (float)scaledSpacePoint.y, (float)scaledSpacePoint.z));
// Draw the marker at half-resolution (30 x 45) - that seems to match the one in the map view
Rect markerRect = new Rect(screenPos.x - 15f, (float)Screen.height - screenPos.y - 45.0f, 30f, 45f);
// Half-res for the icon too (16 x 16)
Rect iconRect = new Rect(screenPos.x - 8f, (float)Screen.height - screenPos.y - 39.0f, 16f, 16f);
if (alpha < 0.0f)
{
bool occluded = WaypointData.IsOccluded(targetBody, cameraPos, localSpacePoint, altitude);
float desiredAlpha = occluded ? 0.3f : 1.0f * Config.opacity;
if (lastAlpha < 0.0f)
{
lastAlpha = desiredAlpha;
}
else if (lastAlpha < desiredAlpha)
{
lastAlpha = Mathf.Clamp(lastAlpha + Time.deltaTime * 4f, lastAlpha, desiredAlpha);
}
else
{
lastAlpha = Mathf.Clamp(lastAlpha - Time.deltaTime * 4f, desiredAlpha, lastAlpha);
}
alpha = lastAlpha;
}
// Draw the marker
Graphics.DrawTexture(markerRect, GameDatabase.Instance.GetTexture("Squad/Contracts/Icons/marker", false), new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, new Color(0.5f, 0.5f, 0.5f, 0.5f * (alpha - 0.3f) / 0.7f));
// Draw the icon
Graphics.DrawTexture(iconRect, ContractDefs.sprites[id].texture, new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, SystemUtilities.RandomColor(seed, alpha));
}
示例4: isInSafetyBubble
//Adapted from KMP. Called from PlayerStatusWorker.
public bool isInSafetyBubble(Vector3d worlPos, CelestialBody body)
{
//If not at Kerbin or past ceiling we're definitely clear
if (body.name != "Kerbin")
{
return false;
}
Vector3d landingPadPosition = body.GetWorldSurfacePosition(-0.0971978130377757, 285.44237039111, 60);
Vector3d runwayPosition = body.GetWorldSurfacePosition(-0.0486001121594686, 285.275552559723, 60);
double landingPadDistance = Vector3d.Distance(worlPos, landingPadPosition);
double runwayDistance = Vector3d.Distance(worlPos, runwayPosition);
return runwayDistance < SAFETY_BUBBLE_DISTANCE || landingPadDistance < SAFETY_BUBBLE_DISTANCE;
}
示例5: DrawGroundMarker
static bool DrawGroundMarker(CelestialBody body, Coordinates pos, Color c, float r = IconSize, Texture2D texture = null)
{
Vector3d center;
Camera camera;
if(MapView.MapIsEnabled)
{
//TODO: cache local center coordinates of the marker
camera = PlanetariumCamera.Camera;
center = body.position + (body.TerrainAltitude(pos.Lat, pos.Lon)+body.Radius) * body.GetSurfaceNVector(pos.Lat, pos.Lon);
}
else
{
camera = FlightCamera.fetch.mainCamera;
center = body.GetWorldSurfacePosition(pos.Lat, pos.Lon, body.TerrainAltitude(pos.Lat, pos.Lon)+GLB.WaypointHeight);
if(camera.transform.InverseTransformPoint(center).z <= 0) return false;
}
return !IsOccluded(center, body) &&
DrawMarker(camera.WorldToScreenPoint(MapView.MapIsEnabled ? ScaledSpace.LocalToScaledSpace(center) : center), c, r, texture);
}
示例6: isInSafetyBubble
private bool isInSafetyBubble(Vector3d pos, CelestialBody body, double altitude)
{
//Assume Kerbin if body isn't supplied for some reason
if (body == null)
body = FlightGlobals.Bodies.Find(b => b.name == "Kerbin");
//If not at Kerbin or past ceiling we're definitely clear
if (body.name != "Kerbin" || altitude > SAFETY_BUBBLE_CEILING)
return false;
//Cylindrical safety bubble -- project vessel position to a plane positioned at KSC with normal pointed away from surface
Vector3d kscNormal = body.GetSurfaceNVector(-0.102668048654, -74.5753856554);
Vector3d kscPosition = body.GetWorldSurfacePosition(-0.102668048654, -74.5753856554, 60);
Vector3d landingPadPosition = body.GetWorldSurfacePosition(-0.0971978130377757, 285.44237039111, 60);
Vector3d runwayPosition = body.GetWorldSurfacePosition(-0.0486001121594686, 285.275552559723, 60);
double projectionDistance = Vector3d.Dot(kscNormal, (pos - kscPosition)) * -1;
double landingPadDistance = Vector3d.Distance(pos, landingPadPosition);
double runwayDistance = Vector3d.Distance(pos, runwayPosition);
Vector3d projectedPos = pos + (Vector3d.Normalize(kscNormal) * projectionDistance);
return Vector3d.Distance(kscPosition, projectedPos) < safetyBubbleRadius || runwayDistance < MIN_SAFETY_BUBBLE_DISTANCE || landingPadDistance < MIN_SAFETY_BUBBLE_DISTANCE;
}
示例7: Distance
public float Distance(double latitude1, double longitude1, double altitude1, double latitude2, double longitude2, double altitude2, CelestialBody body)
{
// I did use great circle distance, but now I'm actually thinking a straight line might be best.
Vector3d position1 = body.GetWorldSurfacePosition(latitude1, longitude1, altitude1);
Vector3d position2 = body.GetWorldSurfacePosition(latitude2, longitude2, altitude2);
return (float)Vector3d.Distance(position1, position2);
}
示例8: isInSafetyBubble
private bool isInSafetyBubble(Vector3d pos, CelestialBody body, double altitude)
{
//Assume Kerbin if body isn't supplied for some reason
if (body == null) body = FlightGlobals.Bodies.Find(b => b.name == "Kerbin");
//If KSC out of range, syncing, not at Kerbin, or past ceiling we're definitely clear
if (syncing || body.name != "Kerbin" || altitude > SAFETY_BUBBLE_CEILING)
return false;
//Cylindrical safety bubble -- project vessel position to a plane positioned at KSC with normal pointed away from surface
Vector3d kscNormal = body.GetSurfaceNVector(-0.102668048654,-74.5753856554);
Vector3d kscPosition = body.GetWorldSurfacePosition(-0.102668048654,-74.5753856554,60);
double projectionDistance = Vector3d.Dot(kscNormal, (pos - kscPosition)) * -1;
Vector3d projectedPos = pos + (Vector3d.Normalize(kscNormal)*projectionDistance);
return Vector3d.Distance(kscPosition, projectedPos) < safetyBubbleRadius;
}
示例9: Update
public void Update(CelestialBody body, double latitude, double longitude, double altitude)
{
Update(body.GetWorldSurfacePosition(latitude, longitude, altitude));
}