Beau Hollis wrote: ↑Tue Jan 29, 2019 3:48 pmYou can convert to/from ScreenCoord and LLA using the Camera interface.
Could you please shed some light on the GetWorldCoord() function ? I can use the GetScreenCoord() function with no issues, and it works as expected, but can't figure out how the inverse GetWorldCoord() works.
It seems that, regardless what I'm passing as screen coords, it always return the same result: the Lat/Lon coordinates of the current camera.
For example, if I'm in default Spot view, and move the view to see the airplane from the right side, GetWorldCoord() returns a point in Lat/Lon which seems to match the position of a camera moved to a place that matches the current view so, it's some meters on the right side of the plane.
If I place the view directly overhead the airplane, or use the default Top Down view, GetWorldCoord() returns exactly the Lat/Lon of the center of the airplane.
But the main issue I don't understand, is that I can pass anything as the first screencoords parameter, but the returned lat/lon it's always the same, as if the first parameter was ignored. For example:
POINT mp; ScreenCoord screenCoords;
GetCursorPos(&mp);
ScreenToClient(hFSWindow, &mp);
screenCoords.XPixels = mp.x;
screenCoords.YPixels = mp.y;
screenCoords.DistanceMeters = 0;
m_pCamera->GetWorldCoord(screenCoords, LLA);
Here, I was hoping to get the lat/lon coordinates of a point after having clicked on it on screen, so I'm passing the mouse coordinates relative to the main program window, but the result is always as described before: the current location in the world of the current camera.
But even passing 0 to all 3 parameters:
screenCoords.XPixels = 0;
screenCoords.YPixels = 0;
screenCoords.DistanceMeters = 0;
m_pCamera->GetWorldCoord(screenCoords, LLA);
Doesn't change anything, same result as passing different mouse coordinates.
So I checked the samples, and the only one that uses this function is MousePicking.
The sample compiles normally, but nothing happens. I ran it through the VS debugger, and I see it's running, it calls the constructor and registers the plugin correctly, it enters in the OnCustomRender function at each frame. However, it doesn't do anything there, since the window pointer it's always 0. From the source code, it looks like in order to start a mouse picking, the RequestPicks() call must be made, and this is done in the PickWindowPlugin::OnPreCameraUpdate(). However, this one is NEVER called, so no picking ever starts. The OnViewChange() function is also never called too. The OnApplicationShutdown() is called normally when exiting the sim so, for some reason, the MousePicking sample doesn't seem to work correctly.
//Get the current pick results.
P3D::PickResult pickResults;
LLADegreesMeters LLA;
pCamera->GetPickResult(0, pickResults);
pCamera->GetWorldCoord(pickResults.Location, LLA);
if (pickResults.pWindow != nullptr)
{
LPCWSTR szWindowName = pickResults.pWindow->GetWindowName();
}
This code doesn't seem right. According to the docs, GetPickResult() takes 3 parameters, an int ID, a bool wasHit and a float distanceToHit, but here it seems it's being called with two LLAs, since both pickResults.Location and LLA are LLADegreesMeters. I thought it was an overload, but it doesn't look like, and it doesn't compile like this.
In any case, my goal would be simply being able to click on the current view, and get the World Lat/Lon coordinates of the clicked point.