[RESOLVED] Mouse click coords

SDK supports Prepar3D’s philosophy of an open development architecture and encourages third parties to bring new innovations with improved add-ons and training content.
Locked
JeeHell
Posts: 94
Joined: Sun Jan 15, 2012 11:04 pm

[RESOLVED] Mouse click coords

Post by JeeHell »

Hello,

I very probably am overlooking a plain stupid thing, but is there a simple way in simconnect or PDK module to retrieve the mouse click view window coordinates?
In other words, when I click on a view, I want to know the X,Y pixel coordinates in that view.

Thanks
Jean Luc
BenBaron
Posts: 80
Joined: Fri Jan 16, 2015 7:51 am

Re: Mouse click coords

Post by BenBaron »

Hi Jean Luc,

did you take a look into the PDK documentation? The "Window and Camera Services" could provide you with answers. I guess, you could implement your own version of IWindowPlugin on an IWindow, intercept the mouse click window messages and work from there. I don't know if there is an easier way for this, but this is what I'd try.

Greets, Benny
User avatar
Beau Hollis
Lockheed Martin
Posts: 2452
Joined: Wed Oct 06, 2010 3:25 pm

Re: Mouse click coords

Post by Beau Hollis »

There is a picking sample in the PDK. That's a good place to start. You can request custom pick points, or you can get the result of the mouse pick done by the app by using pick id 0.
http://www.prepar3d.com/SDKv4/sdk/pdk_a ... 9452aa61e0

The PickResult sctruct gives you the location, distance, and mouse message id associated with the pick. We use the PDK for the VR mouse cursor emulation, and custom pick requests for the new gaze selection capability. There are convenient functions for converting between ScreenCoord and LLADegreesMeters. If you need to offset relative to the pick location or get that point relative to the user aircraft, you can use the ApplyBodyRelativeOffset and CalculateBodyRelativeOffset functions.
http://www.prepar3d.com/SDKv4/sdk/pdk_a ... 01f576c9bf

If you want to get the input messages directly, you can register a WindowPlugin and handle the OnUserInput callback.
http://www.prepar3d.com/SDKv4/sdk/pdk_a ... bebcc4a096

For panels and gauges, there a number of ways to handle mouse input using C++, XML, and Scaleform.

Thanks
Beau Hollis
Prepar3D Software Architect
JeeHell
Posts: 94
Joined: Sun Jan 15, 2012 11:04 pm

Re: Mouse click coords

Post by JeeHell »

Hello Beau, BenBaron,

thanks to both of you for the answer.

I tried the PickResult route, with the Pick ID=0. But my GetPickResults always return with a distance of 0.0 meters, so this is not pointing to the correct world pick location, but only at my own position (offset by the X,Y pixels....). Any idea?
User avatar
Beau Hollis
Lockheed Martin
Posts: 2452
Joined: Wed Oct 06, 2010 3:25 pm

Re: Mouse click coords

Post by Beau Hollis »

Are you in the VC? We have some other functions for doing a ray cast into the terrain and objects. The pick result will typically only get filled with distance info if you hit something in the VC.
Beau Hollis
Prepar3D Software Architect
JeeHell
Posts: 94
Joined: Sun Jan 15, 2012 11:04 pm

Re: Mouse click coords

Post by JeeHell »

Not necessarily in VC since I need to find the terrain location picked.
JeeHell
Posts: 94
Joined: Sun Jan 15, 2012 11:04 pm

Re: Mouse click coords

Post by JeeHell »

I am trying to use the Iraytracemanager.
I cannot find much info in the PDK documentation. I suppose there is a way from the view matrix to find the unit vector I need?
User avatar
Beau Hollis
Lockheed Martin
Posts: 2452
Joined: Wed Oct 06, 2010 3:25 pm

Re: Mouse click coords

Post by Beau Hollis »

Yes. I think grabbing the 3rd row from the view matrix would probably do the trick. You could grab the pitch and heading of the camera and calculate it. You could also apply a 0 0 1 xyz body relative offset then zero out the pbh of the camera location and calculate the body relative offset from it to the other point.
Beau Hollis
Prepar3D Software Architect
JeeHell
Posts: 94
Joined: Sun Jan 15, 2012 11:04 pm

Re: Mouse click coords

Post by JeeHell »

Hello Beau,

I am having issues with RayTraceManager.
I tried this code:
//global variable
CComPtr<IRayTraceManagerV340> spRayTraceMgr; //Smart pointer reference to RayTraceManager
//....


//at DLL start:
//...
pPdk->QueryService(SID_RayTraceManager, IID_IRayTraceManagerV340, (void**)&spRayTraceMgr);
//...

//in a window plugin callback :
CComPtr<ICameraSystemV440> mcam440;
//...
DXYZ vWorldRadiansFeet;
DXYZ xyzWorldUnitRayDir;
DXYZ xyzWorldRes;
UINT ResObjID;
DWORD interrogRes;

mcam440->GetLLARadians(vWorldRadiansFeet.dZ, vWorldRadiansFeet.dX, vWorldRadiansFeet.dY);

xyzWorldUnitRayDir.dX = 0;
xyzWorldUnitRayDir.dZ = 0;
xyzWorldUnitRayDir.dY = 1;

spRayTraceMgr->InterrogateWorldRay(
INTEROGATIONTYPE_TERRAIN,
0,
vWorldRadiansFeet,
xyzWorldUnitRayDir,
5000.0f,
0.2f,
&ResObjID,
&xyzWorldRes,
interrogRes
);
However, no matter what values I put in the unit vector xyzWorldUnitRayDir, I get results which are very very close to the camera view LAT/LON/altitude.
I tried in all kind of views (virtual cockpit, outside view...). Is there a known issue with this function?
User avatar
Beau Hollis
Lockheed Martin
Posts: 2452
Joined: Wed Oct 06, 2010 3:25 pm

Re: Mouse click coords

Post by Beau Hollis »

You might be hitting the aircraft itself. I believe you can pass in an object id to exclude it.
Beau Hollis
Prepar3D Software Architect
JeeHell
Posts: 94
Joined: Sun Jan 15, 2012 11:04 pm

Re: Mouse click coords

Post by JeeHell »

Ok so I have been playing with the ray casting, and got it to work with a workaround.
The only way to make that work was to offset(by a very small distance such as 0.000001m) the LLA of the cast source to another position than the camera LLA itself, otherwise it would always hit something located on the same plane as the camera.
Even using the exclude ObjectID did not work (I tried many things...). So I think there is very probably an issue there.

On another note, using topdown view the GetFOV call returns bad data. I initially thought you were using an orthographic projection which would have made the FOVs undefined, but then the projection matrix still looked like a perspective matrix. I derived FOVs using that matrix, and I could compute correct FOVs.
Locked