PDK GetScreenCoord() trouble

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
raxter78
Posts: 1
Joined: Sun Jan 15, 2017 4:44 pm

PDK GetScreenCoord() trouble

Post by raxter78 »

Hello,
it seems that the GetScreenCord overload that supports lla and pbh parameters:

Code: Select all

void GetScreenCoord(
    const double lla[3], 
    const float pbh[3],
    const float xyzOffset[][3],
    float xyOutput[][3],
    const int count 
)
doesn't work as expected.

Although the basic GetScreenCord overload without lla/pbh parameters (that uses user sim object as reference) works fine, using instead the other call with lla and pbh set the same as the current user position/rotation does not return the same results in xyOutput.

Maybe someone can confirm that?
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: PDK GetScreenCoord() trouble

Post by Clifton Crane »

Hello,

We believe there is an issue regarding the coordinate conversion of the given orientation. We have opened a ticket to address the issue.

Thanks.
Clifton Crane
Prepar3D® Software Engineer Sr.
User avatar
Beau Hollis
Lockheed Martin
Posts: 2452
Joined: Wed Oct 06, 2010 3:25 pm

Re: PDK GetScreenCoord() trouble

Post by Beau Hollis »

The pbh value is being converted incorrectly. This function can still be used with the PBH and XYZ set to zero, and it should give you a valid screen coordinate for a given LLA. I suspect this is how must developers have been using it since this bug has been around since v2. The good news is, there is a workaround. If you need to calculate an LLA based on the body relative offset from an LLAPBH, you can do that using IObjectRenderer::ApplyBodyRelativeOffset (a new PDK interface added in 3.4 and used in the custom lights sample).

Code: Select all


struct LLADegreesMeters
{
    double Latitude;
    double Longitude;
    double Altitude;

    LLADegreesMeters() : Latitude(0.0), Longitude(0.0), Altitude(0.0) {}
    LLADegreesMeters(double latitude, double longitude, double altitude)
        : Latitude(latitude), Longitude(longitude), Altitude(altitude) {}
};

struct PBHDegrees
{
    float Pitch;
    float Bank;
    float Heading;

    PBHDegrees() : Pitch(0.0f), Bank(0.0f), Heading(0.0f) {}
    PBHDegrees(float pitch, float bank, float heading)
        : Pitch(pitch), Bank(bank), Heading(heading) {}
};

struct XYZMeters
{
    float X;
    float Y;
    float Z;

    XYZMeters() : X(0.0f), Y(0.0f), Z(0.0f) {}
    XYZMeters(float x, float y, float z) : X(x), Y(y), Z(z) {}
};

struct ObjectLocalTransform
{
    XYZMeters XYZ;
    PBHDegrees PBH;

    ObjectLocalTransform(){}
    ObjectLocalTransform(float x, float y, float z, float pitch, float bank, float heading)
        : XYZ(x, y, z), PBH(pitch, bank, heading) {}
};

struct ObjectWorldTransform
{
    LLADegreesMeters LLA;
    PBHDegrees PBH;

    ObjectWorldTransform(){}
    ObjectWorldTransform(double latitude, double longitude, double altitude,
        float pitch, float bank, float heading)
        : LLA(latitude, longitude, altitude), PBH(pitch, bank, heading) {}
};

/**
* Service for rendering lights into a view 
*/
DECLARE_INTERFACE_(IObjectRenderer, IUnknown)
{
    /**
    * Add a light to the group
    */
    virtual HRESULT AddLight(float x,
                             float y,
                             float z,
                             unsigned int lightType, 
                             unsigned int color,
                             float size, 
                             float range, 
                             bool bAttenuateByAmbient) abstract;

    /**
    * Begin a light group with na origin at the LLA provided
    */
    virtual HRESULT BeginLightGroup(ObjectWorldTransform& groupOrigin) abstract;

    /**
    * End a light group.
    */
    virtual HRESULT EndLightGroup(bool sortGroup) abstract;

    /**
    * Applu body relative local transformation to a world transform
    */
    virtual void ApplyBodyRelativeOffset(const ObjectWorldTransform& llapbhAtOrigin,
                                         const ObjectLocalTransform& offsetXyzPbh,
                                               ObjectWorldTransform& llapbhAtOffset) abstract;

    /**
    * Calculate body relative offset between two world transforms
    */
    virtual void CalculateBodyRelativeOffset(const ObjectWorldTransform& llapbhAtOrigin,
                                             const ObjectWorldTransform& llapbhAtOffset,
                                                   ObjectLocalTransform& offsetXyzPbh) abstract;
};

See IRenderingService.h and the custom lights sample for more details.
Beau Hollis
Prepar3D Software Architect
virtuali
Posts: 598
Joined: Tue Sep 27, 2011 12:51 pm

Re: PDK GetScreenCoord() trouble

Post by virtuali »

Thank you for having fixed this in the new Hotfix.

I can confirm your proposed solution work so, we adapted our code to use the workaround if the sim version is at least 3.4, and to use the updated "good" API directly, if the build is >= 19868, since I guess the latter it's faster.
Umberto Colapicchioni - VIRTUALI Sagl
http://www.fsdreamteam.com
Locked