Bisschen Mathe ;)

Previous topic - Next topic

Tenorm

so:

Code (glbasic) Select
FUNCTION NewtonBuildMatrix: 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


und jetzt das ganze R?ckw?rts (heist: ich m?chte aus M[16] wieder rotationen machen), y-rotation is ja noch einfach, aber irgendwie komm ich bei x- und z-rotation nicht durch, bleib i.wie bei sb h?ngen weil das von cc abh?ngig is und umgekehrt  :S
aber  :x, ihr seit dran!

Danke!

Kitty Hello

Code (glbasic) Select

//! Get the euler angles from an OpenGL matrix
// \param m[] - the matrix
// \param rx - [out] the rotation around the x axis
// \param ry - [out] the rotation around the y axis
// \param rz - [out] the rotation around the z axis
FUNCTION EntityGetEulers: mat[], BYREF X, BYREF Y, BYREF Z
// roll = rx
// yaw = ry
// pitch = rz

LOCAL rotx, roty, C

    Y = -ASIN(mat[2])
    C = COS(Y)

    IF ABS(C)>1e-7
            LOCAL invC = 1.0/C
            rotx = mat[10] * invC
            roty = mat[6]  * invC
            X = ATAN( roty, rotx )
            rotx = mat[0] * invC
            roty = mat[1] * invC
            Z = ATAN( roty, rotx )
    ELSE
            X = 0.0
            rotx =  mat[5]
            roty = -mat[4]
            Z = ATAN( roty, rotx )
    ENDIF
ENDFUNCTION

Tenorm

#2
Danke!