Page 1 of 1

3d Matrix Rotations

Posted: Fri Mar 25, 2005 10:40 pm
by Dreglor
in true axis rotations are made by a matrix
problem is, im not sure how you get x,y,z values out of that i look some stuff on google got some stuff but so far it isn't working..

this is the code i got so far trying this.

Code: Select all

 Angle\x = *mfChange\m33Rotation\v3X\x * Angle\x + *mfChange\m33Rotation\v3Y\x * Angle\y + *mfChange\m33Rotation\v3Z\x * Angle\z
  Angle\y = *mfChange\m33Rotation\v3X\y * Angle\y + *mfChange\m33Rotation\v3Y\y * Angle\y + *mfChange\m33Rotation\v3Z\y * Angle\z
  Angle\z = *mfChange\m33Rotation\v3X\z * Angle\z + *mfChange\m33Rotation\v3Y\z * Angle\y + *mfChange\m33Rotation\v3Z\z * Angle\z
  
  RotateEntity(#k_ObjectEnitiy, OldAngle\x-Angle\x, OldAngle\y-Angle\y, OldAngle\z-Angle\z)
  OldAngle\x = Angle\x
  OldAngle\y = Angle\y
  OldAngle\z = Angle\z

Posted: Thu Mar 31, 2005 11:21 am
by Nells
Well, i don't really know how work your stuff but i see that you use Angle\y in your third line but you've assigned Angle\y at the line before :

Code: Select all

 Angle\y = *mfChange\m33Rotation\v3X\y * Angle\y + *mfChange\m33Rotation\v3Y\y * Angle\y + *mfChange\m33Rotation\v3Z\y * Angle\z
  Angle\z = *mfChange\m33Rotation\v3X\z * Angle\z + *mfChange\m33Rotation\v3Y\z * Angle\y + *mfChange\m33Rotation\v3Z\z * Angle\z 

Posted: Mon Apr 04, 2005 3:47 am
by Dreglor
yeah that is a small typo but the whole thing is wrong to begin with :\

here is the proper way to do it but i need some sort of atan2(y,x) becasue the correct way to get the angles is with this code (which is in c)

Code: Select all

angle_y = D =  asin( mat[2]);        /* Calculate Y-axis angle */
    C           =  cos( angle_y );
    angle_y    *=  RADIANS;
    if ( fabs( C ) > 0.005 )             /* Gimball lock? */
      {
      trx      =  mat[10] / C;           /* No, so get X-axis angle */
      try      = -mat[6]  / C;
      angle_x  = atan2( try, trx ) * RADIANS;
      trx      =  mat[0] / C;            /* Get Z-axis angle */
      try      = -mat[1] / C;
      angle_z  = atan2( try, trx ) * RADIANS;
      }
    else                                 /* Gimball lock has occurred */
      {
      angle_x  = 0;                      /* Set X-axis angle to zero */
      trx      =  mat[5];                 /* And calculate Z-axis angle */
      try      =  mat[4];
      angle_z  = atan2( try, trx ) * RADIANS;
      }

    /* return only positive angles in [0,360] */
    if (angle_x < 0) angle_x += 360;
    if (angle_y < 0) angle_y += 360;
    if (angle_z < 0) angle_z += 360;
and have converted most of it, execpt for the atan2 function...
so if any one can point me to a way to do that function by lib, asm, pb code please point it out for me thanks.

Posted: Mon Apr 04, 2005 8:51 am
by Psychophanta
If you tell me what do ATan2() exactly, i'll give you it in ASM. :)

Posted: Mon Apr 04, 2005 9:13 am
by Psychophanta
Aha! not needed. Google is magic :!:

Code: Select all

Procedure.l atan2(y.l,x.l)
  !fild dword[esp]
  !fild dword[esp+4]
  !fpatan
  result.l
  !fistp dword[esp+8]
  !mov eax,dword[esp+8]
  ProcedureReturn
EndProcedure

;Test it:
Debug atan2(-3,4)
And in FASM macro version:

Code: Select all

!macro atan2 y,x,result{
  !fild dword[v_#y]
  !fild dword[v_#x]
  !fpatan
  !fistp dword[v_#result]
  !mov eax,dword[v_#result]}


;Test it:
a.l=-3:b.l=5:r.l
!atan2 a,b,r
Debug r.l
I think it is well done.
There are another function in C called atan2f(), which do it with floats:

Code: Select all

Procedure.f atan2f(y.f,x.f)
  !fld dword[esp]
  !fld dword[esp+4]
  !fpatan
EndProcedure

;Test it:
Debug atan2f(-3,5)
And:

Code: Select all

!macro atan2f y,x,result{
  !fld dword[v_#y]
  !fld dword[v_#x]
  !fpatan
  !fstp dword[v_#result]}

;Test it:
a.f=-3:b.f=5:r.f
!atan2f a,b,r
Debug r.f
That's it :wink:

Posted: Mon Apr 04, 2005 2:31 pm
by Dreglor
THANKS!
yeah, this is in the standard c libs why doesn't pb have it :P

Posted: Tue Apr 05, 2005 6:30 pm
by Psychophanta
Dreglor wrote:THANKS!
yeah, this is in the standard c libs why doesn't pb have it :P
Yes, i will request it just now in the request section :!:

Posted: Tue Apr 05, 2005 7:13 pm
by DoubleDutch
And in FASM macro version:
:) At least somebody doesn't think the macro trick was useless ;)

Posted: Mon Apr 11, 2005 8:46 am
by Psychophanta
DoubleDutch wrote:At least somebody doesn't think the macro trick was useless ;)
hehe! Of course :wink: