Welcome! Log In Create A New Profile

Advanced

Much ado about guMtxRotAxisDeg(....)

Posted by glennxserge 
Much ado about guMtxRotAxisDeg(....)
February 07, 2011 10:48AM
First off, the example code I am compiling is from nehe lesson6 with a few modifications for my own sake. I wanted to take the example of the rotating cube and experiment with setting up a camera that had yaw, pitch, and roll and keep the cube as a center reference point (for testing anyway).

Here is a snippet of code that I have regarding the rotation matrices. I just need a few things demystified

some declarations:
f32 camXRot = -45;
f32 camYRot = 0;

guVector aboutXAxis = {1,0,0};
guVector aboutYAxis = {0,1,0};

and the implementation :

guMtxIdentity(model);
guMtxRotAxisDeg(model, &aboutXAxis, camXRot);
guMtxRotAxisDeg(model, &aboutYAxis, camYRot);
		
guMtxTransApply(model, model, 0.0f, 0.0f, -8.0f);
guMtxConcat(view,model,modelview);
// load the modelview matrix into matrix memory
GX_LoadPosMtxImm(modelview, GX_PNMTX0);

Basically the camXRot and camYRot values are incremented through keypad input, and while x rotations seem to work, y rotations don't. If I comment out the x rotations then my y rotations start working. This makes me think there is some order/limit to specifying multi-axis rotations, but I don't know exactly what the guMtxRot function is doing. I have relatively no experience with matrices. So, although this may seem fundamentally simple, I don't know what the process is for multi-axis rotations. A nod in the right direction would be most appreciated.

Thanks
Re: Much ado about guMtxRotAxisDeg(....)
February 07, 2011 06:07PM
The guMtxRotAxisDeg function sets a rotation matrix, it does not multiply with the matrix (like glRotate does)

So you need to setup a 'temp' matrix for that.

Example:
    Mtx model, modelview;
    Mtx model2, model3;
    Mtx mrx, mry,mrz;

    guMtxIdentity(model);
    guMtxIdentity(model2);
    guMtxRotAxisDeg(model, &pitchAxis, pitch);
    guMtxTransApply(model, model, x, y, z);
    guMtxRotAxisDeg(mrx, &yawAxis, yaw2);
    guMtxRotAxisDeg(mry, &pitchAxis, pitch2);
    guMtxRotAxisDeg(mrz, &rollAxis, roll2);
    guMtxConcat(mrx,mry,mry);
    guMtxConcat(mry,mrz,model2);
    guMtxTransApply(model2, model2, x2, y2, z2);
    guMtxConcat(model,model2,model3);
    guMtxConcat(view,model3,modelview);
    // load the modelview matrix into matrix memory
    GX_LoadPosMtxImm(modelview, GX_PNMTX0);
Re: Much ado about guMtxRotAxisDeg(....)
February 09, 2011 02:12AM
And you probably want to rotate your matrix incrementally instead of storing rotation values and applying them as a whole. This is because it is not the same to rotate a matrix 10 degrees around Y, 10 around X and then again 10 about Y that rotating it 20 deg around Y and then 10 around X. The first aproach makes more sense "physically"
Re: Much ado about guMtxRotAxisDeg(....)
February 09, 2011 05:18AM
Daid:

Thanks a lot! That is exactly what I was looking for. I tried it out with a few modifications and it seems to do the job perfectly.

I was assuming that gu would have a wrapper for a glRotate type function, and the libogc doxygen documentation site only has a couple of these matrix functions listed so it is hard to know what they do. In any case you've just made my day.

Tecnik:

I'm not sure I follow what you are saying. Is choosing incrementing over storing my rotations a choice that comes down to desired behavior or is it more a matter of technical correctness? The code I have in place at the moment acts exactly how I want it to, but I want to make sure it is the correct way.



Edited 1 time(s). Last edit at 02/09/2011 09:32AM by glennxserge.
Re: Much ado about guMtxRotAxisDeg(....)
February 09, 2011 12:32PM
Quote
glennxserge
I was assuming that gu would have a wrapper for a glRotate type function, and the libogc doxygen documentation site only has a couple of these matrix functions listed so it is hard to know what they do. In any case you've just made my day.
I hardly use the doxygen from libogc. I found out how to work with gu/gx by looking at sources from different projects on wiibrew.org
Re: Much ado about guMtxRotAxisDeg(....)
February 11, 2011 12:37AM
wait @Daid I have a questio, so how do you know where the new top edge of your object is? Say for instance I draw a cude in GRRLIB and I rotate it by 45 degrees/radians on the Y. How do I find out the new coordinates of the corners? especially when it comes to collision detection.
Re: Much ado about guMtxRotAxisDeg(....)
February 11, 2011 10:30AM
You could use trigonometric functions to calculate the new points in 3D space.

I'm no expert in 3D collision detection, I always keep my games 2D, sometimes with 3D graphics.

If you want advanced 3D collision detection then bullet: [code.google.com] might help you.
Sorry, only registered users may post in this forum.

Click here to login