Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
c_xyz.h
Go to the documentation of this file.
1#ifndef C_XYZ_H
2#define C_XYZ_H
3
4#include "dolphin/mtx.h"
5#include "math.h"
6
7struct cXyz : Vec {
8 static const cXyz Zero;
9 static const cXyz BaseX;
10 static const cXyz BaseY;
11 static const cXyz BaseZ;
12 static const cXyz BaseXY;
13 static const cXyz BaseXZ;
14 static const cXyz BaseYZ;
15 static const cXyz BaseXYZ;
16#ifdef __MWERKS__
17 cXyz() {}
18 ~cXyz() {}
19 cXyz(const cXyz& vec) {
20 x = vec.x;
21 y = vec.y;
22 z = vec.z;
23 }
24#else
25 cXyz() = default;
26 ~cXyz() = default;
27 cXyz(const cXyz& vec) = default;
28#endif
30 this->x = x;
31 this->y = y;
32 this->z = z;
33 }
34 cXyz(const Vec& vec) {
35 this->x = vec.x;
36 this->y = vec.y;
37 this->z = vec.z;
38 }
39 void operator=(const Vec& vec) {
40 this->x = vec.x;
41 this->y = vec.y;
42 this->z = vec.z;
43 }
44 cXyz operator+(Vec const&) const;
45 cXyz operator-(Vec const&) const;
46 cXyz operator*(f32) const;
47 cXyz operator*(Vec const&) const;
48 cXyz operator/(f32) const;
49
50 void operator+=(f32 f) {
51 x += f;
52 y += f;
53 z += f;
54 }
55 void operator-=(f32 f) {
56 x -= f;
57 y -= f;
58 z -= f;
59 }
60
61 void operator*=(const Vec& other) {
62 x *= other.x;
63 y *= other.y;
64 z *= other.z;
65 }
66
67 cXyz* operator-=(const Vec& other) {
68 PSVECSubtract(this, &other, this);
69 return this;
70 }
71 cXyz* operator+=(const Vec& other) {
72 PSVECAdd(this, &other, this);
73 return this;
74 }
76 PSVECScale(this, this, scale);
77 return this;
78 }
80 PSVECScale(this, this, 1.0f / scale);
81 return this;
82 }
83 cXyz getCrossProduct(Vec const&) const;
84 cXyz outprod(Vec const&) const;
85 cXyz norm() const;
86 cXyz normZP() const;
87 cXyz normZC() const;
90 bool normalizeRS();
91 bool operator==(Vec const&) const;
92 bool operator!=(Vec const&) const;
93 bool isZero() const;
94 s16 atan2sX_Z() const;
95 s16 atan2sY_XZ() const;
96
97 void set(f32 pX, f32 pY, f32 pZ) {
98 x = pX;
99 y = pY;
100 z = pZ;
101 }
102
103 void set(const Vec& other) {
104 x = other.x;
105 y = other.y;
106 z = other.z;
107 }
108
109 f32 getXDiff(const Vec* other) const { return x - other->x; }
110 f32 getYDiff(const Vec* other) const { return y - other->y; }
111 f32 getZDiff(const Vec* other) const { return z - other->z; }
112
113 void setall(f32 f) { set(f, f, f); }
114
115 void zero() { set(0.0f, 0.0f, 0.0f); }
116
117 f32 getSquareMag() const { return PSVECSquareMag(this); }
118 f32 getSquareDistance(const Vec& other) const { return PSVECSquareDistance(this, &other); }
119
120 static f32 getNearZeroValue() { return 8e-11f; }
121
122 bool isNearZeroSquare() const { return (this->getSquareMag() < getNearZeroValue()); }
123 bool isNearZeroSquare(const cXyz& other) const { return (PSVECSquareMag(&other) < getNearZeroValue()); }
124
125 f32 abs2() const { return this->getSquareMag(); }
126 f32 abs2(const Vec& other) const { return this->getSquareDistance(other); }
127 f32 abs2XZ() const {
128 cXyz tmp(this->x, 0, this->z);
129 return tmp.abs2();
130 }
131 f32 abs2XZ(const Vec& other) const {
132 cXyz tmp(this->x, 0, this->z);
133 cXyz tmp2(other.x, 0, other.z);
134 return tmp.abs2(tmp2);
135 }
136
137 f32 abs() const { return sqrtf(this->abs2()); }
138 f32 abs(const Vec& other) const { return sqrtf(this->abs2(other)); }
139 f32 absXZ() const { return sqrtf(this->abs2XZ()); }
140 f32 absXZ(const Vec& other) const { return sqrtf(this->abs2XZ(other)); }
141
142 f32 getMagXZ() const { return cXyz(this->x, 0, this->z).getSquareMag(); }
143
144 f32 getDotProduct(const Vec& other) const { return PSVECDotProduct(this, &other); }
145
146 f32 inprod(const Vec& other) const { return getDotProduct(other); }
147 f32 inprodXZ(const Vec& other) const { return x * other.x + z * other.z; }
148};
149
150#endif /* C_XYZ_H */
asm f32 PSVECDotProduct(const __REGISTER Vec *a, const __REGISTER Vec *b)
Definition vec.c:181
f32 PSVECSquareMag(const __REGISTER Vec *v)
Definition vec.c:120
asm void PSVECAdd(const __REGISTER Vec *a, const __REGISTER Vec *b, __REGISTER Vec *ab)
Definition vec.c:14
f32 PSVECSquareDistance(const __REGISTER Vec *a, const __REGISTER Vec *b)
Definition vec.c:282
asm void PSVECSubtract(const __REGISTER Vec *a, const __REGISTER Vec *b, __REGISTER Vec *a_b)
Definition vec.c:34
void PSVECScale(const __REGISTER Vec *src, __REGISTER Vec *dst, __REGISTER f32 scale)
Definition vec.c:53
signed short int s16
Definition types.h:9
float f32
Definition types.h:25
float sqrtf(float mag)
Definition math.h:78
Definition mtx.h:13
f32 z
Definition mtx.h:14
f32 x
Definition mtx.h:14
f32 y
Definition mtx.h:14
Definition c_xyz.h:7
cXyz * operator*=(f32 scale)
Definition c_xyz.h:75
f32 inprodXZ(const Vec &other) const
Definition c_xyz.h:147
cXyz normalize()
Definition c_xyz.cpp:87
f32 abs2XZ(const Vec &other) const
Definition c_xyz.h:131
cXyz operator+(Vec const &) const
Definition c_xyz.cpp:10
cXyz(f32 x, f32 y, f32 z)
Definition c_xyz.h:29
bool normalizeRS()
Definition c_xyz.cpp:102
f32 abs2(const Vec &other) const
Definition c_xyz.h:126
bool isNearZeroSquare() const
Definition c_xyz.h:122
f32 getSquareDistance(const Vec &other) const
Definition c_xyz.h:118
static const cXyz BaseYZ
Definition c_xyz.h:14
s16 atan2sY_XZ() const
Definition c_xyz.cpp:128
cXyz operator*(f32) const
Definition c_xyz.cpp:22
cXyz()
Definition c_xyz.h:17
cXyz(const cXyz &vec)=default
static const cXyz BaseXZ
Definition c_xyz.h:13
static const cXyz BaseY
Definition c_xyz.h:10
cXyz outprod(Vec const &) const
Definition c_xyz.cpp:48
bool isNearZeroSquare(const cXyz &other) const
Definition c_xyz.h:123
f32 getDotProduct(const Vec &other) const
Definition c_xyz.h:144
cXyz(const cXyz &vec)
Definition c_xyz.h:19
void operator=(const Vec &vec)
Definition c_xyz.h:39
void operator*=(const Vec &other)
Definition c_xyz.h:61
cXyz normZC() const
Definition c_xyz.cpp:69
static const cXyz BaseZ
Definition c_xyz.h:11
cXyz * operator-=(const Vec &other)
Definition c_xyz.h:67
bool operator==(Vec const &) const
Definition c_xyz.cpp:111
static const cXyz BaseXYZ
Definition c_xyz.h:15
cXyz * operator/=(f32 scale)
Definition c_xyz.h:79
static f32 getNearZeroValue()
Definition c_xyz.h:120
f32 abs(const Vec &other) const
Definition c_xyz.h:138
cXyz(const Vec &vec)
Definition c_xyz.h:34
~cXyz()
Definition c_xyz.h:18
cXyz operator/(f32) const
Definition c_xyz.cpp:36
void set(f32 pX, f32 pY, f32 pZ)
Definition c_xyz.h:97
cXyz * operator+=(const Vec &other)
Definition c_xyz.h:71
f32 abs2XZ() const
Definition c_xyz.h:127
cXyz getCrossProduct(Vec const &) const
Definition c_xyz.cpp:42
f32 getXDiff(const Vec *other) const
Definition c_xyz.h:109
void zero()
Definition c_xyz.h:115
cXyz normalizeZP()
Definition c_xyz.cpp:93
f32 getYDiff(const Vec *other) const
Definition c_xyz.h:110
void setall(f32 f)
Definition c_xyz.h:113
void set(const Vec &other)
Definition c_xyz.h:103
s16 atan2sX_Z() const
Definition c_xyz.cpp:124
f32 abs() const
Definition c_xyz.h:137
void operator-=(f32 f)
Definition c_xyz.h:55
f32 getSquareMag() const
Definition c_xyz.h:117
f32 absXZ() const
Definition c_xyz.h:139
f32 getZDiff(const Vec *other) const
Definition c_xyz.h:111
static const cXyz BaseX
Definition c_xyz.h:9
cXyz normZP() const
Definition c_xyz.cpp:59
cXyz()=default
bool operator!=(Vec const &) const
Definition c_xyz.cpp:115
bool isZero() const
Definition c_xyz.cpp:119
f32 getMagXZ() const
Definition c_xyz.h:142
cXyz operator-(Vec const &) const
Definition c_xyz.cpp:16
void operator+=(f32 f)
Definition c_xyz.h:50
static const cXyz BaseXY
Definition c_xyz.h:12
static const cXyz Zero
Definition c_xyz.h:8
cXyz norm() const
Definition c_xyz.cpp:52
~cXyz()=default
f32 abs2() const
Definition c_xyz.h:125
f32 inprod(const Vec &other) const
Definition c_xyz.h:146
f32 absXZ(const Vec &other) const
Definition c_xyz.h:140