Alchemy
Loading...
Searching...
No Matches

object_distance.h

Go to the documentation of this file.
1#include "types.h"
2#include "iwram_call.h"
3
4// Several scenes (Mercury and Venus Lighthouses' aeries, Tolbi, Vault, Venus
5// Lighthouse, Xian, and every scene with object_staged_actor.h): the distance
6// between two actors.
7
8/// The distance in whole pixels between two 16.16 positions of x, y and z.
9/// Callers take byte views of complete actors; their coordinate members do
10/// not form an array.
11UNUSED static s32 FixedPoint_Distance(const u8 *firstPosition,
12 const u8 *secondPosition) {
13 s32 deltaX =
14 (*(const s32 *)firstPosition - *(const s32 *)secondPosition) >> 16;
15 s32 deltaY;
16 s32 deltaZ;
17 s32 deltaXSquared;
18 s32 deltaYSquared;
19 s32 deltaZSquared;
20
21 firstPosition += sizeof(s32);
22 secondPosition += sizeof(s32);
23 deltaY = (*(const s32 *)firstPosition - *(const s32 *)secondPosition) >> 16;
24 firstPosition += sizeof(s32);
25 secondPosition += sizeof(s32);
26 deltaZ = (*(const s32 *)firstPosition - *(const s32 *)secondPosition) >> 16;
27 deltaXSquared = deltaX * deltaX;
28 deltaYSquared = deltaY * deltaY;
29 deltaZSquared = deltaZ * deltaZ;
30 return Iwram_Sqrt(deltaXSquared + deltaYSquared + deltaZSquared);
31}
The IWRAM call layer: the routines the game keeps resident in IWRAM, each at its fixed address,...
static s32 Iwram_Sqrt(s32 value)
Definition iwram_call.h:63
static UNUSED s32 FixedPoint_Distance(const u8 *firstPosition, const u8 *secondPosition)
The distance in whole pixels between two 16.16 positions of x, y and z.
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
#define UNUSED
Definition types.h:22
unsigned char u8
Definition types.h:11