3d Matrix Rotations

Advanced game related topics
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

3d Matrix Rotations

Post 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
~Dreglor
Nells
New User
New User
Posts: 6
Joined: Tue Mar 02, 2004 12:43 pm

Post 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 
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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.
~Dreglor
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

If you tell me what do ATan2() exactly, i'll give you it in ASM. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

THANKS!
yeah, this is in the standard c libs why doesn't pb have it :P
~Dreglor
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 :!:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

And in FASM macro version:
:) At least somebody doesn't think the macro trick was useless ;)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

DoubleDutch wrote:At least somebody doesn't think the macro trick was useless ;)
hehe! Of course :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply