sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

guRotateF.c (1398B)


      1 #include "libultra_internal.h"
      2 
      3 void guRotateF(float m[4][4], float a, float x, float y, float z) {
      4     static f32 pi_180 = GU_PI / 180.0f;
      5     f32 sin_a;
      6     f32 cos_a;
      7     f32 ab;
      8     f32 bc;
      9     f32 ca;
     10     f32 t;
     11 #ifdef VERSION_CN
     12     f32 xs;
     13     f32 ys;
     14     f32 zs;
     15 #else
     16     f32 xx, yy, zz;
     17 #endif
     18 
     19     guNormalize(&x, &y, &z);
     20 
     21     a = a * pi_180;
     22 
     23     sin_a = sinf(a);
     24     cos_a = cosf(a);
     25     t = 1 - cos_a;
     26 
     27     ab = x * y * t;
     28     bc = y * z * t;
     29     ca = z * x * t;
     30 
     31     guMtxIdentF(m);
     32 
     33     // TODO: Merge IDO/GCC
     34 #ifdef VERSION_CN
     35     xs = x * sin_a;
     36     t = x * x;
     37     m[0][0] = t + cos_a * (1 - t);
     38     m[2][1] = bc - xs;
     39     m[1][2] = bc + xs;
     40 
     41     ys = y * sin_a;
     42     t = y * y;
     43     m[1][1] = t + cos_a * (1 - t);
     44     m[2][0] = ca + ys;
     45     m[0][2] = ca - ys;
     46 
     47     zs = z * sin_a;
     48     t = z * z;
     49     m[2][2] = t + cos_a * (1 - t);
     50     m[1][0] = ab - zs;
     51     m[0][1] = ab + zs;
     52 #else
     53     xx = x * x;
     54     m[0][0] = xx + cos_a * (1 - xx);
     55     m[2][1] = bc - (x * sin_a);
     56     m[1][2] = bc + (x * sin_a);
     57 
     58     yy = y * y;
     59     m[1][1] = yy + cos_a * (1 - yy);
     60     m[2][0] = ca + (y * sin_a);
     61     m[0][2] = ca - (y * sin_a);
     62 
     63     zz = z * z;
     64     m[2][2] = zz + cos_a * (1 - zz);
     65     m[1][0] = ab - (z * sin_a);
     66     m[0][1] = ab + (z * sin_a);
     67 #endif
     68 }
     69 
     70 void guRotate(Mtx *m, float a, float x, float y, float z) {
     71     float mf[4][4];
     72     guRotateF(mf, a, x, y, z);
     73     guMtxF2L(mf, m);
     74 }