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 > glFrustumf32 bug

#140545 - a128 - Mon Sep 17, 2007 10:08 am

The latest libnds has a bug.

glFrustumf32 sets the MATRIX_MULT4x4 in a wrong order. The older version in libnds does this right.

from http://nocash.emubase.de/gbatek.htm#ds3dmatrixtypes

this is the order of the MATRIX_MULT4x4 operations ..so the old code does the setup correct.

m[0] m[1] m[2] m[3]
m[4] m[5] m[6] m[7]
m[8] m[9] m[10] m[11]
m[12] m[13] m[14] m[15]

Code:



//OLD CODE AND OK

   MATRIX_MULT4x4 = divf32(2*near, right - left);
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = divf32(right + left, right - left);
   MATRIX_MULT4x4 = 0;
   
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = divf32(2*near, top - bottom);
   MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
   MATRIX_MULT4x4 = 0;
   
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = -divf32(far + near, far - near);
   MATRIX_MULT4x4 = floattof32(-1.0F);
   MATRIX_MULT4x4 = 0;
   
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
   MATRIX_MULT4x4 = 0;
   


Code:


NEw CODE AND WRONG?!!!!!!

        MATRIX_MULT4x4 = divf32(2*near, right - left);
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = 0;
 
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = divf32(2*near, top - bottom);
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = 0;
 
   MATRIX_MULT4x4 = divf32(right + left, right - left);
   MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
   MATRIX_MULT4x4 = -divf32(far + near, far - near);
   MATRIX_MULT4x4 = floattof32(-1.0F);
 
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = 0;
   MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
   MATRIX_MULT4x4 = 0;





#140610 - wintermute - Tue Sep 18, 2007 7:39 am

And yet the bug report indicates that the old code was incorrect and the new code improves the compatibility with openGL.

I'm really not sure what to do with your report. What evidence do you actually have that the new code is wrong?

The orginal bug report with code showing the issue.

https://sourceforge.net/tracker/index.php?func=detail&aid=1758603&group_id=114505&atid=668551

Given that the new code produces the expected results for the previously broken sample and that all the libnds 3D example code displays appropriately I can't accept your assertion.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#140612 - a128 - Tue Sep 18, 2007 8:58 am

If the new code is correct..

then
http://nocash.emubase.de/gbatek.htm#ds3dmatrixtypes

is wrong.

I can not see that this spec is wrong because it`s the same with OpenGl

m[0] m[1] m[2] m[3]
m[4] m[5] m[6] m[7]
m[8] m[9] m[10] m[11]
m[12] m[13] m[14] m[15]

is the order where you apply your values

the new libnds glFrstum code have this order

m[0] m[4] m[8] m[12]
m[1] m[5] m[9] m[13]
m[2] m[6] m[10] m[14]
m[3] m[7] m[11] m[15]

#140615 - mml - Tue Sep 18, 2007 9:37 am

openGL's matrix functions take a one-dimensional array of 16 elements, which are then interpreted as a column-major 4x4 matrix. that's consistent with the new libnds code here; how the DS hardware does it I have no idea.

for example of how opengl does it, see the glMultMatrix docs here:
http://www.glprogramming.com/blue/ch05.html#id5509833


unless I'm much mistaken though (and I'll admit I could be, I'm new to this maths), the difference is mostly in how you conceptualise it, since a post-multiplication by a column-major matrix is the same as a pre-multiplication by the same matrix arranged row-majorly.

#140617 - a128 - Tue Sep 18, 2007 10:47 am

mml wrote:

for example of how opengl does it, see the glMultMatrix docs here:
http://www.glprogramming.com/blue/ch05.html#id5509833




Oh yes..I see glMultmatrix in OpenGl is in order

0 4 8 12
1 5 9 12
2 6 10 14
3 7 11 15


so wintermute is right..that the new glFrustum using glMultMatrix is now mutch more opengl conform.