sm64

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

guPerspectiveF.c (1128B)


      1 #include "libultra_internal.h"
      2 
      3 void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, float near, float far,
      4                     float scale) {
      5     float yscale;
      6     int row;
      7     int col;
      8     guMtxIdentF(mf);
      9     fovy *= GU_PI / 180.0;
     10     yscale = cosf(fovy / 2) / sinf(fovy / 2);
     11     mf[0][0] = yscale / aspect;
     12     mf[1][1] = yscale;
     13     mf[2][2] = (near + far) / (near - far);
     14     mf[2][3] = -1;
     15     mf[3][2] = 2 * near * far / (near - far);
     16     mf[3][3] = 0.0f;
     17     for (row = 0; row < 4; row++) {
     18         for (col = 0; col < 4; col++) {
     19             mf[row][col] *= scale;
     20         }
     21     }
     22     if (perspNorm != NULL) {
     23         if (near + far <= 2.0) {
     24             *perspNorm = 65535;
     25         } else {
     26             *perspNorm = (double) (1 << 17) / (near + far);
     27             if (*perspNorm <= 0) {
     28                 *perspNorm = 1;
     29             }
     30         }
     31     }
     32 }
     33 
     34 void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, float far,
     35                    float scale) {
     36     float mat[4][4];
     37     guPerspectiveF(mat, perspNorm, fovy, aspect, near, far, scale);
     38     guMtxF2L(mat, m);
     39 }