I am working on my first open gl es app and I have a question that may be something I have over looked.
If I am using GLfixed and I want to have a float value like 1.0056 I am not able to do my normal shifts on it. Right now I am basically saying take the whole 1 and the dec 0056 and do the shifts to make them a fixed float. But, of couse the 0056 truncates down to 56 which totaly messes everything up. Is it possible to have decimal values that start with 0’s?
Of couse any help would be appreciated. If I come up with anything I’ll also update this post.
You convert a float to fixed by multiplying by 65536.
#define FLOATTOFIX(x) (x * (1<<16))
or this may work as well
#define FLOATTOFIX(x) (x * 65536)
Convert a fixed back to float - divide by 65536
#define FIXTOFLOAT(x) (x / (1 << 16))
#define FIXTOFLOAT(x) (x / 65536)
You might want to look into fixed point maths. The following site is a good starting point http://gameprogrammer.com/4-fixed.html
Thanks for the reply gautam. The thing I’m stuck on is that I’m working in BREW and we dont have floating point numbers so I cant say:
FLOATTOFIX(0.002) (0.002 * (1<<16))
because the 0.002 gets truncated down to 0 which wont work at all.
The best I’ve managed to do was go from 0.0001 to 0.9999 and do that number as an int 0.0001 = 1 * 1<<16, and that works roughly but I still have bad truncation going on.
UPDATE : I was going to post this reply and it sat in the background for like 3 hours but I finally figured out my problem. It wasn’t a problem at all with my floats. It was a problem with my model loading. The first value of every matrix was ignoring if it was negative or not. Such an easy fix for such a stressfull night, but I guess thats how it goes.
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.