gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > glRotatef / sqrtf32 issue and fix

#57464 - SevenString - Sun Oct 16, 2005 5:12 am

The "sqrtf32" function in LIBNDS/math.h returned incorrect results for me. The fix was to alter the function to shift-left (<<) by 13, NOT 12.

Normally, I tend to use tables, or avoid sqrts altogether when I can. But the problem that led to this discovery was that when using the libnds "glRotatef", the normalization function was not returning a unit vector. So I had to drill down to find the culprit.

I'm not sure if this is due to an emulation bug in iDeaS, or if this is an actual bug in libnds. To be honest, I'm too busy coding 3D stuff to bother drilling down into what the HW is actually doing vs. what the emulator may or may not be doing wrong.

However, if your 3D geometry is warping unpleasantly as you rotate, and you're using glRotatef, you might try altering sqrtf32 to use the << 13 trick. However, you'll need to rebuild the libnds source for this to work.

As a side note, many of the demos looked funky on the iDeaS emulator until I recompiled with this "fix".
_________________
"Artificial Intelligence is no match for natural stupidity."

#57469 - Lino - Sun Oct 16, 2005 6:32 am

Sincerely I haven't tried on the DS. It maybe a bug of iDeaS.

However in my emulator's source code I use 12 and not 13 for sqrtf32

#57524 - SevenString - Sun Oct 16, 2005 7:03 pm

Hey, Lino

Since I haven't yet purchased a flash-based devkit for my DS, I'm currently just working with your emulator. So AFAIK, it could very well be a bug in the libnds sqrtf32 routine and not your emulator. I don't know if sqrtf32 has the same behaviour on a real DS.

As a side note, your emulator seems to be working out quite well for me in this stage of my code development. My compliments on some nice work!
_________________
"Artificial Intelligence is no match for natural stupidity."