Create functionally equivalent C for handwritten portalConvertCoordinates
This commit is contained in:
parent
51442c4db1
commit
1c7dc246f5
|
|
@ -189,7 +189,7 @@
|
|||
build/ROMID/game/collisionutils.o (section); \
|
||||
build/ROMID/game/bg.o (section); \
|
||||
build/ROMID/game/bgbss.o (section); \
|
||||
build/ROMID/game/game_165360.o (section); \
|
||||
build/ROMID/game/portalconvasm.o (section); \
|
||||
build/ROMID/game/stagetable.o (section); \
|
||||
build/ROMID/game/gfxreplace.o (section); \
|
||||
build/ROMID/game/env.o (section); \
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@
|
|||
build/ROMID/game/collisionutils.o (section); \
|
||||
build/ROMID/game/bg.o (section); \
|
||||
build/ROMID/game/bgbss.o (section); \
|
||||
build/ROMID/game/game_165360.o (section); \
|
||||
build/ROMID/game/portalconvasm.o (section); \
|
||||
build/ROMID/game/stagetable.o (section); \
|
||||
build/ROMID/game/gfxreplace.o (section); \
|
||||
build/ROMID/game/env.o (section); \
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@
|
|||
build/ROMID/game/collisionutils.o (section); \
|
||||
build/ROMID/game/bg.o (section); \
|
||||
build/ROMID/game/bgbss.o (section); \
|
||||
build/ROMID/game/game_165360.o (section); \
|
||||
build/ROMID/game/portalconvasm.o (section); \
|
||||
build/ROMID/game/stagetable.o (section); \
|
||||
build/ROMID/game/gfxreplace.o (section); \
|
||||
build/ROMID/game/env.o (section); \
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@
|
|||
build/ROMID/game/collisionutils.o (section); \
|
||||
build/ROMID/game/bg.o (section); \
|
||||
build/ROMID/game/bgbss.o (section); \
|
||||
build/ROMID/game/game_165360.o (section); \
|
||||
build/ROMID/game/portalconvasm.o (section); \
|
||||
build/ROMID/game/stagetable.o (section); \
|
||||
build/ROMID/game/gfxreplace.o (section); \
|
||||
build/ROMID/game/env.o (section); \
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@
|
|||
build/ROMID/game/collisionutils.o (section); \
|
||||
build/ROMID/game/bg.o (section); \
|
||||
build/ROMID/game/bgbss.o (section); \
|
||||
build/ROMID/game/game_165360.o (section); \
|
||||
build/ROMID/game/portalconvasm.o (section); \
|
||||
build/ROMID/game/stagetable.o (section); \
|
||||
build/ROMID/game/gfxreplace.o (section); \
|
||||
build/ROMID/game/env.o (section); \
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
#include "game/gfxmemory.h"
|
||||
#include "game/gfxreplace.h"
|
||||
#include "game/bg.h"
|
||||
#include "game/game_165360.h"
|
||||
#include "game/portalconv.h"
|
||||
#include "game/stagetable.h"
|
||||
#include "game/env.h"
|
||||
#include "game/room.h"
|
||||
|
|
@ -3689,7 +3689,7 @@ bool g_PortalGetScreenBbox(s32 portalnum, struct screenbox *box)
|
|||
return g_PortalThings[portalnum].unk06;
|
||||
}
|
||||
|
||||
len = func0f165360(portalnum, &start, things);
|
||||
len = portalConvertCoordinates(portalnum, &start, things);
|
||||
|
||||
sp2ec = 0;
|
||||
thing = &things[start];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,99 @@
|
|||
#include <ultra64.h>
|
||||
#include "constants.h"
|
||||
#include "bss.h"
|
||||
#include "lib/memp.h"
|
||||
#include "data.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* This function is not linked in the N64 build. The N64 build appears to use
|
||||
* handwritten assembly for this function. The below is functionally equivalent
|
||||
* C that can be dropped in place of the handwritten function by linking the
|
||||
* different file.
|
||||
*/
|
||||
s32 portalConvertCoordinates(s32 portalnum, s32 *start, struct portalthing2 *things)
|
||||
{
|
||||
Mtxf *mtx = g_Vars.currentplayer->worldtoscreenmtx;
|
||||
struct portalvertices *pvertices = (struct portalvertices *) ((u32) g_BgPortals + g_BgPortals[portalnum].verticesoffset);
|
||||
struct portalthing2 *left;
|
||||
struct portalthing2 *right = &things[39];
|
||||
bool anybehind = false;
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < pvertices->count; i++) {
|
||||
f32 x = pvertices->vertices[i].x;
|
||||
f32 y = pvertices->vertices[i].y;
|
||||
f32 z = pvertices->vertices[i].z;
|
||||
|
||||
right->coord.x = mtx->m[0][0] * x + mtx->m[1][0] * y + mtx->m[2][0] * z;
|
||||
right->coord.y = mtx->m[0][1] * x + mtx->m[1][1] * y + mtx->m[2][1] * z;
|
||||
right->coord.z = mtx->m[0][2] * x + mtx->m[1][2] * y + mtx->m[2][2] * z;
|
||||
|
||||
right->coord.x += mtx->m[3][0];
|
||||
right->coord.y += mtx->m[3][1];
|
||||
right->coord.z += mtx->m[3][2];
|
||||
|
||||
if (right->coord.z <= 0.0f) {
|
||||
right->behind = false;
|
||||
} else {
|
||||
right->behind = true;
|
||||
anybehind = true;
|
||||
}
|
||||
|
||||
right--;
|
||||
}
|
||||
|
||||
if (anybehind) {
|
||||
s32 numfinalvertices = 0;
|
||||
|
||||
right->coord.x = things[39].coord.x;
|
||||
right->coord.y = things[39].coord.y;
|
||||
right->coord.z = things[39].coord.z;
|
||||
right->behind = things[39].behind;
|
||||
|
||||
left = &things[0];
|
||||
|
||||
for (i = 0; i < pvertices->count; i++) {
|
||||
s32 value = right[1].behind * 2 + right[0].behind;
|
||||
f32 mult;
|
||||
|
||||
if (value == 0) {
|
||||
left->coord.x = right[1].coord.x;
|
||||
left->coord.y = right[1].coord.y;
|
||||
left->coord.z = right[1].coord.z;
|
||||
left->behind = right[1].behind;
|
||||
left++;
|
||||
numfinalvertices++;
|
||||
} else if (value == 1) {
|
||||
left->coord.x = right[1].coord.x;
|
||||
left->coord.y = right[1].coord.y;
|
||||
left->coord.z = right[1].coord.z;
|
||||
left->behind = right[1].behind;
|
||||
left++;
|
||||
numfinalvertices++;
|
||||
|
||||
mult = -(right[0].coord.z / (right[1].coord.z - right[0].coord.z));
|
||||
left->coord.x = (right[1].coord.x - right[0].coord.x) * mult + right[0].coord.x;
|
||||
left->coord.y = (right[1].coord.y - right[0].coord.y) * mult + right[0].coord.y;
|
||||
left->coord.z = 0.0f;
|
||||
left++;
|
||||
numfinalvertices++;
|
||||
} else {
|
||||
mult = -(right[0].coord.z / (right[1].coord.z - right[0].coord.z));
|
||||
left->coord.x = (right[1].coord.x - right[0].coord.x) * mult + right[0].coord.x;
|
||||
left->coord.y = (right[1].coord.y - right[0].coord.y) * mult + right[0].coord.y;
|
||||
left->coord.z = 0.0f;
|
||||
left++;
|
||||
numfinalvertices++;
|
||||
}
|
||||
|
||||
right++;
|
||||
}
|
||||
|
||||
*start = 0;
|
||||
return numfinalvertices;
|
||||
}
|
||||
|
||||
*start = 40 - pvertices->count;
|
||||
return pvertices->count;
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ glabel var7f1b76d0
|
|||
|
||||
.text
|
||||
|
||||
glabel func0f165360
|
||||
glabel portalConvertCoordinates
|
||||
mfc1 $t7, $f20
|
||||
lui $a3, %hi(g_Vars)
|
||||
addiu $a3, $a3, %lo(g_Vars)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#ifndef _IN_GAME_GAME_165360_H
|
||||
#define _IN_GAME_GAME_165360_H
|
||||
#include <ultra64.h>
|
||||
#include "data.h"
|
||||
#include "types.h"
|
||||
|
||||
s32 func0f165360(s32 portalnum, s32 *start, struct portalthing2 *things);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _IN_GAME_PORTALCONV_H
|
||||
#define _IN_GAME_PORTALCONV_H
|
||||
#include <ultra64.h>
|
||||
#include "data.h"
|
||||
#include "types.h"
|
||||
|
||||
s32 portalConvertCoordinates(s32 portalnum, s32 *start, struct portalthing2 *things);
|
||||
|
||||
#endif
|
||||
|
|
@ -6357,7 +6357,7 @@ struct modelrwdatabinding {
|
|||
|
||||
struct portalthing2 {
|
||||
struct coord coord;
|
||||
u32 unk0c;
|
||||
bool behind;
|
||||
};
|
||||
|
||||
struct var800a6538 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue