Jump to content
The simFlight Network Forums

Conversion problems ?


Recommended Posts

Hi Pete

Sorry for my bad English, i'm a young French student in computer science.

I use FSUIPC for my professional training, indeed i have to replace the old visualization program of a flight simulator (FlightGear) by Flight Simulator X.

For this work I use 2 Thread. The first thread receives data through a socket and the second write with FSUIPC.

The server converts data and send this one with the socket.

I use 32-bit PC and i have little problem of fluidity image. I think it's because of conversion.

Example of latitude :


int intLatB=0;
int intLatH=0;
double latB=0;
double latH=0;
double latitude;

// --------------------------------------------------------------------------------

latitude=latitude/(90.0/10001750.0);
latB=modf(latitude,&latH);
latB=latB*(65536.0*65536.0);

v=modf(latB,&latB);

intLatB=latB;
intLatH=latH;

( ... )

//Latitude
FSUIPC_Write(0x0560,4,&intLatB,&dwResult);
FSUIPC_Write(0x0564,4,&intLatH,&dwResult);

// --------------------------------------------------------------------------------
[/CODE]

This is correct? Or you have another idea?

Thank you in advance for your help and sorry again for my very bad English.

Regards,

Rémi

Link to comment
Share on other sites

I use 32-bit PC and i have little problem of fluidity image. I think it's because of conversion.

Your code seems only concerned with latitude. What anout altitude and longitude? You should write all three together, as one 24-byte block. Inside FSX they are just one structure. You should do the same, make a 3-element structure.

//Latitude

FSUIPC_Write(0x0560,4,&intLatB,&dwResult);

FSUIPC_Write(0x0564,4,&intLatH,&dwResult);

And in any case you should write this as one 8-byte integer. If your compiler doesn't support "long long" or 2_int64" types (64-bit integers), the make the one 64-bit value with a two DWORD array.

How often are you sending the data (FSUIPC_Process seds it)? You should try to equal the frame rate of FS, otherwise it will certainly be jerky.

Regards

Pete

Link to comment
Share on other sites

My code


double longitude;
double latitude;
double altitude;

int intLogB=0;
int intLogH=0;
double logB=0;
double logH=0;


int intLatB=0;
int intLatH=0;
double latB=0;
double latH=0;


int intAltH=0;
int intAltB=0;
double doubleAltH=0;
double doubleAltB=0;
double doubleAlt=0;



//Calcul altitude
doubleAltB=modf(doubleAlt,&doubleAltH);
intAltH=doubleAltH;
doubleAltB=doubleAltB*1000;
intAltB=doubleAltB;
//intAltB=5;

//Calculs longitude
longitude=longitude/(360.0/(65536.0 * 65536.0));
logB=modf(longitude,&logH);
logB=logB*(65536.0*65536.0);

v=modf(logB,&logB);

intLogB=logB;
intLogH=logH;

//Calculs latitude
latitude=latitude/(90.0/10001750.0);
latB=modf(latitude,&latH);
latB=latB*(65536.0*65536.0);

v=modf(latB,&latB);

intLatB=latB;
intLatH=latH;

( ... )

//Angles
FSUIPC_Write(0x0578,4,&intPitch,&dwResult);
FSUIPC_Write(0x057C,4,&intBank,&dwResult);
FSUIPC_Write(0x0580,4,&intHead,&dwResult);

//Latitude
FSUIPC_Write(0x0560,4,&intLatB,&dwResult);
FSUIPC_Write(0x0564,4,&intLatH,&dwResult);

//Longitude
FSUIPC_Write(0x056C,4,&intLogH,&dwResult);
FSUIPC_Write(0x0568,4,&intLogB,&dwResult);

//Altitude
FSUIPC_Write(0x0570,4,&intAltB,&dwResult);
FSUIPC_Write(0x0574,4,&intAltH,&dwResult);

FSUIPC_Process(&dwResult);
[/CODE]

You should try to equal the frame rate of FS, otherwise it will certainly be jerky.

I think I have solved this problem. But when I fly near the ground I see the plane moving from left to right in jerking. So I think the latitude, altitude and longitude are the problem.

And in any case you should write this as one 8-byte integer. If your compiler doesn't support "long long" or 2_int64" types (64-bit integers), the make the one 64-bit value with a two DWORD array.

Sorry but i don't understand everything, can you give me an example?

Thank you for your help,

Rémi

Link to comment
Share on other sites

//Angles

FSUIPC_Write(0x0578,4,&intPitch,&dwResult);

FSUIPC_Write(0x057C,4,&intBank,&dwResult);

FSUIPC_Write(0x0580,4,&intHead,&dwResult);

//Latitude

FSUIPC_Write(0x0560,4,&intLatB,&dwResult);

FSUIPC_Write(0x0564,4,&intLatH,&dwResult);

//Longitude

FSUIPC_Write(0x056C,4,&intLogH,&dwResult);

FSUIPC_Write(0x0568,4,&intLogB,&dwResult);

//Altitude

FSUIPC_Write(0x0570,4,&intAltB,&dwResult);

FSUIPC_Write(0x0574,4,&intAltH,&dwResult);

FSUIPC_Process(&dwResult);

Instead of all those separate FSUIPC_Writes (which will all be processed separately in FSUIPC!), make a structure for all 6 values, set up your structure, then write it all with one (1) FSUIPC_Write of 36 bytes. Otherwise each separate write is making a change in FSX. All the vlaues need to be written at once, in one structure.

