SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
CollisionParts.cpp
1#include "Game/Boss/BossStinkBug.hpp"
2#include "Game/Camera/CameraPolygonCodeUtil.hpp"
3#include "Game/Map/CollisionCategorizedKeeper.hpp"
4#include "Game/Map/CollisionDirector.hpp"
5#include "Game/Map/CollisionParts.hpp"
6#include "Game/Map/KCollision.hpp"
7#include "Game/LiveActor/HitSensor.hpp"
8#include "Game/LiveActor/LiveActor.hpp"
9#include "Game/Util/SceneUtil.hpp"
10
11CollisionParts::CollisionParts() {
12 _0 = nullptr;
13 mHitSensor = nullptr;
14 _CC = false;
15 _CD = true;
16 _CE = false;
17 _CF = false;
18 _D0 = false;
19 _D4 = 0;
20 _D8 = -1.0f;
21 _DC = 1.0f;
22 mKeeperIndex = -1;
23 mZone = nullptr;
24
25 mServer = new KCollisionServer();
26
27 mPrevBaseMatrix.identity();
28 mBaseMatrix.identity();
29 mMatrix.identity();
30 PSMTXInverse(reinterpret_cast<MtxPtr>(&mBaseMatrix), reinterpret_cast<MtxPtr>(&mInvBaseMatrix));
31}
32
33void CollisionParts::init(const TPos3f &a1, HitSensor *pHitSensor, const void *pKclData, const void *pMapInfo, long keeperIndex, bool a6) {
34 mServer->init(const_cast<void *>(pKclData), pMapInfo);
35 mHitSensor = pHitSensor;
36
37 resetAllMtx(a1);
38
39 TVec3f scale;
40 mBaseMatrix.getScale(scale);
41
42 CollisionDirector *director = MR::getCollisionDirector();
43 CollisionCategorizedKeeper *keeper = director->mKeepers[keeperIndex];
44 s32 zoneID = MR::getCurrentPlacementZoneId();
45
46 mZone = keeper->getZone(zoneID);
47
48 MR::initCameraCodeCollection(pHitSensor->mActor->mName, mZone->mZoneID);
49 mServer->calcFarthestVertexDistance();
50 MR::termCameraCodeCollection();
51
52 updateBoundingSphereRange(scale);
53 mKeeperIndex = keeperIndex;
54}
55
56void CollisionParts::addToBelongZone() {
57 s32 index = mKeeperIndex;
58 s32 zoneID = mZone->mZoneID;
59
60 CollisionDirector *director = MR::getCollisionDirector();
61 director->mKeepers[index]->addToZone(this, zoneID);
62}
63
64void CollisionParts::removeFromBelongZone() {
65 s32 index = mKeeperIndex;
66 s32 zoneID = mZone->mZoneID;
67
68 CollisionDirector *director = MR::getCollisionDirector();
69 director->mKeepers[index]->removeFromZone(this, zoneID);
70}
71
72void CollisionParts::initWithAutoEqualScale(const TPos3f &a1, HitSensor *pHitSensor, const void *pKclData, const void *pMapInfo, long keeperIndex, bool a6) {
73 _CF = true;
74 _D0 = false;
75
76 init(a1, pHitSensor, pKclData, pMapInfo, keeperIndex, a6);
77}
78
79void CollisionParts::initWithNotUsingScale(const TPos3f &a1, HitSensor *pHitSensor, const void *pKclData, const void *pMapInfo, long keeperIndex, bool a6) {
80 _CF = false;
81 _D0 = true;
82
83 init(a1, pHitSensor, pKclData, pMapInfo, keeperIndex, a6);
84}
85
86void CollisionParts::resetAllMtx(const TPos3f &a1) {
87 bool reset = false;
88
89 if (_CD || _CE) {
90 reset = true;
91 }
92
93 if (!reset) {
94 return;
95 }
96
97 resetAllMtxPrivate(a1);
98}
99
100void CollisionParts::resetAllMtx() {
101 bool reset = false;
102
103 if (_CD || _CE) {
104 reset = true;
105 }
106
107 if (reset) {
108 TPos3f matrix;
109 JMath::gekko_ps_copy12(&matrix, _0);
110 makeEqualScale(reinterpret_cast<MtxPtr>(&matrix));
111
112 resetAllMtxPrivate(matrix);
113 }
114}
115
116void CollisionParts::forceResetAllMtxAndSetUpdateMtxOneTime() {
117 TPos3f matrix;
118 JMath::gekko_ps_copy12(&matrix, _0);
119 makeEqualScale(reinterpret_cast<MtxPtr>(&matrix));
120 resetAllMtxPrivate(matrix);
121
122 _CE = true;
123}
124
125void CollisionParts::resetAllMtxPrivate(const TPos3f &a1) {
126 JMath::gekko_ps_copy12(&mPrevBaseMatrix, &a1);
127 JMath::gekko_ps_copy12(&mBaseMatrix, &a1);
128 JMath::gekko_ps_copy12(&mMatrix, &a1);
129 PSMTXInverse(reinterpret_cast<MtxPtr>(&mBaseMatrix), reinterpret_cast<MtxPtr>(&mInvBaseMatrix));
130}
131
132void CollisionParts::setMtx(const TPos3f &matrix) {
133 JMath::gekko_ps_copy12(&mMatrix, &matrix);
134}
135
136void CollisionParts::setMtx() {
137 JMath::gekko_ps_copy12(&mMatrix, _0);
138}
139
140void CollisionParts::updateMtx() {
141 bool bVar1 = false;
142
143 if (_CD || _CE) {
144 bVar1 = true;
145 }
146
147 if (!bVar1) {
148 if (MR::isSameMtx(reinterpret_cast<MtxPtr>(&mMatrix), reinterpret_cast<MtxPtr>(&mBaseMatrix))) {
149 _D4++;
150 }
151 }
152 else {
153 if (MR::isSameMtx(reinterpret_cast<MtxPtr>(&mMatrix), reinterpret_cast<MtxPtr>(&mBaseMatrix))) {
154 _D4++;
155 }
156 else {
157 if (_CE) {
158 _D4 = 1;
159 }
160 else {
161 _D4 = 0;
162 }
163
164 f32 dVar4 = makeEqualScale(reinterpret_cast<MtxPtr>(&mMatrix));
165 _E8 = dVar4;
166 f32 var = dVar4 - _DC;
167 _EC = dVar4;
168 _F0 = dVar4;
169
170 if (!MR::isNearZero(var, 0.001f)) {
171 updateBoundingSphereRangePrivate(dVar4);
172 }
173 }
174
175 _CE = false;
176
177 if (_D4 < 2) {
178 JMath::gekko_ps_copy12(&mPrevBaseMatrix, &mBaseMatrix);
179 JMath::gekko_ps_copy12(&mBaseMatrix, &mMatrix);
180 PSMTXInverse(reinterpret_cast<MtxPtr>(&mBaseMatrix), reinterpret_cast<MtxPtr>(&mInvBaseMatrix));
181 }
182 }
183}
184
185#ifdef NON_MATCHING
186// Issues with assignments of scaleDiff
187f32 CollisionParts::makeEqualScale(MtxPtr matrix) {
188 TPos3f &mtx = *reinterpret_cast<TPos3f *>(matrix);
189
190 TVec3f scale;
191 mtx.getScale(scale);
192
193 TVec3f scaleDiff;
194 scaleDiff.x = scale.z - scale.x;
195 scaleDiff.y = scale.y - scale.z;
196 scaleDiff.z = scale.x - scale.y;
197
198 if (MR::isNearZero(scaleDiff.x, 0.001f) && MR::isNearZero(scaleDiff.y, 0.001f) && MR::isNearZero(scaleDiff.z, 0.001f)) {
199 return scale.x;
200 }
201
202 f32 uniformScale = 1.0f;
203 TVec3f invScale;
204
205 if (_D0) {
206 invScale.set(uniformScale / scale.x, uniformScale / scale.y, uniformScale / scale.z);
207 uniformScale = 1.0f;
208 }
209 else if (_CF) {
210 uniformScale = (scale.x + scale.y + scale.z) / 3.0f;
211 invScale.set(uniformScale / scale.x, uniformScale / scale.y, uniformScale / scale.z);
212 }
213
214 mtx.mMtx[0][0] *= invScale.x;
215 mtx.mMtx[1][0] *= invScale.x;
216 mtx.mMtx[2][0] *= invScale.x;
217
218 mtx.mMtx[0][1] *= invScale.y;
219 mtx.mMtx[1][1] *= invScale.y;
220 mtx.mMtx[2][1] *= invScale.y;
221
222 mtx.mMtx[0][2] *= invScale.z;
223 mtx.mMtx[1][2] *= invScale.z;
224 mtx.mMtx[2][2] *= invScale.z;
225
226 return uniformScale;
227}
228#endif
229
230void CollisionParts::updateBoundingSphereRange() {
231 TMtx34f matrix;
232 JMath::gekko_ps_copy12(&matrix, _0);
233 f32 scale = makeEqualScale(reinterpret_cast<MtxPtr>(&matrix));
234 updateBoundingSphereRangePrivate(scale);
235}
236
237void CollisionParts::updateBoundingSphereRange(TVec3f a1) {
238 f32 range = (a1.x + a1.y + a1.z) / 3.0f;
239 updateBoundingSphereRangePrivate(range);
240}
241
242void CollisionParts::updateBoundingSphereRangePrivate(float scale) {
243 _DC = scale;
244 _D8 = scale * mServer->mMaxVertexDistance;
245}
246
247const char *CollisionParts::getHostName() const {
248 if (mHitSensor == nullptr) {
249 return nullptr;
250 }
251
252 LiveActor *actor = mHitSensor->mActor;
253
254 if (actor == nullptr) {
255 return nullptr;
256 }
257
258 return actor->mName;
259}
260
261s32 CollisionParts::getPlacementZoneID() const {
262 return mZone->mZoneID;
263}
264
265#ifdef NON_MATCHING
266// Instruction order
267void CollisionParts::projectToPlane(TVec3f *pProjected, const TVec3f &rPos, const TVec3f &rOrigin, const TVec3f &rNormal) {
268 TVec3f projected = rPos;
269
270 TVec3f relative = rPos;
271 relative.sub(rOrigin);
272
273 f32 distance = relative.dot(rNormal);
274
275 TVec3f negNormal = TVec3f(-rNormal);
276 negNormal.scale(distance);
277 projected.add(negNormal);
278 pProjected->set(projected);
279}
280#endif
281
282void CollisionParts::calcForceMovePower(TVec3f *a1, const TVec3f &a2) const {
283 TVec3f tStack88 = a2;
284 TMtx34f auStack76;
285 PSMTXInverse((MtxPtr)&mPrevBaseMatrix, reinterpret_cast<MtxPtr>(&auStack76));
286
287 auStack76.mult(tStack88, tStack88);
288 mBaseMatrix.mult(tStack88, tStack88);
289
290 tStack88.sub(a2);
291 *a1 = tStack88;
292}
The basis of a drawable actor that can contain states (see: Nerve)
Definition LiveActor.hpp:24
const char * mName
A string to identify the NameObj.
Definition NameObj.hpp:38