Jump to content

How can one get the coordinates of fixed spot on the KSC grounds? [solved]


Recommended Posts

Hello all. I am hoping someone out there can help me with an issue I am having.

I am trying to expand my Walkabout mod to work with relocated KSCs (à la Kopernicus or Galileo). To do so, I need to reliably locate a fixed spot on the KSC grounds. It doesn't matter which spot it is, but I need to be able to get the coordinates of, let's say, the flagpole whether or not Galileo is installed.

I tried using code similar to the following:
 

var Kerbin = Planetarium.fetch.Home;
PQSCity ksc = null;
foreach (var city in Kerbin.pqsController.GetComponentsInChildren<PQSCity>(true))
{
    if (city.name == "KSC")
    {
        ksc = city;
        break;
    }
}
var kscVectorPosition = ksc.transform.position;

var latitude = Kerbin.GetLatitude(kscVectorPosition);
var longitude = Kerbin.GetLongitude(kscVectorPosition);
var altitude = Kerbin.GetAltitude(kscVectorPosition);

When I do this with a plain vanilla install of KSC (v1.2.2), it gives me a point that is in the centre of the crawlway about 1/4 of the way between the VAB and the launchpad.

However, when Galileo is installed (also with v1.2.2), it gives me a point that is near the edge of the R&D buildings.

Is there a way that I can reliably get the coordinates of a point in the KSC?

Edited by Antipodes
Link to comment
Share on other sites

I looked through the API documentation and found the SpaceCenter object. I thought that might help:

var kscVectorPosition =
    ((FlagPoleFacility)SpaceCenter.FindObjectOfType(typeof(FlagPoleFacility)))
    .transform
    .position;
var latitude = Kerbin.GetLatitude(kscVectorPosition);
var longitude = Kerbin.GetLongitude(kscVectorPosition);
var altitude = Kerbin.GetAltitude(kscVectorPosition);

but it was to no avail. In vanilla KSC I get the proper position for the flagpole, but with Galileo I get a position west of the KSC.

Link to comment
Share on other sites

Maybe you can store the offset of the flagpole's location relative to the KSC position.

That way flagpole offset + spacenter.position will always point to the flagpole. Unless there are mods out there that move the location of KSC buildings, but I don't think that's even possible.

Link to comment
Share on other sites

On 2017-6-25 at 9:44 AM, Antipodes said:

I looked through the API documentation and found the SpaceCenter object. I thought that might help:


var kscVectorPosition =
    ((FlagPoleFacility)SpaceCenter.FindObjectOfType(typeof(FlagPoleFacility)))
    .transform
    .position;
var latitude = Kerbin.GetLatitude(kscVectorPosition);
var longitude = Kerbin.GetLongitude(kscVectorPosition);
var altitude = Kerbin.GetAltitude(kscVectorPosition);

but it was to no avail. In vanilla KSC I get the proper position for the flagpole, but with Galileo I get a position west of the KSC.

Ah Ha! I got it! The method I posted above does work. The success was hidden by a bug I introduced while trying to display the results. 

I still don't know why GPP gives me different results for the location of the KSC, but it doesn't matter if I can reliably get the location of the flagpole. 

Now I just have do some validation (I. E ensure the flagpole does not change position as the buildings are upgraded) and I will be ready to work on updating WalkAbout. 

Link to comment
Share on other sites

On 2017-6-29 at 4:30 AM, legacy.nl said:

Maybe you can store the offset of the flagpole's location relative to the KSC position.

That way flagpole offset + spacenter.position will always point to the flagpole. Unless there are mods out there that move the location of KSC buildings, but I don't think that's even possible.

That is exactly the problem I was running into. Vanilla KSP says the centre of the KSC is somewhere in the crawlway, so the flagpole would be x metres due west. But GPP says the centre of the KSC is in the R&D facility and the flagpole is y meters NWN. So any offsets I stored would give me inconsistent positions relative to the KSC depending on which mods were installed. 

Fortunately, as my previous post shows, I can get the lat/long of the flagpole independently from the position of the KSC so I can base all my calculations on the position of the flagpole and don't have to worry about the KSC having been moved.

I am going to have to check if the KSC has been rotated, lifted, lowered or rescaled, but I already know how to handle those issues. 

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...