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 > GFX_POS_TEST oddity

#149032 - DiscoStew - Sun Jan 13, 2008 9:59 pm

So, I began working on a new structure for a new model exporter (yes, different than my last one that I put on hiatus for now), and the meat of it involves directly editing a pre-made display list, so that it will work as a rigid-skinned model. The problem I've come up against is the testing phase for the structure in the program itself.

What it involves is Position Test, but the results I'm getting are somewhat off of what they should be. So I trimmed down everything just to see if what I put in coems out the same when used on an Identity matrix, and when I did, I did not get the same values as I put in.

Code:

glPushMatrix();
glLoadIdentity();
while(GFX_BUSY);
GFX_POS_TEST = 0 | (4096 << 16); // A simple test for putting in (0, 1, 0)
GFX_POS_TEST = 0;
while(GFX_STATUS & BIT(0));
iprintf("%04X, %04X\n", GFX_POS_RESULT[0], GFX_POS_RESULT[1]);
iprintf("%04X, %04X\n", GFX_POS_RESULT[2], GFX_POS_RESULT[3]);
glPopMatrix(1);


My results turned up...
Code:
0000, 175F
FFFFFCCE, 0000

Which is obviously not 0, 1000, 0, 0. When I put all 0s, I got...
Code:
0000, 0000
FFFFFCCE, 0000


Anyone know what I could be doing wrong? My "initial" set up of the 3D engine is the same as all my other projects, yet they've got no problem. I'm afraid it may be some silly oversight too.
_________________
DS - It's all about DiscoStew

#149056 - a128 - Mon Jan 14, 2008 9:49 am

What do you want to achive with your Postest?

For getting the distance to your camera do

Code:

    glPushMatrix();
    //1)  translate to position
    MATRIX_TRANSLATE = pos.X();
    MATRIX_TRANSLATE = pos.Y();
    MATRIX_TRANSLATE = pos.Z();

    //2) test against pos now at origin
    PosTest(0, 0, 0);

    Fixed  distanceZ = _FixedNum(PosTestZresult());
    glPopMatrix(1);
 

#149072 - DiscoStew - Mon Jan 14, 2008 6:50 pm

What I'm trying to achieve is direct editing to a display list, mainly so it will be able to act like a rigid-skinned model, except contain only as many glMatrixRestore commands as there are bones.

As you see in the little bit of code, I am practically starting with an Identity matrix, so that whatever I put in to the Position Test, I should receive back the same value. That isn't the case here though.

Looking at your code, it's basically what I'm doing in the example code I have, except you are translating prior to doing the Position Test. Testing it just for kicks, I am still getting values that are not the original.


EDIT:

And I think I found the culprit. Even if I start with the Identity Matrix in Modelview mode, unless I start with an Identity matrix in the Projection mode too, I won't get correct results. Still a little confused as to why my prior project wasn't having this same problem.

Considering I plan to wrap this up into a library, and that the Projection matrix only has 2 stacks for storing matrices, guess I'll have to make a copy of the current matrix, then do my editing, reload the matrix, and then let the display list do it's job. Don't want to do a Push/Pop on the Projection matrix, since people may be using that, and as said before, it only has 2 stacks.
_________________
DS - It's all about DiscoStew