How to switch to AI traffic views (via SimConnect)?

Discuss on the SimConnect SDK can be used by programmers to write add-on components for Prepar3D
Locked
kwb
Posts: 10
Joined: Tue Aug 28, 2012 9:16 pm

How to switch to AI traffic views (via SimConnect)?

Post by kwb »

When I add AI traffic I have views for each aircraft under "AI traffic". How can I switch to that view from SimConnect. Adding AI like this:

Code: Select all

const HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, qPrintable(modelString), qPrintable(callsign.toQString().left(12)), initialPosition, requestId);
gives me something like the "model description" + callsign as menu entry, e.g. "COMMERCIAL JET - DAMBZ". I have tried to switch to that view by "building" that string

Code: Select all

const QString viewName = "Commercial Jet-" + callsign.asString();
const char *view = viewName.toLatin1().constData();

HRESULT hr = SimConnect_ChangeView(m_hSimConnect, view);
I have tried some permutations like "callsign only", spaces around the "-" (hyphen/dash) etc. Does anybody know how what would be correct or even better how to obtain the correct view name at runtime?
obinder
Posts: 145
Joined: Sun Jun 08, 2014 9:43 am

Re: How to switch to AI traffic views (via SimConnect)?

Post by obinder »

The Ai aircraft that you created cannot be called with a view name.
The "view name" in the method that you are using would be the camera definition looking at the AI. By default that is "AI Planes", category "Airtraffic", and the individual aircraft are "sub views" of that camera definition (so to speak).

I have already implemented this in two of my commercial and one freeware product, and from my experience this still requires complex logic. Expect a significant effort until you find a suitable method. There is still hope that this will be made easier in one of the next simulator versions.

Make sure to take a look at the Observers too. That logic is very powerful and might fill your need.

Best regards
Oliver Binder
Lorby-SI
kwb
Posts: 10
Joined: Tue Aug 28, 2012 9:16 pm

Re: How to switch to AI traffic views (via SimConnect)?

Post by kwb »

Thanks for the info. I was wondering if there is a workaround which makes it possible to read all P3D menu entries and trigger those.
obinder
Posts: 145
Joined: Sun Jun 08, 2014 9:43 am

Re: How to switch to AI traffic views (via SimConnect)?

Post by obinder »

If I had to do it again, and knew that is was only for P3D v4.x, I would just read all the AI traffic with SimConnect as usual, and when the user selects a particular aircraft, create an Observer that is attached to the AI and looking at it. To move the camera I would implement my own controls, and adjust the attachment point on the target according to the users actions.

Check the Learning Center -> SDK -> SimConnect API -> References -> View Functions -> Observer Specific Functions

Best regards
Oliver Binder
Lorby-SI
Locked