rotating on world axis

Previous topic - Next topic

Richard Rae

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

Schranz0r

i think, multimatrix can fix it !?
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

yes. Multmatrix. Search the forum for "gimbal lock"

Richard Rae

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.

Kitty Hello

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