Codesnippets > 3D-snippets

X_MULTMATRIX

(1/1)

Hemlos:

--- Code: (glbasic) ---DIM mat
mat[0..3] = forward (local x-axis) (x,y,z,0)
mat[4..7] = local up (x,y,z,0)
mat[8..11]=local right (x,y,z,0)
mat[12..16]=translation (offset) from origin (x,y,z,1)

X_MULTMATRIX mat[]
--- End code ---
If you want to use X_ROTATION and stuff, too - use the X_PUSHMATRIX before X_MULTMATRIX.

*quoted from gernot*

--- Quote ---Note from Hemlos:
Im currently working with this new command and will update this in more detail as i get more information.
--- End quote ---

Kitty Hello:
Create rotation/translation matrix:

--- Code: (glbasic) ---// Roll, Pitch, Yaw, Translate
FUNCTION BuildMatrix: ry, rz, rx, x, y, z, M[]
LOCAL sa,sb,sc, ca,cb,cc
LOCAL sacb, cacb
DIM M

//LOCAL a[], B[], C[]
// NewtonRollMatrix (rx, a[])
// NewtonPitchMatrix(ry, B[])
// NewtonMultMatrix(a[], B[], C[])
// NewtonYawMatrix  (rz, a[])
// NewtonMultMatrix(a[], C[], M[])
// M= x
// M= y
// M= z

ca       = COS(-ry);
sa       = SIN(-ry);
sb       = COS(rz);
cb       = SIN(rz);
cc       = COS(-rx);
sc       = SIN(-rx);

sacb=sa*cb
cacb=ca*cb

M  =   sb * cc;
M  =  -sb * sc;
M  =  -cb;

M  = -sacb * cc + ca * sc;
M  =  sacb * sc + ca * cc;
M  =  -sa * sb;

M  =  cacb * cc + sa * sc;
M  = -cacb * sc + sa * cc;
M =   ca * sb;

M= x
M= y
M= z
M= 1;
ENDFUNCTION
--- End code ---

Hemlos:
interesting, and doesnt gimbal lock..but it rotates like x_rotation still, minus the gimbal..

This method works with 2 axes that are fixed to the world and one to the object.