Skip to main content
gamedev.net
🔒 Locked

Reading Float from file

Started by Kumado 3 replies 750+ views
Original Post
Kumado
Kumado
Please help me before I got more nuts than already am. I am trying to read 4 byte float data from a MD2 file and I can't figure how to get the data straight. I have the file open fine and I can index to it but I am pulling my hair out to know how to read the data in to use it. fread? fgetc? fscanf? Thanks for any help in advance. Kumado
Zakwayda
Zakwayda
In C++, you can use a file stream object and the member function read(). In C, I suppose you use would fread(), as you mentioned.

You might take a look at this (remember to watch out for endian-ness issues).
Kumado
Kumado
Thanks for the reply. I did look at the lil eindian issue and it is in lil order.
What I did not add in my post with it there in my mind the whole time is that it must be IEEE format. The float to read first is ( in file order ) 00 00 3f 80.

I have been googleing for a bit but many c examples, well, I am probably old and such but I do not use classes and such, simple function calls no call::this->for me :(

I figure it must be a neg number since the high bit is set but I have a hard time finding info or understanding what I find.

ttfn

Kumado
Jerax
Jerax
That looks like it's a 1.0 float (0x3f800000), but the byte order is off if so, are you sure you're not offset wrongly or something?
Kumado
Kumado
Just need sleep, too many irons ....

it is 00 00 80 3f sorry.

Thanks for the reply - I have found more information and am beginning to see some connections, Thanks for all the help, I do apprec.

Kumado

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.