Skip to content

Commit

Permalink
More Progress (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
FRDS authored Oct 30, 2024
1 parent ae2add5 commit 01b110e
Show file tree
Hide file tree
Showing 6 changed files with 394 additions and 201 deletions.
31 changes: 16 additions & 15 deletions decompile/WorkInProgress/src/CAM/CAM_18_MapRange_PosPoints.c
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
#include <common.h>

// get percentage [0 to 0x1000] of Driver between pos1 and pos2
int DECOMP_CAM_MapRange_PosPoints(short *pos1, short *pos2, short *currPos)
int DECOMP_CAM_MapRange_PosPoints(SVec3 *pos1, SVec3 *pos2, SVec3 *currPos)
{
int percent;
int vectorDistMax;
int vectorDistCurr;
SVec3 vec1;
SVec3 vec2;
short distY;

// vector distance between position1 and position2.
vectorDistMax = CONCAT22(pos1[1] - pos2[1], pos1[0] - pos2[0]);

distY = pos1[2] - pos2[2];

MATH_VectorNormalize(&vectorDistMax);
vec1.x = pos1->x - pos2->x;
vec1.y = pos1->y - pos2->y;
vec1.z = pos1->z - pos2->z;

MATH_VectorNormalize(&vec1);

// vector distance between position1 and currentPosition.
vectorDistCurr = CONCAT22(currPos[1] - pos1[1], currPos[0] - pos1[0]);
vec2.x = pos1->x - currPos->x;
vec2.y = pos1->y - currPos->y;
vec2.z = pos1->z - currPos->z;

gte_ldR11R12(vectorDistMax);
gte_ldR13R21((int)distY);
gte_ldVXY0(vectorDistCurr);
gte_ldVZ0((int)(short)(currPos[2] - pos1[2]));
// replace R11R12 and R13R21
gte_ldsvrtrow0(&vec1);
gte_ldv0(&vec2);
gte_mvmva(0, 0, 0, 3, 0);
percent = gte_stMAC1();
gte_stlvnl0(&percent);

// Shift by 12 bits to get the percentage between 0 and 0x1000.
return percent >> 0xc;
return FP_INT(percent);
}
30 changes: 17 additions & 13 deletions decompile/WorkInProgress/src/MATH.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <common.h>

#define PSYQ_FP_DIV(x, y) (((x) << PSYQ_FRACTIONAL_BITS) / (y))

// only used by flamejet and PapuPyramidPlant for hitbox collision,
// also used by missile, probably hitbox again
MATRIX* DECOMP_MATH_HitboxMatrix(MATRIX* output, MATRIX* input)
Expand Down Expand Up @@ -40,37 +42,39 @@ MATRIX* DECOMP_MATH_HitboxMatrix(MATRIX* output, MATRIX* input)
return;
}

void DECOMP_MATH_VectorLength(VECTOR* input)
void DECOMP_MATH_VectorLength(SVec3* input)
{
unsigned int uVar1;
unsigned int length;

gte_ldR11R12(input->vx);
gte_ldR13R21(input->vy);
gte_ldVXY0(input->vx);
gte_ldVZ0(input->vy);
gte_ldR11R12(input->x);
gte_ldR13R21(input->y);
gte_ldVXY0(input->x);
gte_ldVZ0(input->y);
gte_mvmva(0,0,0,3,0);
uVar1 = gte_stMAC1();
SquareRoot0(uVar1);
gte_stlvnl0(&length);
SquareRoot0(length);

return;
}

int DECOMP_MATH_VectorNormalize(VECTOR* input)
int DECOMP_MATH_VectorNormalize(SVec3* input)
{
int length;

length = MATH_VectorLength();
length = MATH_VectorLength(input);

if (length != 0) {
#if 0
if (length == 0) {
trap(0x1c00);
}
if ((length == -1) && (input->vx | input->vy | input->vz) == 0x8000) {
trap(0x1800);
}
input->vx = (short)((input->vx << 0xc) / length);
input->vy = (short)((input->vy << 0xc) / length);
input->vz = (short)((input->vz << 0xc) / length);
#endif
input->x = (short)(FP_Div(input->x, length));
input->y = (short)(FP_Div(input->y, length));
input->z = (short)(FP_Div(input->z, length));
}
return length;
}
Expand Down
Loading

0 comments on commit 01b110e

Please sign in to comment.