Sorry but i don't understand everything, can you give me an example?

You don't understand what ppart? Structures? Or 64-bit types? Have you any documentation for your compiler or the language?

Pete

Link to comment
Share on other sites

Instead of all those separate FSUIPC_Writes (which will all be processed separately in FSUIPC!), make a structure for all 6 values, set up your structure, then write it all with one (1) FSUIPC_Write of 36 bytes. Otherwise each separate write is making a change in FSX. All the vlaues need to be written at once, in one structure.

I receive a structure with my socket, but how to write the FSUIPC_Write() ? With what offset ?

Have you any documentation for your compiler or the language?

Yes, but I can not translate everything. I use C for this work.

You think the conversion (altitude,latitude,longitude) are correct ? or not optimized ?

Thank you very much for your help

Link to comment
Share on other sites

I receive a structure with my socket, but how to write the FSUIPC_Write() ? With what offset ?

You must surely notice that the offsets for position and attitude, "LLAPBH" (Latitude-Longitude-Altitude-Pitch-Bank-Heading) are in a contiguous block of 36 bytes starting at offset 0560, so that is the offset and that is the size. Your structure will contain the 3 64-bit doubles and 3 32-bit integers.

Yes, but I can not translate everything. I use C for this work.

Unless you are using a very old compiler, most versions of C support 64-bit integers. -- "long long" or "int64" or "_int64" usually. Look up the data types your compiler supports. Check http://en.wikipedia.org/wiki/C_data_types for some hints.

You think the conversion (altitude,latitude,longitude) are correct ? or not optimized ?

I'm not checking your arithmetic for you, I'm just pointing out that messing with lower and upper halves of 64-bit integers is a bit daft when there will undoubtedly be provisions for 64-bit integer handling for you. You are just making it more complicated and messy, and therefore more prone to error. The main thing you need to do still is write them all together as one structure. How you prepare that structure is not really relevant to the optimum operation inside FS.

Pete

Link to comment
Share on other sites

Ok so my structure should look like


typedef struct Plane
{
int pitch;
int head;
int bank;

double lat;

double log;

double alt;
} Plane;
[/CODE]

long long or double for altitude, longitude and latitude ?

And if I use long long (my compiler can) how can I convert double in long long ?

Sorry but I do not understand everything I'm a beginner ...

Thank you so mutch for all,

Rémi

Link to comment
Share on other sites

Ok so my structure should look like


typedef struct Plane
{
int pitch;
int head;
int bank;

double lat;

double log;

double alt;
} Plane;
[/CODE]

No, no, no. You are not referring to the offsets list!

(a ) you have the order incorrect! Your structure MUST match the memory layout in the offsets, else every value will be wrong! Can't you see that?

(b ) the 64-bit values are NOT "doubles" but 64-bit Integers as I keep telling you! Why are you ignoring what I tell you? This is getting frustrating! :sad:

long long or double for altitude, longitude and latitude ?

I already told you several times, and gave you references! Why don't you use the Offsets list in the SDK documentation?

And if I use long long (my compiler can) how can I convert double in long long ?

How did you manage to convert a double into two ints? What's the difference apart from the fact that a 64-bit integer can accommodate the whole value in one instead of splitting it? Just add 0.5 to round to the nearest integer and then simply assign it -- with a cast if you want to avoid compiler warnings about loss of precision.

Questions about simple programming should really lead you to a programming book. I'm not very good at teaching people to program. You really need to learn it first. Sorry.

Pete

Link to comment
Share on other sites

Thank you for your answers Pete. And sorry but i don't ignore you, I have difficulty to translate into French.

Okay. Sorry that I don't speak French. We can only talk in C then? <G>

But now i understand better.

Hope so. Please do check against the Offsets document. That's the prime reference.

Regards

Pete

Link to comment
Share on other sites

Hi Pete,

Last question please, I need to change the weather. Can I use FSUIPC for that or use another interface ?

If possible handle it from another computer with socket.

Thank you for all,

Rémi

Link to comment
Share on other sites

Last question please, I need to change the weather. Can I use FSUIPC for that or use another interface ?

There are three weather interfaces in FSUIPC, dating from different versions and periods of FS itself, each with more sophistication than the previous one.

The original FS98/FS2000 weather control interface is that listed in the Offsets lists in the area ranging from 0F1C onwards. This offers crude control and with global weather only.

Then there's a "command based" weather control which was implemented in FS2002 days. This is documented separately in the FSUIPC SDK, and is called the "Advanced Weather Interface" (AWI).

The best and easiest to use since FS2004 (FS9) days is the "New Weather Interface" (NWI), which is partially documented in the Offsets lists (see offsets C000 to CFFF), but mainly in the separate ZIP for it in the SDK. This latter interface is used by Active Sky on FS9.

There are two demonstration programs provided: WeatherSet.exe which uses the AWI, and WeatherSet2.exe which uses the NWI. The former is really now resundant.

With FS9 and before there really isn't any alternative to FSUIPC for program control over the weather, but in FSX and Prepar3D you can, of course, use SimConnect directly instead if you wish. Active Sky for FSX uses SimConnect directly, and so does REX. FSUIPC4's NWI interface is effectively a backwards-compatible interface for FSX's SimConnect weather facilities.

Regards

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.