Files
mm/src/libultra/gu/perspective.c
T
Anghelo Carvajal 6475196f0f Yet another libultra cleanup (#1384)
* os symbols

* various variables

* more variables

* more cleanup

* yeet HW_REG

* OS_PHYSICAL_TO_K0 and other cleanups

* Rename r4300.h

* migrate pimgr data and cleanup on initialize.c

* rename osFlash symbols

* cleanup gu

* vimodes

* yeet rmon, do libc files

* some os files

* hardwareinterrupt

* cleanup a lot of os files

* cleanup osVirtualToPhysical

* various io files

* another io chunk

* final io chunk

* yeet hardware.h

* yeet PHYSICAL_TO_VIRTUAL and VIRTUAL_TO_PHYSICAL

* fix typo

* fix merge

* remove global.h from libultra files

* fixes and format

* brief explanation

* review

* review

* review

* review

* SEGMENTED_TO_K0

* Revert "SEGMENTED_TO_K0"

This reverts commit f8d62d670f.

* take two

* bss

* bss
2023-10-26 10:44:27 -03:00

43 lines
1.0 KiB
C

#include "ultra64.h"
void guPerspectiveF(float mf[4][4], u16* perspNorm, float fovy, float aspect, float near, float far, float scale) {
float cot;
int i;
int j;
guMtxIdentF(mf);
fovy *= 3.1415926 / 180.0;
cot = cosf(fovy / 2) / sinf(fovy / 2);
mf[0][0] = cot / aspect;
mf[1][1] = cot;
mf[2][2] = (near + far) / (near - far);
mf[2][3] = -1;
mf[3][2] = 2 * near * far / (near - far);
mf[3][3] = 0.0f;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
mf[i][j] *= scale;
}
}
if (perspNorm != NULL) {
if (near + far <= 2.0) {
*perspNorm = 65535;
} else {
*perspNorm = (double)(1 << 17) / (near + far);
if (*perspNorm <= 0) {
*perspNorm = 1;
}
}
}
}
void guPerspective(Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale) {
float mf[4][4];
guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale);
guMtxF2L(mf, m);
}