SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
AreaForm.cpp
1#include "Game/AreaObj/AreaForm.hpp"
2#include "JSystem/JMath/JMath.hpp"
3#include "Game/Util.hpp"
4
5AreaFormCube::AreaFormCube(int a1) {
6 _4 = 0;
7 _8 = a1;
8 mTranslation.x = 0.0f;
9 mTranslation.y = 0.0f;
10 mTranslation.z = 0.0f;
11 mRotation.x = 0.0f;
12 mRotation.y = 0.0f;
13 mRotation.z = 0.0f;
14 mScale.x = 1.0f;
15 mScale.y = 1.0f;
16 mScale.z = 1.0f;
17 mBounding.mMin.x = 0.0f;
18 mBounding.mMin.y = 0.0f;
19 mBounding.mMin.z = 0.0f;
20 mBounding.mMax.x = 0.0f;
21 mBounding.mMax.y = 0.0f;
22 mBounding.mMax.z = 0.0f;
23}
24
25void AreaFormCube::init(const JMapInfoIter &rIter) {
26 MR::getJMapInfoTrans(rIter, &mTranslation);
27 MR::getJMapInfoRotate(rIter, &mRotation);
28 MR::getJMapInfoScale(rIter, &mScale);
29 updateBoxParam();
30}
31
32bool AreaFormCube::isInVolume(const TVec3f &rPos) const {
33 TPos3f pos;
34 calcWorldMtx(&pos);
35
36 TVec3f transpose;
37 pos.multTranspose(rPos, transpose);
38
39 bool res = false;
40
41 if (transpose.x >= mBounding.mMin.x && transpose.y >= mBounding.mMin.y && transpose.z >= mBounding.mMin.z && transpose.x < mBounding.mMax.x && transpose.y < mBounding.mMax.y && transpose.z < mBounding.mMax.z) {
42 res = true;
43 }
44
45 return res;
46}
47
48void AreaFormCube::calcWorldPos(TVec3f *pPos) const {
49 if (_4) {
50 _4->mult(mTranslation, *pPos);
51 return;
52 }
53
54 pPos->set<f32>(mTranslation);
55}
56
57// AreaFormCube::calcWorldRotate
58
59void AreaFormCube::calcWorldBox(TDirBox3f *pBox) const {
60 TPos3f pos;
61 calcWorldMtx(&pos);
62
63 pBox->_0.x = pos.mMtx[0][0];
64 pBox->_C.x = pos.mMtx[0][1];
65 pBox->_18.x = pos.mMtx[0][2];
66 pBox->_24.x = pos.mMtx[0][3];
67 pBox->_0.y = pos.mMtx[1][0];
68 pBox->_C.y = pos.mMtx[1][1];
69 pBox->_18.y = pos.mMtx[1][2];
70 pBox->_24.y = pos.mMtx[1][3];
71 pBox->_0.z = pos.mMtx[2][0];
72 pBox->_C.z = pos.mMtx[2][1];
73 pBox->_18.z = pos.mMtx[2][2];
74 pBox->_24.z = pos.mMtx[2][3];
75
76 JMathInlineVEC::PSVECSubtract(mBounding.mMax.toCVec(), mBounding.mMin.toCVec(), pBox->_30.toVec());
77 pos.mult(mBounding.mMin, pBox->_24);
78}
79
80void AreaFormCube::calcLocalPos(TVec3f *pPos, const TVec3f &a2) const {
81 TPos3f worldMtx;
82 calcWorldMtx(&worldMtx);
83 worldMtx.multTranspose(a2, *pPos);
84}
85
86f32 AreaFormCube::getBaseSize() {
87 return 1000.0f;
88}
89
90
91#ifdef NON_MATCHING
92// issues with floating point math order
93void AreaFormCube::updateBoxParam() {
94 MR::makeMtxRotate(_48, mRotation.x, mRotation.y, mRotation.z);
95
96 f32 v3 = (0.5f * (-mScale.x * 1000.0f));
97 f32 v5 = (0.5f * (-mScale.y * 1000.0f));
98 f32 v6 = (0.5f * (-mScale.z * 1000.0f));
99
100 _48[0][3] = mTranslation.x;
101 _48[1][3] = mTranslation.y;
102 _48[2][3] = mTranslation.z;
103
104 TVec3f v10(v3, v5, v6);
105
106 f32 v20 = (0.5f * (mScale.x * 1000.0f));
107 f32 v21 = (0.5f * (mScale.y * 1000.0f));
108 f32 v22 = (0.5f * (mScale.z * 1000.0f));
109
110 TVec3f v9(v20, v21, v22);
111
112 _30.set<f32>(v10);
113 _3C.set<f32>(v9);
114
115 if (_8 == 1) {
116 TVec3f temp;
117
118 f32 v7 = mScale.y * 1000.0f;
119 temp.x = 0.0f;
120 temp.z = 0.0f;
121 temp.y = 0.5f * v7;
122
123 _30.add(temp);
124 _3C.add(temp);
125 }
126}
127#endif
128
129void AreaFormCube::calcWorldMtx(register TPos3f *pPos) const {
130 register const AreaFormCube* cube = this;
131
132 if (_4) {
133 return pPos->concat(*_4, (const TSMtxf&)*_48);
134 }
135
136 __asm {
137 psq_l f0, 0x48(cube), 0, 0
138 psq_l f1, 0x50(cube), 0, 0
139 psq_l f2, 0x58(cube), 0, 0
140 psq_l f3, 0x60(cube), 0, 0
141 psq_l f4, 0x68(cube), 0, 0
142 psq_l f5, 0x70(cube), 0, 0
143 psq_st f0, 0(pPos), 0, 0
144 psq_st f1, 8(pPos), 0, 0
145 psq_st f2, 0x10(pPos), 0, 0
146 psq_st f3, 0x18(pPos), 0, 0
147 psq_st f4, 0x20(pPos), 0, 0
148 psq_st f5, 0x28(pPos), 0, 0
149 };
150}
151
152AreaFormSphere::AreaFormSphere() {
153 _4 = 0;
154 mTranslation.x = 0.0f;
155 mTranslation.y = 0.0f;
156 mTranslation.z = 0.0f;
157 _14 = 0.0f;
158}
159
160void AreaFormSphere::calcUpVec(TVec3f *pOut) const {
161 if (_4) {
162 _4->mult33(mUp, *pOut);
163 MR::normalize(pOut);
164 }
165 else {
166 pOut->set<f32>(mUp);
167 }
168}
169
170void AreaFormSphere::calcPos(TVec3f *pOut) const {
171 if (_4) {
172 _4->mult(mTranslation, *pOut);
173 }
174 else {
175 pOut->set<f32>(mTranslation);
176 }
177}
178
179bool AreaFormSphere::isInVolume(const TVec3f &rVector) const {
180 TVec3f pos;
181 calcPos(&pos);
182
183 TVec3f thing(rVector);
184 JMathInlineVEC::PSVECSubtract(thing.toCVec(), pos.toCVec(), thing.toVec());
185 return PSVECMag(thing.toCVec()) < _14;
186}
187
188AreaFormBowl::AreaFormBowl() {
189 _4 = 0;
190 mTranslation.x = 0.0f;
191 mTranslation.y = 0.0f;
192 mTranslation.z = 0.0f;
193 _20 = 0.0f;
194}
195
196void AreaFormBowl::init(const JMapInfoIter &rIter) {
197 MR::getJMapInfoTrans(rIter, &mTranslation);
198
199 f32 scale_x;
200 rIter.getValue<f32>("scale_x", &scale_x);
201 _20 = scale_x;
202 _20 *= 500.0f;
203
204 TVec3f rotation;
205 MR::getJMapInfoRotate(rIter, &rotation);
206 calcUpVec(rotation);
207}
208
209bool AreaFormBowl::isInVolume(const TVec3f &rPos) const {
210 TVec3f pos(rPos);
211 JMathInlineVEC::PSVECSubtract(pos.toCVec(), mTranslation.toCVec(), pos.toVec());
212
213 if (PSVECMag((const Vec*)&pos) > _20) {
214 return false;
215 }
216
217 TVec3f other_pos(rPos);
218 PSVECSubtract((const Vec*)&other_pos, (const Vec*)&mTranslation, (Vec*)&other_pos);
219 return other_pos.dot(mUp) < 0.0f;
220}
221
222void AreaFormBowl::calcUpVec(const TVec3f &rPos) {
223 TVec3f up(0.0f, 1.0f, 0.0f);
224
225 Mtx mtx;
226 MR::makeMtxTR(mtx, 0.0f, 0.0f, 0.0f, rPos.x, rPos.y, rPos.z);
227 PSMTXMultVec(mtx, (const Vec*)&up, (Vec*)&up);
228 mUp = up;
229}
230
231AreaFormCylinder::AreaFormCylinder() {
232 _4 = 0;
233 mTranslation.x = 0.0f;
234 mTranslation.y = 0.0f;
235 mTranslation.z = 0.0f;
236 mRotation.x = 0.0f;
237 mRotation.y = 0.0f;
238 mRotation.z = 0.0f;
239 _20 = 0.0f;
240 _24 = 0.0f;
241}
242
243void AreaFormCylinder::calcPos(TVec3f *pPos) const {
244 if (_4) {
245 _4->mult(mTranslation, *pPos);
246 return;
247 }
248
249 pPos->set<f32>(mTranslation);
250}
251
252void AreaFormCylinder::calcCenterPos(TVec3f *pCenterPos) const {
253 calcPos(pCenterPos);
254 TVec3f upVec;
255 calcUpVec(&upVec);
256
257 pCenterPos->add((upVec * _24) * 0.5f);
258}
259
260void AreaFormCylinder::calcUpVec(TVec3f *pUpVec) const {
261 if (_4) {
262 _4->mult33(mRotation, *pUpVec);
263 MR::normalize(pUpVec);
264 }
265 else {
266 pUpVec->set<f32>(mRotation);
267 }
268}
269
270bool AreaFormCylinder::isInVolume(const TVec3f &rVec) const {
271 TVec3f pos;
272 calcPos(&pos);
273
274 TVec3f up;
275 calcUpVec(&up);
276
277 TVec3f stack_8(rVec);
278 JMathInlineVEC::PSVECSubtract((const Vec*)&stack_8, (const Vec*)&pos, (Vec*)&stack_8);
279 f32 v6 = MR::vecKillElement(stack_8, up, &stack_8);
280 f32 v7 = PSVECMag((const Vec*)&stack_8);
281
282 bool ret;
283
284 if (MR::isInRange(v6, 0.0f, _24) && (v7 < _20)) {
285 ret = true;
286 }
287 else {
288 ret = false;
289 }
290
291 return ret;
292}
293
294void AreaFormCylinder::calcDir(const TVec3f &a1) {
295 mRotation.x = 0.0f;
296 mRotation.y = 1.0f;
297 mRotation.z = 0.0f;
298
299 MtxPtr mtx_x = MR::tmpMtxRotXDeg(a1.x);
300 PSMTXMultVec(mtx_x, (const Vec*)&mRotation, (Vec*)&mRotation);
301 MtxPtr mtx_y = MR::tmpMtxRotYDeg(a1.y);
302 PSMTXMultVec(mtx_y, (const Vec*)&mRotation, (Vec*)&mRotation);
303 MtxPtr mtx_z = MR::tmpMtxRotYDeg(a1.z);
304 PSMTXMultVec(mtx_z, (const Vec*)&mRotation, (Vec*)&mRotation);
305 PSVECMag((const Vec*)&mRotation);
306 PSVECNormalize((const Vec*)&mRotation, (Vec*)&mRotation);
307}
308
309void AreaFormSphere::init(const JMapInfoIter &rIter) {
310 MR::getJMapInfoTrans(rIter, &mTranslation);
311
312 f32 scale_x;
313 rIter.getValue<f32>("scale_x", &scale_x);
314
315 _14 = scale_x;
316 _14 *= 500.0f;
317
318 TVec3f rotation;
319 MR::getJMapInfoRotate(rIter, &rotation);
320
321 TVec3f butts(0.0f, 1.0f, 0.0f);
322
323 Mtx mtx;
324 MR::makeMtxTR(mtx, 0.0f, 0.0f, 0.0f, rotation.x, rotation.y, rotation.z);
325 PSMTXMultVec(mtx, (const Vec*)&butts, (Vec*)&butts);
326 mUp = butts;
327}
328
329void AreaFormCylinder::init(const JMapInfoIter &rIter) {
330 MR::getJMapInfoTrans(rIter, &mTranslation);
331 TVec3f rotate;
332
333 MR::getJMapInfoRotate(rIter, &rotate);
334 calcDir(rotate);
335
336 f32 temp;
337 rIter.getValue<f32>("scale_x", &temp);
338
339 _20 = temp;
340 _20 *= 500.0f;
341
342 rIter.getValue<f32>("scale_y", &temp);
343 _24 = temp;
344 _24 *= 500.0f;
345}