Jump to content

Mouse courser on planet intersect


Recommended Posts

hey guys,

i´m trying to figure out at what lat/long my mouse courser is over the planet. i´ve been banging my head against a wall for hours now. does anyone have any idea what is wrong with this code?


Vector3 inputPosition = Input.mousePosition;
var ray = Camera.main.ScreenPointToRay(inputPosition);
var w = targetBody.position - ray.origin ;
var tc = Vector3.Dot(w,ray.direction);
if (tc < 0)
{
return;
}


var d2 = (tc*tc)-(Vector3.Dot(w,w));
var radius2 = targetBody.pqsController.mapMaxHeight * targetBody.pqsController.mapMaxHeight;
if (d2 > radius2)
{
return;
}
var t1c = (float)Math.Sqrt(radius2 - d2);
var t1 = tc - t1c;
var t2 = tc + t1c;
var final = ray.origin*t2;
Debug.Log("intersect: x: "+final.x+" y: "+final.y+" z: "+final.z);
Debug.Log("long: "+targetBody.GetLongitude(final)+" lat: "+targetBody.GetLatitude(final));
Debug.Log("mapmax: "+targetBody.pqsController.mapMaxHeight+" try "+targetBody.pqsController.GetClampedWorldSurfaceHeight(FlightGlobals.ActiveVessel.GetWorldPos3D()));

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