GLBasic forum

Main forum => GLBasic - en => Topic started by: Richard Rae on 2008-Nov-02

Title: global rotation
Post by: Richard Rae on 2008-Nov-02
Hi everyone.Is there anyway to get an object to rotate about the global axis irrespective of its own local rotation.
Title: Re: global rotation
Post by: Hemlos on 2008-Nov-03
object xyz: objectx,0, objectz;
make object Orbit around worldxz coords at specified distance:
Code (glbasic) Select

distance=100
worldx=0 //x
worldz=0 //y
angle=0

whilte true
make3d
angle=angle+1
if angle>359 then angle=0
objectx=worldx+distance*cos(angle)
objectz=worldz+distance*sin(angle)
movement objectx,0,objectz
drawobj
showscreen
wend
Title: Re: global rotation
Post by: Richard Rae on 2008-Nov-03
Thanks Hemlos ,but not quite what I meant.Suppose I had a cube sitting at 0,0,0,if it is unrotated its local axis is the same as the world axis.If ,however,I tilt it about its x axis by say 45 degrees and then rotate it about it's y axis,it won't rotate about the world  y axis but about it's local y axis(tilted by 45 degrees).My question was,how would I still get it to rotate about the world axis even if it was tilted over?
Title: Re: global rotation
Post by: Kitty Hello on 2008-Nov-03
Code (glbasic) Select


//! Rotations: Roll, Yaw, Pitch and Offset by: x,y,z
//? Verdrehung: Roll-, Gier-, Nickwinkel und Verschiebung um: x,y,z
// \param rx - roll angle                       |Rollwinkel
// \param ry - yaw angle                        |Gierwinkel
// \param rz - pitch angle                      |Nickwinkel
// \param x  - offset x                         |Verschiebung in x
// \param y  - offset y                         |Verschiebung in y
// \param z  - offset z                         |Verschiebung in z
// \param M[] - [out] the transformation matrix |[Ausgabe]Die Transformationsmatrix
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


Then use X_MULTMATIX mat[]