#106809 - silent_code - Mon Oct 23, 2006 5:43 pm
hi!
now, i've messed a bit with the whole thing (matrices) but i can't find any way to retrieve the current modelview matrix - there is a GL_GET_MATRIX_PROJECTION define for the projection matrix and a GL_GET_MATRIX_ROTATION define, but i don't see a modelview matrix, except in the matrix modes.
so, how can it be done? can it be done? is there a function or do i have to access the hw directly (write my own function)?
thanks in advance for your help.
#106813 - DiscoStew - Mon Oct 23, 2006 6:52 pm
I've asked this question some time ago, and supposably you get them as an array from those places in memory. However, I've been unsuccessful in doing so, and since I can't check on hardware, I'm not sure if it is just my code, or the emulator, since all I ever get are 0s. Because of this, I have been doing all my matrix math manually rather than trying to use hardware.
I would like to also know the correct way to grab data from these too. I'd much rather let hardware do it, as it is faster.
_________________
DS - It's all about DiscoStew
#106821 - silent_code - Mon Oct 23, 2006 7:34 pm
as soon as i get my hw back i'll see what i can find.
getting the memory area that holds the values and reading them back shouldn't be too hard. i mean you can *write* to it...
if you posted your code, i could test it for you. you could also post a .nds file.
then i'll let you know if it works.
#106844 - Rajveer - Tue Oct 24, 2006 2:49 am
so let me get this straight: performing your own matrix calculations is more costly than using the implemented glTranslate and glRotate functions, because these functions make use of the hardware compared to if i were to just do my own matrix calculations? arent these functions just glMultMatrix e.t.c defines themselves? (which in turn are just mulf32 defines no?)
oh and im pretty sure it IS the GL_GET_MATRIX_ROTATION command that you want (unless you want the whole 4x4 matrix as opposed to the 3x3 rotation matrix
#106848 - DiscoStew - Tue Oct 24, 2006 3:52 am
Rajveer wrote: |
so let me get this straight: performing your own matrix calculations is more costly than using the implemented glTranslate and glRotate functions, because these functions make use of the hardware compared to if i were to just do my own matrix calculations? arent these functions just glMultMatrix e.t.c defines themselves? (which in turn are just mulf32 defines no?)
oh and im pretty sure it IS the GL_GET_MATRIX_ROTATION command that you want (unless you want the whole 4x4 matrix as opposed to the 3x3 rotation matrix |
Well, for the things I'm trying to do now, I feel that letting the hardware do the calculations would be better than me doing them manually with my own routine (which is just normal multiplying without extensive optimizing), because I can make use of Pushing/Popping the matrices, plus I hear that matrix multiplying on hardware is faster in terms of cycles spent from supposably being able to do multiple multiplications at one time. Only major reason why I use my own matrix math functions is because I can't get the active matrix from hardware. The GL_GET_MATRIX_PROJECTION register array keeps giving me 0s.
The hardware has such registers like MATRIX_MULT4x4, that after being written 16 times to it (a 4x4 matrix), it multiplies what you give it with what its active matrix is.
_________________
DS - It's all about DiscoStew
#106954 - silent_code - Wed Oct 25, 2006 6:21 am
well, i don't want the rotation matrix, i want the modelview matrix... and that's a 4x4 matrix including rotation and translation... a plain rotation matrix is pretty useless to me right now. i think i made that clear in the other post...
@ds: so, do you want me to test your stuff on hw?
#107032 - DiscoStew - Wed Oct 25, 2006 8:54 pm
silent_code wrote: |
well, i don't want the rotation matrix, i want the modelview matrix... and that's a 4x4 matrix including rotation and translation... a plain rotation matrix is pretty useless to me right now. i think i made that clear in the other post...
@ds: so, do you want me to test your stuff on hw? |
I'm not even sure if how I'm grabbing stuff is even correct. Would this be correct? (I'm at work right now, so I had to think up a quick example off the top of my head)
Code: |
f32 grabMatrix[16];
GLvector bleh = {4096, 4096, 4096}; // equals 1 unit in the x, y, and z direction
int i = 0;
// Reset the screen and setup the view, blah blah blah
// then
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
//Just to change the matrix so we don't have all 0s....hopefully
glTranslatev(&bleh);
for ( ; i < 16; i++ )
grabMatrix[i] = GL_GET_MATRIX_PROJECTION[i];
glPopMatrix(1);
//Print matrix values to screen
|
Set to the modelview, push matrix, translate matrix, grab matrix values, pop matrix, then print recorded matrix values. This is just about how my basic test for trying to get the active matrix is like, but all I get are 0s on the emulators, no matter what I do to the active matrix. The actual test I have for trying to do this was with my Rigid Bones demo, but because I wasn't getting anywhere with the 0s, I made my own matrix math functions so I could retrieve those values. If my example code above is correct in how to get the values, or the correct method is shown, then I'll reset my demo to use this, and then I can send ya the new build for you to test on hardware, silent_code.
_________________
DS - It's all about DiscoStew
#107045 - silent_code - Wed Oct 25, 2006 10:56 pm
well, there's the function
Code: |
void glGetFixed(GL_GET_TYPE param, fixed* f); |
[\include\nds\arm9\videoGL.h : line 618]
you can pass it "GL_GET_MATRIX_PROJECTION" (this is just an enumeration, so you can't access it as there's no data!!! it's more like "#define GL_GET_MATRIX_PROJECTION 3" - that isn't a register!) [line 302] for param and an array[16] of "fixed"s where the matrix should go. as far as i understand that, this is it, you should have your matrix now.
i'm still wondering if the mx hw can be used for any 4x4 / 3x3 mx calcs... that would require to have access to a modelview mx.
now what i have though about is, that you can load the indentity mx after the reset. then ([possibility] 1) if the projection mx was the identity mx, do your mx math, read back the projection mx, reset it and do all your graphics stuff or (2) if the proj mx was the *real* proj mx (that means it had viewing transformations in it, e.g. like the frustum) just save it, do your math and then multiply your result by the transpose of the former proj mx. that would give you the values without any viewing stuff (there would be some rounding error, though). [if this is BS, tell me and i'll correct it.]
i assume the 1st path is more likely to be the real thing and thus we wouldn't need any additional modelview mx. just calc your stuff, then load the identity mx and set the projection transforms.
i don't have any code (yes, i messed with the nds' hw matrices, but i didn't write any line of code), so you'd have to try it out.
it was nice of you sharing this piece of code if it worked! ;) and seeing your demo running on hw would definitely be kick ass! bones sound cool :D [actually that's what i want to use it for, too ;p ]
greets!
#107047 - DiscoStew - Wed Oct 25, 2006 11:25 pm
Well, I already have my little demo up on the DS Misc section, but that is using my own matrix routines, not the hardware. It's just the demo and a few pics though. Don't worry about the background looking green, as that is what it was supposed to do.
EDIT:
Heh, I just got home, and in my code, I used GL_GET_MATRIX_PROJECTION, when I meant to use MATRIX_READ_PROJECTION. I was at work, and I couldn't remember the actual name, but the latter is what I tried using.
I tried that function, but on Dualis, I get 0s still. =(
_________________
DS - It's all about DiscoStew
#107087 - silent_code - Thu Oct 26, 2006 12:14 pm
then send it over. ;)
pm me.
#107127 - DiscoStew - Thu Oct 26, 2006 10:48 pm
My demo (or should I say "visual demonstration") is here, but like I said before, that is using my own matrix math functions to get the matrix, not getting from hardware, and my purpose is to grab the matrix from hardware.
I just can't continue trying this out unless I know what I'm doing is correct. The method to get the matrix looks very simple, but unless I have proof that that is the way to get it, building my demo now using it is a waste of time. Emulators aren't giving me squat because it is either I am doing it wrong, or the feature to get the matrix is unimplemented in them. If it is just unimplemented, that will at least tell me that I can continue, and that I can move over to grabbing from hardware once either the emulators implement it, or I can test on hardware myself.
Anyone have their own project that uses this feature that could tell me if it is correct, or could tell me how to correctly get the matrix?
_________________
DS - It's all about DiscoStew
#107162 - silent_code - Fri Oct 27, 2006 9:12 am
... i have tried your sw mx demo before my last post ;p i just thought that this is such a small change that you could just build a demo and send it over for testing...
ok, then i'll have to write my own test. i'll post here as soon as i get some results (may take a while - depends on how much other stuff i have to do).
#107276 - DiscoStew - Sat Oct 28, 2006 4:35 am
Well, I decide to head over to the forums of Dualis, and asked 'mic', the author of Dualis, about that. He says that the address for MATRIX_READ_PROJECTION is the correct place to grab the matrix. It's just Dualis does not support it, and I also believe other emulators that I've tested with don't have that either as the same results are retrieved.
So, what I may do is have both the sw matrix math and hardware implementation, and have a single button switch between the two for testing purposed.
_________________
DS - It's all about DiscoStew
#107283 - tepples - Sat Oct 28, 2006 5:53 am
Or you could make a demo that displays a photo of Carrie-Anne Moss as Trinity from The Matrix with that green code behind her when run on hardware, and "YOUR EMULATOR SUCKS!" when run on emulators that don't support reading back the model-view matrix. Then spread this demo as a test case.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#107287 - DiscoStew - Sat Oct 28, 2006 7:00 am
tepples wrote: |
Or you could make a demo that displays a photo of Carrie-Anne Moss as Trinity from The Matrix with that green code behind her when run on hardware, and "YOUR EMULATOR SUCKS!" when run on emulators that don't support reading back the model-view matrix. Then spread this demo as a test case. |
lol, perhaps have it load the Identity Matrix, and right afterwards if what is read are 0s, have that display? I gotta get me a compatible wireless card just to try that out. =D
_________________
DS - It's all about DiscoStew
#107308 - Rajveer - Sat Oct 28, 2006 1:01 pm
hold up, i thought u wanted the modelview matrix. so why are you trying to get the projection matrix?
#107309 - silent_code - Sat Oct 28, 2006 1:10 pm
tepples wrote: |
Or you could make a demo that displays a photo of Carrie-Anne Moss as Trinity from The Matrix with that green code behind her when run on hardware, and "YOUR EMULATOR SUCKS!" when run on emulators that don't support reading back the model-view matrix. Then spread this demo as a test case. |
THAT'S GOLD, tepples! *LOL*
#107335 - DiscoStew - Sat Oct 28, 2006 5:48 pm
Rajveer wrote: |
hold up, i thought u wanted the modelview matrix. so why are you trying to get the projection matrix? |
I think what's confusing is the naming convention used for that particular area of memory. According to GBATEK, that location is called CLIPMTX_RESULT, of which, if I understand correctly, can read both the projection matrix and the modelview matrix from that place. To distinguish the two though, my assumption is that using glMatrixMode changes what is read from there, just like how using glMatrixMode allows changes to be made to either the projection or modelview matrix.
_________________
DS - It's all about DiscoStew
#107487 - Rajveer - Mon Oct 30, 2006 3:32 am
ahh right, makes sense. cheers for the explanation :)
#107513 - Ted - Mon Oct 30, 2006 12:19 pm
Slightly late to the party, but i tried throwing together a small test for reading the model matrix from the 3d hardware,
and as far as i can tell, it works nice on hardware but not in emulators, they just return zeroes like everyone has said.
(tried with dualis and desmume, probably not the latest versions though)
Code: |
// array to store the matrix in
fixed matrixData[16];
// switch to projection matrix and save it
glMatrixMode(GL_PROJECTION);
glPushMatrix();
// load identity matrix so we get the modelview matrix when reading
glLoadIdentity();
// wait for 3d-engine to finish before reading
while(GFX_STATUS & BIT(27));
glGetFixed(GL_GET_MATRIX_PROJECTION, matrixData);
// restore original projection matrix
glPopMatrix(1); |
If you want to read the projection matrix instead, just change GL_PROJECTION to GL_MODELVIEW.
#107530 - DiscoStew - Mon Oct 30, 2006 4:02 pm
It's goodto have multiple confirmations. =)
_________________
DS - It's all about DiscoStew
#107546 - silent_code - Mon Oct 30, 2006 7:22 pm
OH, that'S nice :)
thanks, it helpes a lot! :D