Jump to content

Surface position calculations are off after returning from map view.


Recommended Posts

So I use the follow calculations in flight mode regular view to draw some stuff on the ground.

Vector3d surfaceNVector = vessel.mainBody.GetSurfaceNVector(geoCoord.Latitude.NormalAngle, geoCoord.Longitude.NormalAngle);

Vector3d surfaceVector3D = vessel.mainBody.position + (vessel.mainBody.Radius * surfaceNVector);

I press M to go into map view and then M again to return and now those numbers are way off. Why would they be so different after returning from map view? Everything still looks correct, just the surfaceVector3D is very different.

Example. I'm using DoubleConverter to fetch the whole double to string. I added vessel position in vector3 just to show that my ships position had not changed.

Before mapview.

vessel.position= (1442.5, -46.4, -302.2)

body.position= 129187.193202878246665932238101959228515625, -6156.2309592617975795292295515537261962890625, 686391.0464513562619686126708984375

SurfaceNVector= -0.0887034059184583778545629684231244027614593505859375, 0.00578425817552570553647939277652767486870288848876953125, -0.9960412883690235030798021398368291556835174560546875

body.Radius= 600000

Radius * surfaceNVector= -53222.043551075024879537522792816162109375, 3470.55490531542318421998061239719390869140625, -597624.773021414061076939105987548828125

surfaceVector3D= 75965.14965180322178639471530914306640625, -2685.67605394637439530924893915653228759765625, 88766.273429942200891673564910888671875

After coming back from mapview.

vessel.position= (1442.6, -46.4, -301.7)

body.position= 121576.205192791647277772426605224609375, -5910.33500358540550223551690578460693359375, 687781.159533579251728951930999755859375

SurfaceNVector= -0.202680362274793690602336937445215880870819091796875, 0.0098522251209750520695163089612833573482930660247802734375, -0.97919538622704094255055906614870764315128326416015625

body.Radius= 600000

Radius * surfaceNVector= -121608.21736487621092237532138824462890625, 5911.3350725850314120179973542690277099609375, -587517.2317362246103584766387939453125

surfaceVector3D= -32.01217208456364460289478302001953125, 1.0000689996259097824804484844207763671875, 100263.927797354641370475292205810546875

Link to comment
Share on other sites

You complain that you cannot save the data? Well, the reference frame can change quite a lot for whatever reason, and KSP is pretty flexible in that regard. FloatingOrigin (xy-offset), Krakensbane (velocity), planet rotation (did you know that usually, unity-kerbin only rotates once you are at least 100km above sea level?). My guess for your example would be planet rotation. So make sure to save your data in a format / with a reference frame you know and convert it via the current values or using a given converter when you need them.

Link to comment
Share on other sites

You complain that you cannot save the data? Well, the reference frame can change quite a lot for whatever reason, and KSP is pretty flexible in that regard. FloatingOrigin (xy-offset), Krakensbane (velocity), planet rotation (did you know that usually, unity-kerbin only rotates once you are at least 100km above sea level?). My guess for your example would be planet rotation. So make sure to save your data in a format / with a reference frame you know and convert it via the current values or using a given converter when you need them.

Faark,

Thanks for your reply. I've very new to all of this so I really appreciate the assistance.

The difference in real time between going in and out of map view is about 5 seconds those numbers are updated every OnFixedUpdate I'm not saving any data. From the camera point of view my marker was on the ground and now it looks like its right up by the vessel. I'm not sure what I would use as a known reference. Also, I tried using CelestialBody.GetWorldSurfacePosition and the the same thing happens.

Maybe a better question to ask is what is a reliable way given Lat, Long, to get a Vector3d that is relative to the world position of the vessel of that position on a bodies surface?

Link to comment
Share on other sites

It may be that your surface normal isn't reflecting terrain before you open map view and is afterwards (or vice versa).

The way I'd get the Vector that passes between the vessel and the center of the body is to subtract the two positions from each other - i.e. vessel.position - vessel.mainBody.position (or vice versa depending on which way round you want the vector). Then scale as appropriate. It doesn't involve latitude and longitude though.

Link to comment
Share on other sites

Have you tried CelestialBody's GetLatitude(pos), GetLongitude(pos), GetAltitude(pos) and GetWorldSurfacePosition(lat, lon, alt), respectively?

Yes. I started out with that and everything was working great until I hopped into and out of map view. ( Planetarium? ) Then I started Googling for snipits of example code and found out that calculation above basically generated the same numbers as GetWorldSurfacePostion(lat, lon, 0.0f).

Link to comment
Share on other sites

Thank you Faark and EndlessWaves. I figured out what my issue was and it didn't have anything to do with any of the methods from CelestialBody. My issue was that I was using "Camera.main.WorldToScreenPoint()". It seems that jumping from Flight to Map view and back changes Camera.main to the UICamera instead of Camera 00. So I'm now using "FlightCamera.fetch.mainCamera" as my reference.

Faark, you were right on in thinking that my issue could be the re-positioning of objects. During my debugging ( writing LOTS of traces ) I think I learned a lot about how Krakensbane might work. I can at least write what I think I learned for the benefit of others. Please let me know how close I get.

Vector3d surfaceNVector = vessel.mainBody.GetSurfaceNVector(geoCoord.Latitud e.NormalAngle, geoCoord.Longitude.NormalAngle);

Vector3d surfaceVector3D = vessel.mainBody.position + (vessel.mainBody.Radius * surfaceNVector);

surfaceNVector is the relative direction to the surface where lat long is. Multiplying it by Radius takes you to the relative surface position of lat long. Adding it to body.position makes that relative position a world position.

from time to time and when you jump in and out of map view. Krakensbane takes your vessel and makes it the center of the universe and re-positions everything around you to fit within Unity's Vector3 floats. Jumping into Map view seems to shrink or scale everything down so the entire solar system can fit within the Vector3. Which is why the ship position is reset when you return from it, I guess. This is why my my SurfaceVector3D reset to being straight below the vessel.

With all that said. It would be nice if Squad could create a Development Build with Script Debugging so we can set breakpoints and step through things. Being able to do that would have saved a lot of time. :)

Thanks again y'all.

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...