Jump to content

Finding building heights from PQS? (Or another way?)


Recommended Posts

I'm working on some code to return terrain height at an arbitrary location.  I already know about CelestialBody.pqsController.GetSurfaceHeight, and that works for a first-pass.  However, I'd also like to be able to account for buildings / anomalies / whatevers when I am querying.  I haven't really done much with the PQS stuff or the city related code, so I'm not sure where to look.

Note that this is not necessarily for pinging directly below the vessel - it is for an arbitrary location on the planet which may or may not be in physics range.  Otherwise I could use some of the vessel data fields and a physics raycast to find what I need.

Link to comment
Share on other sites

@Steven Mading I tried looking at the code of laserdist but I got a bit lost, I need to check the altitude of the terrain at a certain lat/lon

this seems like a simpler case compared to your problem since my origin is always the center of the planet so I only really need to input the direction to get my result.

 

the problem is that all the Methods I've tried either don't work or don't return the correct value. could you give me a couple of pointers so that I can get to the number I'm looking for... thanks :)

Link to comment
Share on other sites

On 11/23/2017 at 5:55 AM, Sigma88 said:

@Steven Mading I tried looking at the code of laserdist but I got a bit lost, I need to check the altitude of the terrain at a certain lat/lon

this seems like a simpler case compared to your problem since my origin is always the center of the planet so I only really need to input the direction to get my result.

Do I understand that all you want is a method that does this?

Givens:

- which body

- latitude

- longitude

Output:

- Altitude (above seal level) of the terrain at that position on that body.

If that's what you want, then instead of looking at LaserDist, you're better off examining the code in kOS that implements geocoordinates:terrainheight, which is this method here:

https://github.com/KSP-KOS/KOS/blob/develop/src/kOS/Suffixed/GeoCoordinates.cs#L124

This is a method of a class in kOS called GeoCoordinates that represents a spot on a world.  The class has members: Body, lat, and lng - so the givens are already "in" the class, and this method just outputs the terrain height of its own spot.  I think everything the method is doing is just calls into KSP (instead of calls into other parts of kOS) so you should be able to copy its steps almost verbatim.

The problem it's trying to solve is this:  KSP lets you query its PQS system which returns a hypothetical altitude at any given lat/lng by using formulae that return smoothly curving values describing the terrain as a math function.  BUT this is only the hypothetical ideal terrain altitude at that spot.  In practice once your active vessel gets close to that spot the game will create a mesh of polygons that is only an approximation of this curved surface the PQS result described. (It takes samples from the PQS system to define where the polygon vertexes are.)  Depending on how low your terrain detail is set, this could be quite different from what PQS predicted.

For most game purposes, you care about the altitude of the actual polygon you could smash into, not the ideal smooth altitude you never get to see that the polygon is approximating.

So the method calculates PQS terrain height as good-enough fallback, but before it resorts to returning that, it first tries to refine it further with an actual raycast to find the exact height of the polygon hit at that spot.  If the colliders are not present, then the raycast fails and it just has to make do with the PQS hit.

 

 

 

 

Edited by Steven Mading
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...