sm64

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

guLookAtRef.c (3776B)


      1 /*
      2  * This file originates from the standard Nintendo 64 SDK libultra src
      3  * directory, and it used exclusively when building with the Fast3DEX2
      4  * microcode. Not not using it breaks environment mapping.
      5  *
      6  * Apart from the modifications listed below, this file is unmodified.
      7  */
      8 
      9 /**************************************************************************
     10  *                                                                        *
     11  *         Copyright (C) 1994, Silicon Graphics, Inc.                     *
     12  *                                                                        *
     13  *  These coded instructions, statements, and computer programs  contain  *
     14  *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
     15  *  are protected by Federal copyright law.  They  may  not be disclosed  *
     16  *  to  third  parties  or copied or duplicated in any form, in whole or  *
     17  *  in part, without the prior written consent of Silicon Graphics, Inc.  *
     18  *                                                                        *
     19  **************************************************************************/
     20 
     21 /* Minor modifications */
     22 #include <ultra64.h>
     23 #define FTOFRAC8(x) ((int) MIN(((x) * (128.0)), 127.0) & 0xff)
     24 
     25 void guLookAtReflectF(float mf[4][4], LookAt *l, float xEye, float yEye, float zEye, float xAt,
     26                       float yAt, float zAt, float xUp, float yUp, float zUp) {
     27     float len, xLook, yLook, zLook, xRight, yRight, zRight;
     28 
     29     guMtxIdentF(mf);
     30 
     31     xLook = xAt - xEye;
     32     yLook = yAt - yEye;
     33     zLook = zAt - zEye;
     34 
     35     /* Negate because positive Z is behind us: */
     36     len = -1.0 / sqrtf(xLook * xLook + yLook * yLook + zLook * zLook);
     37     xLook *= len;
     38     yLook *= len;
     39     zLook *= len;
     40 
     41     /* Right = Up x Look */
     42 
     43     xRight = yUp * zLook - zUp * yLook;
     44     yRight = zUp * xLook - xUp * zLook;
     45     zRight = xUp * yLook - yUp * xLook;
     46     len = 1.0 / sqrtf(xRight * xRight + yRight * yRight + zRight * zRight);
     47     xRight *= len;
     48     yRight *= len;
     49     zRight *= len;
     50 
     51     /* Up = Look x Right */
     52 
     53     xUp = yLook * zRight - zLook * yRight;
     54     yUp = zLook * xRight - xLook * zRight;
     55     zUp = xLook * yRight - yLook * xRight;
     56     len = 1.0 / sqrtf(xUp * xUp + yUp * yUp + zUp * zUp);
     57     xUp *= len;
     58     yUp *= len;
     59     zUp *= len;
     60 
     61     /* reflectance vectors = Up and Right */
     62 
     63     l->l[0].l.dir[0] = FTOFRAC8(xRight);
     64     l->l[0].l.dir[1] = FTOFRAC8(yRight);
     65     l->l[0].l.dir[2] = FTOFRAC8(zRight);
     66     l->l[1].l.dir[0] = FTOFRAC8(xUp);
     67     l->l[1].l.dir[1] = FTOFRAC8(yUp);
     68     l->l[1].l.dir[2] = FTOFRAC8(zUp);
     69     l->l[0].l.col[0] = 0x00;
     70     l->l[0].l.col[1] = 0x00;
     71     l->l[0].l.col[2] = 0x00;
     72     l->l[0].l.pad1 = 0x00;
     73     l->l[0].l.colc[0] = 0x00;
     74     l->l[0].l.colc[1] = 0x00;
     75     l->l[0].l.colc[2] = 0x00;
     76     l->l[0].l.pad2 = 0x00;
     77     l->l[1].l.col[0] = 0x00;
     78     l->l[1].l.col[1] = 0x80;
     79     l->l[1].l.col[2] = 0x00;
     80     l->l[1].l.pad1 = 0x00;
     81     l->l[1].l.colc[0] = 0x00;
     82     l->l[1].l.colc[1] = 0x80;
     83     l->l[1].l.colc[2] = 0x00;
     84     l->l[1].l.pad2 = 0x00;
     85 
     86     mf[0][0] = xRight;
     87     mf[1][0] = yRight;
     88     mf[2][0] = zRight;
     89     mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight);
     90 
     91     mf[0][1] = xUp;
     92     mf[1][1] = yUp;
     93     mf[2][1] = zUp;
     94     mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp);
     95 
     96     mf[0][2] = xLook;
     97     mf[1][2] = yLook;
     98     mf[2][2] = zLook;
     99     mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook);
    100 
    101     mf[0][3] = 0;
    102     mf[1][3] = 0;
    103     mf[2][3] = 0;
    104     mf[3][3] = 1;
    105 }
    106 
    107 void guLookAtReflect(Mtx *m, LookAt *l, float xEye, float yEye, float zEye, float xAt, float yAt,
    108                      float zAt, float xUp, float yUp, float zUp) {
    109     float mf[4][4];
    110 
    111     guLookAtReflectF(mf, l, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp);
    112 
    113     guMtxF2L(mf, m);
    114 }