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 <cmath>
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 cXyz& operator=(const Vec& vec) {
40 this->x = vec.x;
41 this->y = vec.y;
42 this->z = vec.z;
43 return *this;
44 }
45 cXyz operator+(Vec const&) const;
46 cXyz operator-(Vec const&) const;
47 cXyz operator*(f32) const;
48 cXyz operator*(Vec const&) const;
49 cXyz operator/(f32) const;
50
52 x += f;
53 y += f;
54 z += f;
55 }
57 x -= f;
58 y -= f;
59 z -= f;
60 }
61
62 void operator*=(const Vec& other) {
63 x *= other.x;
64 y *= other.y;
65 z *= other.z;
66 }
67
68 cXyz* operator-=(const Vec& other) {
69 PSVECSubtract(this, &other, this);
70 return this;
71 }
72 cXyz* operator+=(const Vec& other) {
73 PSVECAdd(this, &other, this);
74 return this;
75 }
77 PSVECScale(this, this, scale);
78 return this;
79 }
81 PSVECScale(this, this, 1.0f / scale);
82 return this;
83 }
84 cXyz getCrossProduct(Vec const&) const;
85 cXyz outprod(Vec const&) const;
86 cXyz norm() const;
87 cXyz normZP() const;
88 cXyz normZC() const;
91 bool normalizeRS();
92 bool operator==(Vec const&) const;
93 bool operator!=(Vec const&) const;
94 bool isZero() const;
95 s16 atan2sX_Z() const;
96 s16 atan2sY_XZ() const;
97
98 void set(f32 pX, f32 pY, f32 pZ) {
99 x = pX;
100 y = pY;
101 z = pZ;
102 }
103
104 void set(const Vec& other) {
105 x = other.x;
106 y = other.y;
107 z = other.z;
108 }
109
110 f32 getXDiff(const Vec* other) const { return x - other->x; }
111 f32 getYDiff(const Vec* other) const { return y - other->y; }
112 f32 getZDiff(const Vec* other) const { return z - other->z; }
113
114 void setall(f32 f) { set(f, f, f); }
115
116 void zero() { set(0.0f, 0.0f, 0.0f); }
117
118 f32 getSquareMag() const { return PSVECSquareMag(this); }
119 f32 getSquareDistance(const Vec& other) const { return PSVECSquareDistance(this, &other); }
120
121 static f32 getNearZeroValue() { return 8e-11f; }
122
123 bool isNearZeroSquare() const { return (this->getSquareMag() < getNearZeroValue()); }
124 bool isNearZeroSquare(const cXyz& other) const { return (PSVECSquareMag(&other) < getNearZeroValue()); }
125
126 f32 abs2() const { return this->getSquareMag(); }
127 f32 abs2(const Vec& other) const { return this->getSquareDistance(other); }
128 f32 abs2XZ() const {
129 cXyz tmp(this->x, 0, this->z);
130 return tmp.abs2();
131 }
132 f32 abs2XZ(const Vec& other) const {
133 cXyz tmp(this->x, 0, this->z);
134 cXyz tmp2(other.x, 0, other.z);
135 return tmp.abs2(tmp2);
136 }
137
138 f32 abs() const { return sqrtf(this->abs2()); }
139 f32 abs(const Vec& other) const { return sqrtf(this->abs2(other)); }
140 f32 absXZ() const { return sqrtf(this->abs2XZ()); }
141 f32 absXZ(const Vec& other) const { return sqrtf(this->abs2XZ(other)); }
142
143 f32 getMagXZ() const { return cXyz(this->x, 0, this->z).getSquareMag(); }
144
145 f32 getDotProduct(const Vec& other) const { return PSVECDotProduct(this, &other); }
146
147 f32 inprod(const Vec& other) const { return getDotProduct(other); }
148 f32 inprodXZ(const Vec& other) const { return x * other.x + z * other.z; }
149};
150
151#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
f
Definition e_log.c:119
signed short int s16
Definition types.h:9
float f32
Definition types.h:25
f32 sqrtf(f32)
Definition sdk_math.h:3
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:76
f32 inprodXZ(const Vec &other) const
Definition c_xyz.h:148
cXyz normalize()
Definition c_xyz.cpp:92
f32 abs2XZ(const Vec &other) const
Definition c_xyz.h:132
cXyz operator+(Vec const &) const
Definition c_xyz.cpp:15
cXyz(f32 x, f32 y, f32 z)
Definition c_xyz.h:29
bool normalizeRS()
Definition c_xyz.cpp:107
f32 abs2(const Vec &other) const
Definition c_xyz.h:127
bool isNearZeroSquare() const
Definition c_xyz.h:123
f32 getSquareDistance(const Vec &other) const
Definition c_xyz.h:119
static const cXyz BaseYZ
Definition c_xyz.h:14
s16 atan2sY_XZ() const
Definition c_xyz.cpp:133
cXyz operator*(f32) const
Definition c_xyz.cpp:27
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:53
bool isNearZeroSquare(const cXyz &other) const
Definition c_xyz.h:124
f32 getDotProduct(const Vec &other) const
Definition c_xyz.h:145
cXyz(const cXyz &vec)
Definition c_xyz.h:19
void operator*=(const Vec &other)
Definition c_xyz.h:62
cXyz normZC() const
Definition c_xyz.cpp:74
static const cXyz BaseZ
Definition c_xyz.h:11
cXyz * operator-=(const Vec &other)
Definition c_xyz.h:68
bool operator==(Vec const &) const
Definition c_xyz.cpp:116
static const cXyz BaseXYZ
Definition c_xyz.h:15
cXyz * operator/=(f32 scale)
Definition c_xyz.h:80
static f32 getNearZeroValue()
Definition c_xyz.h:121
f32 abs(const Vec &other) const
Definition c_xyz.h:139
cXyz(const Vec &vec)
Definition c_xyz.h:34
~cXyz()
Definition c_xyz.h:18
cXyz operator/(f32) const
Definition c_xyz.cpp:41
void set(f32 pX, f32 pY, f32 pZ)
Definition c_xyz.h:98
cXyz * operator+=(const Vec &other)
Definition c_xyz.h:72
f32 abs2XZ() const
Definition c_xyz.h:128
cXyz getCrossProduct(Vec const &) const
Definition c_xyz.cpp:47
f32 getXDiff(const Vec *other) const
Definition c_xyz.h:110
void zero()
Definition c_xyz.h:116
cXyz normalizeZP()
Definition c_xyz.cpp:98
f32 getYDiff(const Vec *other) const
Definition c_xyz.h:111
void setall(f32 f)
Definition c_xyz.h:114
void set(const Vec &other)
Definition c_xyz.h:104
cXyz & operator=(const Vec &vec)
Definition c_xyz.h:39
s16 atan2sX_Z() const
Definition c_xyz.cpp:129
f32 abs() const
Definition c_xyz.h:138
void operator-=(f32 f)
Definition c_xyz.h:56
f32 getSquareMag() const
Definition c_xyz.h:118
f32 absXZ() const
Definition c_xyz.h:140
f32 getZDiff(const Vec *other) const
Definition c_xyz.h:112
static const cXyz BaseX
Definition c_xyz.h:9
cXyz normZP() const
Definition c_xyz.cpp:64
cXyz()=default
bool operator!=(Vec const &) const
Definition c_xyz.cpp:120
bool isZero() const
Definition c_xyz.cpp:124
f32 getMagXZ() const
Definition c_xyz.h:143
cXyz operator-(Vec const &) const
Definition c_xyz.cpp:21
void operator+=(f32 f)
Definition c_xyz.h:51
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:57
~cXyz()=default
f32 abs2() const
Definition c_xyz.h:126
f32 inprod(const Vec &other) const
Definition c_xyz.h:147
f32 absXZ(const Vec &other) const
Definition c_xyz.h:141