sm64

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

guMtxF2L.c (1673B)


      1 #include "libultra_internal.h"
      2 #ifdef GBI_FLOATS
      3 #include <string.h>
      4 #endif
      5 
      6 #if !defined(VERSION_CN) || !defined(TARGET_N64)
      7 
      8 #ifndef GBI_FLOATS
      9 void guMtxF2L(float mf[4][4], Mtx *m) {
     10     int r, c;
     11     s32 tmp1;
     12     s32 tmp2;
     13     s32 *m1 = &m->m[0][0];
     14     s32 *m2 = &m->m[2][0];
     15     for (r = 0; r < 4; r++) {
     16         for (c = 0; c < 2; c++) {
     17             tmp1 = mf[r][2 * c] * 65536.0f;
     18             tmp2 = mf[r][2 * c + 1] * 65536.0f;
     19             *m1++ = (tmp1 & 0xffff0000) | ((tmp2 >> 0x10) & 0xffff);
     20             *m2++ = ((tmp1 << 0x10) & 0xffff0000) | (tmp2 & 0xffff);
     21         }
     22     }
     23 }
     24 
     25 void guMtxL2F(float mf[4][4], Mtx *m) {
     26     int r, c;
     27     u32 tmp1;
     28     u32 tmp2;
     29     u32 *m1;
     30     u32 *m2;
     31     s32 stmp1, stmp2;
     32     m1 = (u32 *) &m->m[0][0];
     33     m2 = (u32 *) &m->m[2][0];
     34     for (r = 0; r < 4; r++) {
     35         for (c = 0; c < 2; c++) {
     36             tmp1 = (*m1 & 0xffff0000) | ((*m2 >> 0x10) & 0xffff);
     37             tmp2 = ((*m1++ << 0x10) & 0xffff0000) | (*m2++ & 0xffff);
     38             stmp1 = *(s32 *) &tmp1;
     39             stmp2 = *(s32 *) &tmp2;
     40             mf[r][c * 2 + 0] = stmp1 / 65536.0f;
     41             mf[r][c * 2 + 1] = stmp2 / 65536.0f;
     42         }
     43     }
     44 }
     45 #else
     46 void guMtxF2L(float mf[4][4], Mtx *m) {
     47     memcpy(m, mf, sizeof(Mtx));
     48 }
     49 #endif
     50 
     51 void guMtxIdentF(float mf[4][4]) {
     52     int r, c;
     53     for (r = 0; r < 4; r++) {
     54         for (c = 0; c < 4; c++) {
     55             if (r == c) {
     56                 mf[r][c] = 1.0f;
     57             } else {
     58                 mf[r][c] = 0.0f;
     59             }
     60         }
     61     }
     62 }
     63 
     64 void guMtxIdent(Mtx *m) {
     65 #ifndef GBI_FLOATS
     66     float mf[4][4];
     67     guMtxIdentF(mf);
     68     guMtxF2L(mf, m);
     69 #else
     70     guMtxIdentF(m->m);
     71 #endif
     72 }
     73 
     74 #endif