Jump to content

Get terrain height from NOT directly under the craft


Recommended Posts

Is there a way to get information about terrain that is not directly under the vessel in question? I see that one can easily get the terrainAltitude via the value in this.vessel, but I was hoping to be able to that information for a few terrain points near the vessel. In anybody aware of how to get terrain data in the vicinity of one's vessel?

Link to comment
Share on other sites

Is there a way to get information about terrain that is not directly under the vessel in question? I see that one can easily get the terrainAltitude via the value in this.vessel, but I was hoping to be able to that information for a few terrain points near the vessel. In anybody aware of how to get terrain data in the vicinity of one's vessel?

Apart from Googling "Kerbal Topology Map", not that I know of.

Link to comment
Share on other sites

It would be tricky, but the only method I know of is to use a raycast.

Find the Vector3, raycast to the center of the planet and the distance you hit would be your altitude.

My landing height mod would have the raycast code for reference. Not sure how you'd go about getting the Vector3 postion to raycast from though.

Actually, this does not apply to this question as outside the 2.5km physics bubble, ray casts can get weird and I don't consider them reliable.

D.

Edited by Diazo
Change my mind
Link to comment
Share on other sites

PQScontroller is fine as long as you aren't trying to do it several hundred thousand times at once like SCANsat does. If you're doing it once per frame, or once every time onGUI runs it should be fine.

And note that you'll also need to subtract the planet's radius from the resulting value coming from pqsController.GetSurfaceHeight(); use body.pqsController.radius, otherwise you'll get the terrain height above the center of the planet.

Link to comment
Share on other sites

It's a mess, a real big mess.

Why? Because KSP doesn't load real polygons for ground that's far away from you, so raycasting only works on nearby ground. For far away ground you have to use the PQScontroller, and it's not well documented what its actual coordinate system is meant to be - you have to fiddle with it a while with trial and error to work out what it is.

I'm in the middle of trying to create a raycast solver for PQS terrain and it's really messy if you want it to run fast enough to give you an answer in one update and yet at the same time not have the chance of error. (It has to work by a numerical approximation algorithm cutting the ray into sample points and looking for a spot where one point is above ground and a neighboring point on the line is below ground. Knowing that the answer must lay between those two points, it takes that smaller line segment and runs it through the same algorithm, recursively. The problem is that to avoid the case where the line segment of the sample might miss a mountain entirely, both endpoints being outside the mountain, you need to make sure you use a lot of small slices, and then you're starting to do too much work in one Update call and causing KSP to lag. I'm going to be trying to solve this by cutting up the algorithm into pieces that can be run

spread across multiple updates, so you get an answer without lagging the game, but the answer might take a half second or so.

Link to comment
Share on other sites

It's not well documented but some mods already use it. Just have a look.

altitude = body.pqsController.GetSurfaceHeight(QuaternionD.AngleAxis( longitude, Vector3d.down) * QuaternionD.AngleAxis( latitude, Vector3d.forward ) * Vector3d.right)

You may have to add or substract body.pqsController.radius, I forgot :)

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