Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
CheckPositionRelativeToPlane.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "npc.h"
3
4// checks whether the player has crossed the plane defined by points A = (Ax, Az) and B = (Bx, Bz)
5// this plane divides space into two halves: a "positive" region and "negative" region, with the positive
6// region on the right side of the line going from A to B.
7/*
8 ex: the region depicted goes from x = [0,100] and z = [0,100] with A = (10,10) and B = (60,80)
9(z)
10100 ---------------++++++
11 ---------------++++++
12 --------------+++++++
13 -------------++++++++
14 ------------B++++++++
15 ------------+++++++++
16 -----------++++++++++
17 ----------+++++++++++
18 ----------+++++++++++
19 ---------++++++++++++
20 --------+++++++++++++
21 --------+++++++++++++
22 -------++++++++++++++
23 ------+++++++++++++++
24 -----++++++++++++++++
25 -----++++++++++++++++
26 ----+++++++++++++++++
27 ---++++++++++++++++++
28 --A++++++++++++++++++
29 --+++++++++++++++++++
30 0 -++++++++++++++++++++
31 0 100 (x)
32*/
33
34// returns (on LVar0) the side of the plane the player is on
35#define PLANE_SIDE_NEGATIVE 0
36#define PLANE_SIDE_POSITIVE 1
37
38API_CALLABLE(N(CheckPositionRelativeToPlane)) {
39 Bytecode* args = script->ptrReadPos;
40 PlayerStatus* playerStatus = &gPlayerStatus;
41 f32 Ax = evt_get_variable(script, *args++);
42 f32 Az = evt_get_variable(script, *args++);
43 f32 Bx = evt_get_variable(script, *args++);
44 f32 Bz = evt_get_variable(script, *args++);
45 f32 dzdx;
46
47 dzdx = (Bz - Az) / (Bx - Ax);
48
49 // this is equivalent to testing the determinant: ((Bx - Ax)*(Pz - Az) - (Bz - Az)*(Px - Ax)) < 0
50 if (playerStatus->pos.z < ((dzdx * playerStatus->pos.x) + (Az - (dzdx * Ax)))) {
51 script->varTable[0] = PLANE_SIDE_NEGATIVE;
52 } else {
53 script->varTable[0] = PLANE_SIDE_POSITIVE;
54 }
55
56 return ApiStatus_DONE2;
57}
#define PLANE_SIDE_NEGATIVE
#define PLANE_SIDE_POSITIVE
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
PlayerStatus gPlayerStatus
Definition 77480.c:39