GLBasic forum

Main forum => GLBasic - en => Topic started by: Richard Rae on 2007-Nov-11

Title: rotating on world axis
Post by: Richard Rae on 2007-Nov-11
Hi.I am getting along quite well with my programme but have hit a problem.I am having a problem with rotations.I assume GL basic uses euler
angles for rotation and therein,I think,lies the problem.The programme I am doing simulates a rubick's cube..If you rotate one face only everything rotates fine,but,if you then rotate another face everything gets mixed up.Is there any way to fix the pivot of an object so that it always rotates about it's world axis.
A zip file can be downloaded from here.---//www.rrae.pwp.blueyonder.co.uk/rubick.zipPress space and move the mouse to rotate the entire cube,click on the highlighted cube to rotate face(only the side faces rotate at present
Title: rotating on world axis
Post by: Schranz0r on 2007-Nov-11
i think, multimatrix can fix it !?
Title: rotating on world axis
Post by: Kitty Hello on 2007-Nov-11
yes. Multmatrix. Search the forum for "gimbal lock"
Title: rotating on world axis
Post by: Richard Rae on 2007-Nov-11
Searched for gimbal lock and found only 2 hits(1 was my question and one by Hemlos).The documentation is not very clear,could you please post an example showing in more detail how to use this command.
Title: rotating on world axis
Post by: Kitty Hello on 2007-Nov-12
Code (glbasic) Select
LOCAL M[]
BuildMatrix(RotoX, RotoY, RotoZ, MoveX, MoveY, MoveZ, M[])
X_PUSHMATRIX
   X_MULTMATRIX M[]
   X_DRAWOBJ 0,0
X_POPMATRIX
SHOWSCREEN


FUNCTION BuildMatrix: rx, ry, rz, x, y, z, M[]
LOCAL sa,sb,sc, ca,cb,cc
LOCAL sacb, cacb
DIM M[16]
    ca       = COS(-rx);
    sa       = SIN(-rx);
    sb       = COS(ry);
    cb       = SIN(ry);
    cc       = COS(-rz);
    sc       = SIN(-rz);

sacb=sa*cb
cacb=ca*cb

    M[0]  =   sb * cc;
    M[1]  =  -sb * sc;
    M[2]  =  -cb;

    M[4]  = -sacb * cc + ca * sc;
    M[5]  =  sacb * sc + ca * cc;
    M[6]  =  -sa * sb;

    M[8]  =  cacb * cc + sa * sc;
    M[9]  = -cacb * sc + sa * cc;
    M[10] =   ca * sb;

M[12]= x
M[13]= y
M[14]= z
    M[15]= 1;
ENDFUNCTION