guLookAt & guLookAtF matching

This commit is contained in:
Alejandro Javier Asenjo Nitti
2023-10-17 17:43:47 -03:00
parent 2142ae4410
commit 85ab89eb48
5 changed files with 74 additions and 11 deletions
+5 -3
View File
@@ -82,7 +82,7 @@ endif
### Compiler ###
CC := $(TOOLS)/ido_recomp/$(DETECTED_OS)/5.3/cc
IDO := $(TOOLS)/ido_recomp/$(DETECTED_OS)/5.3/cc
AS := $(MIPS_BINUTILS_PREFIX)as
LD := $(MIPS_BINUTILS_PREFIX)ld
OBJCOPY := $(MIPS_BINUTILS_PREFIX)objcopy
@@ -194,10 +194,12 @@ build/src/libultra/2D300.o: OPTFLAGS := -O1 -g0
build/src/libultra/io/controller.o: OPTFLAGS := -O1 -g0
build/src/libultra/libc/string.o: OPTFLAGS := -O2 -g0
build/src/libultra/libc/ldiv.o: OPTFLAGS := -O2 -g0
#build/src/libultra/gu/lookat.o: OPTFLAGS := -O3 -g0
build/src/libultra/gu/lookat.o: OPTFLAGS := -O3 -g0
# cc & asm-processor
build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(CC) -- $(AS) $(ASFLAGS) --
CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(IDO) -- $(AS) $(ASFLAGS) --
build/src/libultra/gu/lookat.o: CC := $(IDO)
#build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(IDO) -- $(AS) $(ASFLAGS) --
all: uncompressed
+1 -1
View File
@@ -2,7 +2,7 @@
def apply(config, args):
config['baseimg'] = 'baserom.us.z64'
config['myimg'] = 'build/starfox64.us.z64'
config['myimg'] = 'build/starfox64.us.uncompressed.z64'
config['mapfile'] = 'build/starfox64.us.map'
config['source_directories'] = ['./src','./include']
config['objdump_flags'] = ['-M','reg-names=32']
+2
View File
@@ -59,6 +59,8 @@ typedef double f64; /* double prec floating point */
typedef u32 size_t;
typedef float Matrix[4][4];
#endif /* _LANGUAGE_C */
+1
View File
@@ -2,5 +2,6 @@
#define MACROS_H
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
#define SQ(x) ((x) * (x))
#endif // MACROS_H
+65 -7
View File
@@ -1,11 +1,73 @@
#include "global.h"
#include "PR/gbi.h"
typedef float Matrix[4][4];
void guMtxIdentF(float (*mf)[4]);
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/lookat/guLookAtF.s")
float sqrtf(float value);
void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp,
float yUp, float zUp) {
float len;
float xLook;
float yLook;
float zLook;
float xRight;
float yRight;
float zRight;
guMtxIdentF(mf);
xLook = xAt - xEye;
yLook = yAt - yEye;
zLook = zAt - zEye;
/* Negate because positive Z is behind us: */
len = -1.0 / sqrtf(xLook * xLook + yLook * yLook + zLook * zLook);
xLook *= len;
yLook *= len;
zLook *= len;
/* Right = Up x Look */
xRight = yUp * zLook - zUp * yLook;
yRight = zUp * xLook - xUp * zLook;
zRight = xUp * yLook - yUp * xLook;
len = 1.0 / sqrtf(xRight * xRight + yRight * yRight + zRight * zRight);
xRight *= len;
yRight *= len;
zRight *= len;
/* Up = Look x Right */
xUp = yLook * zRight - zLook * yRight;
yUp = zLook * xRight - xLook * zRight;
zUp = xLook * yRight - yLook * xRight;
len = 1.0 / sqrtf(xUp * xUp + yUp * yUp + zUp * zUp);
xUp *= len;
yUp *= len;
zUp *= len;
mf[0][0] = xRight;
mf[1][0] = yRight;
mf[2][0] = zRight;
mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight);
mf[0][1] = xUp;
mf[1][1] = yUp;
mf[2][1] = zUp;
mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp);
mf[0][2] = xLook;
mf[1][2] = yLook;
mf[2][2] = zLook;
mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook);
mf[0][3] = 0;
mf[1][3] = 0;
mf[2][3] = 0;
mf[3][3] = 1;
}
#if 0
void guLookAt(Mtx* m, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp,
float zUp) {
Matrix mf;
@@ -14,7 +76,3 @@ void guLookAt(Mtx* m, float xEye, float yEye, float zEye, float xAt, float yAt,
guMtxF2L(mf, m);
}
#else
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/gu/lookat/guLookAt.s")
#endif