Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
port Matrix_TranslateRel
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 28, 2023
1 parent b4ba638 commit 6c4edab
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
16 changes: 8 additions & 8 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef struct PHD_3DPOS {
00401430 000000A8 + void __cdecl Matrix_RotZ(int16_t rz);
004014E0 000001DC + void __cdecl Matrix_RotYXZ(int16_t ry, int16_t rx, int16_t rz);
004016C0 000001E7 + void __cdecl Matrix_RotYXZpack(uint32_t rpack);
004018B0 000000AB - sub_4018B0
004018B0 000000AB + bool __cdecl Matrix_TranslateRel(int32_t x, int32_t y, int32_t z);
00401960 0000007A - sub_401960
004019E0 000000F3 - sub_4019E0
00401AE0 000000EA - sub_401AE0
Expand Down Expand Up @@ -1232,3 +1232,4 @@ typedef struct PHD_3DPOS {
004BCB58 MATRIX g_MatrixStack[];
004B2AC0 MATRIX g_W2VMatrix;
0046C304 float g_ViewportAspectRatio = 0.0f;
00478058 int32_t PhdFarZ;
13 changes: 13 additions & 0 deletions src/game/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "global/const.h"
#include "global/types.h"
#include "global/vars.h"
#include "util.h"

#include <stdint.h>

Expand Down Expand Up @@ -270,3 +271,15 @@ void __cdecl Matrix_RotYXZpack(uint32_t rpack)
mptr->_21 = r1 >> W2V_MATRIX;
}
}

bool __cdecl Matrix_TranslateRel(int32_t x, int32_t y, int32_t z)
{
struct MATRIX *mptr = g_MatrixPtr;
mptr->_03 += z * mptr->_02 + y * mptr->_01 + x * mptr->_00;
mptr->_13 += z * mptr->_12 + y * mptr->_11 + x * mptr->_10;
mptr->_23 += z * mptr->_22 + y * mptr->_21 + x * mptr->_20;

return (
ABS(mptr->_03) <= g_PhdFarZ && ABS(mptr->_13) <= g_PhdFarZ
&& ABS(mptr->_23) <= g_PhdFarZ);
}
2 changes: 2 additions & 0 deletions src/game/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "global/types.h"

#include <stdbool.h>
#include <stdint.h>

struct PHD_3DPOS;
Expand All @@ -15,3 +16,4 @@ void __cdecl Matrix_RotY(PHD_ANGLE ry);
void __cdecl Matrix_RotZ(PHD_ANGLE rz);
void __cdecl Matrix_RotYXZ(int16_t ry, int16_t rx, int16_t rz);
void __cdecl Matrix_RotYXZpack(uint32_t rpack);
bool __cdecl Matrix_TranslateRel(int32_t x, int32_t y, int32_t z);
1 change: 1 addition & 0 deletions src/global/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
#define g_MatrixStack ARRAY_(0x004BCB58, MATRIX, [])
#define g_W2VMatrix VAR_U_(0x004B2AC0, MATRIX)
#define g_ViewportAspectRatio VAR_I_(0x0046C304, float, 0.0f)
#define g_PhdFarZ VAR_U_(0x00478058, int32_t)
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static void Inject_Matrix(void)
INJECT(0x00401430, Matrix_RotZ);
INJECT(0x004014E0, Matrix_RotYXZ);
INJECT(0x004016C0, Matrix_RotYXZpack);
INJECT(0x004018B0, Matrix_TranslateRel);
}

void Inject_Exec(void)
Expand Down
7 changes: 7 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#ifndef ABS
#define ABS(x) (((x) < 0) ? (-(x)) : (x))
#define MIN(x, y) ((x) <= (y) ? (x) : (y))
#define MAX(x, y) ((x) >= (y) ? (x) : (y))
#endif

0 comments on commit 6c4edab

Please sign in to comment.