#155721 - iljanated - Sat May 03, 2008 10:15 am
Hi,
this might sound silly , but anyway:
in videoGL.h it is suggested that vertices should be represented as "v16" , but in math.h, all the Dot, Cross, ... functions use "int32".
My question is: how should I store a 3DModel in memory? as v16 or as int32?
And if I store them as v16, should I convert them to int32 to use the mathfunctions , or will it work anyway?
Or should I use a completely other datatype?
Thx
(Years of messing with XNA / Shockwave / ... have made me forget all about the bits and bytes under the hood :-( )
#155724 - Maxxie - Sat May 03, 2008 10:31 am
It strongly depends what you would like to do with the model data.
If you require to do complex operations with some precission on the model, then you'll be more happy to use int or even more abstract datatyes (i.e. the (on the DS) very slow ieee 754 aka double/float)
If you are just feeding it to the 3d hardware with other hardware commands, use the hardware format, which is v16. Take a look at the DS display list format in this case.
Btw. allways keep in mind to not exceed the v16 limits (-8.0 till +7.***) when posting the data to the hardware, even if you use int.
#155727 - iljanated - Sat May 03, 2008 10:59 am
thx for the quick reply, I think I'll stick with the int32 since it's used in the matrix structs, GLvertex, math.h, ...
one more noob question: :-)
- how do I convert a float to int32 and then from int32 to v16?
Could you give an example with 7.999999999999f ?
#155728 - Maxxie - Sat May 03, 2008 11:14 am
This depends how you organize your int32.
Be 'fb' the number of fractional bits to use (representing the bits after the point) i.e. for a 16.16 organized int32 fb = 16, for a 8.24 its fb=24
float f ;
int32 i ;
v16 v ;
i = /* bits befor point */ ((int)f << fb) | /* bits after point */ ((int)(f * (1<<fb)) & ((2<<fb)-1)) ; // = (int)(f * (1<<fb))
v = fb>12?(v16)(i >> (fb-12)):(v16)(i << (12-fb)) ;
Note: there is a dataloss possible in each step
Afair (long time not used) there are conversation function in libnds already for the used v formats.
Last edited by Maxxie on Sat May 03, 2008 11:24 am; edited 1 time in total
#155729 - iljanated - Sat May 03, 2008 11:19 am
thx, I'm starting to understand, now there's still the matter of choosing a format that doesn't drive me into overflow problems , but I'm getting there :-)
#155734 - M3d10n - Sat May 03, 2008 4:30 pm
The int32 used by the math functions is 20.12 while the v16 is 4.12. You have the same amount of bits for the fractional parts.
So, if you call glVertex16() and pass int32's as parameter it work just the same as long as your values are within the [-8, 7.9997] range.
But, the main question is: what are you doing with your vertices? Usually on the DS you don't need to pass vertices to the math functions. It might be the case if you're soft-skinning a model or something, but even so I don't think you'd gain anything by storing all vertices using 32-bits instead of 16.
#155785 - iljanated - Sun May 04, 2008 6:53 am
I use the same faces/vertices for collision detection as for drawing / culling at the moment, though I'm going to replace them by bounding volumes later on, so I need dot/cross products and matrices
I'm now using the int32's and performance is acceptable as long as I don't run out of memory
the fixed point theory is slowly comming back ( last time I used them was more than ten years ago), thx for the help !