Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
vec.h
Go to the documentation of this file.
1#ifndef VEC_H
2#define VEC_H
3
4#include "dolphin/types.h"
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef struct Vec {
11 f32 x, y, z;
13
14typedef Vec* VecPtr;
15typedef Vec Point3d;
16typedef Vec* Point3dPtr;
17
18typedef struct SVec {
19 s16 x, y, z;
21
22void PSVECAdd(const Vec* a, const Vec* b, Vec* ab);
23void PSVECSubtract(const Vec* a, const Vec* b, Vec* a_b);
24void PSVECScale(const Vec* src, Vec* dst, f32 scale);
25void PSVECNormalize(const Vec* src, Vec* unit);
27f32 PSVECMag(const Vec* v);
28f32 PSVECDotProduct(const Vec* a, const Vec* b);
29void PSVECCrossProduct(const Vec* a, const Vec* b, Vec* axb);
30f32 PSVECSquareDistance(const Vec* a, const Vec* b);
31f32 PSVECDistance(const Vec* a, const Vec* b);
32
33void C_VECHalfAngle(const Vec* a, const Vec* b, Vec* half);
34void C_VECReflect(const Vec* src, const Vec* normal, Vec* dst);
35
36inline void C_VECAdd(register const Vec* a, register const Vec* b, register Vec* ab) {
37 register f32 axy;
38 register f32 bxy;
39 register f32 az;
40 register f32 sumz;
41 register f32 bz;
42 asm {
43 psq_l axy, 0(a), 0, 0
44 psq_l bxy, 0(b), 0, 0
46 psq_st bxy, 0(ab), 0, 0
47 psq_l az, 8(a), 1, 0
48 psq_l bz, 8(b), 1, 0
50 psq_st sumz, 8(ab), 1, 0
51 }
52}
53
54inline void C_VECSubtract(register const Vec* a, register const Vec* b, register Vec* ab) {
55 register f32 axy;
56 register f32 bxy;
57 register f32 az;
58 register f32 subz;
59 register f32 bz;
60 asm {
61 psq_l axy, 0(a), 0, 0
62 psq_l bxy, 0(b), 0, 0
64 psq_st bxy, 0(ab), 0, 0
65 psq_l az, 8(a), 1, 0
66 psq_l bz, 8(b), 1, 0
68 psq_st subz, 8(ab), 1, 0
69 }
70}
71
72inline f32 C_VECSquareMag(const Vec* v) {
73 register f32 x_y;
74 register f32 z;
75 register f32 res;
76 register const f32* src = &v->x;
77 asm {
78 psq_l x_y, 0(src), 0, 0
80 lfs z, 8(src)
81 ps_madd res, z, z, x_y
83 }
84 ;
85 return res;
86}
87
88/* When compiling in debug mode, use C implementations */
89#ifdef DEBUG
90// TODO: Add debug rom C implementations
91/* #define VECAdd C_VECAdd
92#define VECSubtract C_VECSubtract
93#define VECScale C_VECScale
94#define VECNormalize C_VECNormalize
95#define VECSquareMag C_VECSquareMag
96#define VECMag C_VECMag
97#define VECDotProduct C_VECDotProduct
98#define VECCrossProduct C_VECCrossProduct
99#define VECSquareDistance C_VECSquareDistance
100#define VECDistance C_VECDistance */
101
102#define VECAdd PSVECAdd
103#define VECSubtract PSVECSubtract
104#define VECScale PSVECScale
105#define VECNormalize PSVECNormalize
106#define VECSquareMag PSVECSquareMag
107#define VECMag PSVECMag
108#define VECDotProduct PSVECDotProduct
109#define VECCrossProduct PSVECCrossProduct
110#define VECSquareDistance PSVECSquareDistance
111#define VECDistance PSVECDistance
112#else
113#define VECAdd PSVECAdd
114#define VECSubtract PSVECSubtract
115#define VECScale PSVECScale
116#define VECNormalize PSVECNormalize
117#define VECSquareMag PSVECSquareMag
118#define VECMag PSVECMag
119#define VECDotProduct PSVECDotProduct
120#define VECCrossProduct PSVECCrossProduct
121#define VECSquareDistance PSVECSquareDistance
122#define VECDistance PSVECDistance
123#endif
124
125#ifdef __cplusplus
126};
127#endif
128
129#endif /* VEC_H */
T cLib_calcTimer(T *value)
Definition c_lib.h:74
void PSVECSquareDistance()
void PSVECSquareMag()
static SECTION_DATA u8 az[16]
Definition d_a_mg_rod.cpp:618
static SECTION_DATA u8 normal[12]
Definition d_a_npc_pouya.cpp:546
void PSVECAdd()
double v
Definition e_pow.c:163
z
Definition e_pow.c:390
a
Definition k_cos.c:89
static const static double double half
Definition k_sin.c:49
Definition vec.h:18
s16 x
Definition vec.h:19
s16 z
Definition vec.h:19
s16 y
Definition vec.h:19
Definition d_a_hozelda.cpp:18
f32 z
Definition vec.h:11
f32 x
Definition vec.h:11
f32 y
Definition vec.h:11
float f32
Definition types.h:22
signed short s16
Definition types.h:5
void PSVECScale(const Vec *src, Vec *dst, f32 scale)
f32 PSVECMag(const Vec *v)
void C_VECAdd(register const Vec *a, register const Vec *b, register Vec *ab)
Definition vec.h:36
f32 C_VECSquareMag(const Vec *v)
Definition vec.h:72
f32 PSVECDistance(const Vec *a, const Vec *b)
void C_VECHalfAngle(const Vec *a, const Vec *b, Vec *half)
Definition vec.c:185
void PSVECCrossProduct(const Vec *a, const Vec *b, Vec *axb)
Vec Point3d
Definition vec.h:15
f32 PSVECDotProduct(const Vec *a, const Vec *b)
Vec * Point3dPtr
Definition vec.h:16
void PSVECNormalize(const Vec *src, Vec *unit)
void C_VECReflect(const Vec *src, const Vec *normal, Vec *dst)
Definition vec.c:210
void PSVECSubtract(const Vec *a, const Vec *b, Vec *a_b)
Vec * VecPtr
Definition vec.h:14
void C_VECSubtract(register const Vec *a, register const Vec *b, register Vec *ab)
Definition vec.h:54