#93523 - tciny - Wed Jul 19, 2006 6:10 pm
Hi,
I'm currently writing a viewer (on Windows/OSX) for checking files that were saved in a model format that I'm developing for the NDS.
Now, to save time, i store normals in the format that NORMAL_PACK returns already.
My problem now is: I want to get the v10 values out of there as floats again. I tried pretty long and hard, but I keep losing the sign. (Negative numbers like -0.5 appear as 1.5; very odd)
This is what I wrote so far:
#define v10tofloat(n) (((float)(n)) / (1<<9))
#define NORMAL_UNPACK_X(x) ((v10)((x) & 0x3FF))
#define NORMAL_UNPACK_Y(y) ((v10)(((y) >> 10) & 0x3FF))
#define NORMAL_UNPACK_Z(z) ((v10)((z) >> 20))
The corresponding defines from the devkit are
#define floattov10(n) ((v10)((n)*(1<<9)))
#define NORMAL_PACK(x,y,z) (((x)&0x3FF) | (((y) & 0x3FF)<<10) | ((z)<<20))
It works fine for positive numbers... any ideas where the problem might be?
Also: Am I correct when I think that values like 1.0 are very problematic as they occupy the same bit as the sign would? Right now, while exporing, I conver values like 1.0 to something like 0.999...
Any help is greatly appreciated! :)
I'm currently writing a viewer (on Windows/OSX) for checking files that were saved in a model format that I'm developing for the NDS.
Now, to save time, i store normals in the format that NORMAL_PACK returns already.
My problem now is: I want to get the v10 values out of there as floats again. I tried pretty long and hard, but I keep losing the sign. (Negative numbers like -0.5 appear as 1.5; very odd)
This is what I wrote so far:
#define v10tofloat(n) (((float)(n)) / (1<<9))
#define NORMAL_UNPACK_X(x) ((v10)((x) & 0x3FF))
#define NORMAL_UNPACK_Y(y) ((v10)(((y) >> 10) & 0x3FF))
#define NORMAL_UNPACK_Z(z) ((v10)((z) >> 20))
The corresponding defines from the devkit are
#define floattov10(n) ((v10)((n)*(1<<9)))
#define NORMAL_PACK(x,y,z) (((x)&0x3FF) | (((y) & 0x3FF)<<10) | ((z)<<20))
It works fine for positive numbers... any ideas where the problem might be?
Also: Am I correct when I think that values like 1.0 are very problematic as they occupy the same bit as the sign would? Right now, while exporing, I conver values like 1.0 to something like 0.999...
Any help is greatly appreciated! :)