Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi guys,

Im still having a problem with the heading equation for offset 0580.

Code snippet below...

var
 heading : DWord;
begin
 FSUIPC_Read($0580, 4, @heading, dwResult);
 Hdg.Caption := FloattoStr(heading*360/(65536*65536))+'º';
end;

Its the only problem i seem to be having and it looks simple in the programmers guide.

Any help?

Cheers

Mick.

Posted

Hi again,

Never mind, I worked it out.

Hdg.Caption := CurrtoStr(heading*360.0/(65536.0*65536.0))+'º';

Then I just did the TRUE to MAG conversion and all is now fine.

Cheers,

Mick

Posted

FSUIPC_Read($0580, 4, @heading, dwResult);

Hdg.Caption := FloattoStr(heading*360/(65536*65536))+'º';

[/code]

Its the only problem i seem to be having and it looks simple in the programmers guide.

You really need to try using FSInterrogate. It can help clarify most of these sorts of misunderstanding. That's why it is provided.

You are correctly reading the 32-bit (4-byte) heading into an unsigned integer variable (at least, that's how I assume Dword is defined?). But this is fixed point, not floating point. What does your "FloattoStr" do when fed with a fixed point number?

Try converting the heading to a double floating point value first. In C this can be done automatically by:

(heading*360.0)/(65536.0*65536.0)

The ".0" bits make all the difference, in C at least. I assume you are using VB, so I'm not really sure what will be happening in the code you are showing.

Also, I always like to be explicit with parentheses. In C I know the multiplication will be done first anyway, but will it be so in VB? If not you are actually multiplying by zero: 360/(65536*65536) is zero in fixed point. It is possible that the compiler is optimising the code and converting the 360/(65536*65536) part even before you get to run the code.

Regards,

Pete

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.