SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
CollisionArea.cpp
1#include "Game/AreaObj/CollisionArea.hpp"
2#include "Game/MapObj/DynamicCollisionObj.hpp"
3#include "Game/Util/JMapUtil.hpp"
4#include "Game/Util/LiveActorUtil.hpp"
5#include "Game/Util/PlayerUtil.hpp"
6#include "Inline.hpp"
7
8DynamicCollisionObj::~DynamicCollisionObj() {
9
10}
11
12bool AreaObj::isValid() const {
13 bool valid = false;
14
15 if (mValid && _15 && mAwake) {
16 valid = true;
17 }
18
19 return valid;
20}
21
22AreaPolygon::AreaPolygon() : DynamicCollisionObj("エリアポリゴン") {
23 mForm = nullptr;
24 _128 = nullptr;
25 _12C.zero();
26}
27
28AreaPolygon::~AreaPolygon() {
29
30}
31
32/*void AreaPolygon::init(const JMapInfoIter &rIter) {
33 if (MR::isValidInfo(rIter)) {
34 MR::initDefaultPos(this, rIter);
35 }
36 else {
37 MR::extractMtxTrans(_128, &mPosition);
38 mRotation.x = 0.0f;
39 mRotation.y = 0.0f;
40 mRotation.z = 0.0f;
41 }
42
43 mScale.x = 1.0f;
44 mScale.y = 1.0f;
45 mScale.z = 1.0f;
46 _8C = nullptr;
47 mNrTriangles = 4;
48 _94 = 2;
49
50 mPositions = new TVec3f[12];
51 setSurface(0);
52 initHitSensor(1);
53
54 TVec3f local28 = CALL_INLINE_FUNC(TVec3f, 1.0f, 1.0f, 1.0f);
55 MR::addHitSensorEye(this, "body", 8, 1.0f, local28);
56
57 mIndices = new TriangleIndexing[_94];
58 _9C = new TVec3f[_94];
59
60 mIndices[0].mIndex[0] = 0;
61 mIndices[0].mIndex[1] = 0;
62 mIndices[0].mIndex[2] = 0;
63
64 mIndices[1].mIndex[0] = 0;
65 mIndices[1].mIndex[2] = 0;
66 mIndices[1].mIndex[3] = 0;
67
68 createCollision();
69 makeActorAppeared();
70}*/
71
72void AreaPolygon::setMtx(MtxPtr matrix, const TVec3f &a2, float a3) {
73 _128 = matrix;
74 _12C = a2;
75 _138 = a3;
76}
77
78void AreaPolygon::setSurfaceAndSync(long a1) {
79 setSurface(a1);
80
81 if (a1 != -1) {
82 syncCollision();
83 }
84}
85
86void AreaPolygon::invalidate() {
87 MR::invalidateCollisionParts(mParts);
88}
89
90void AreaPolygon::validate() {
91 MR::validateCollisionParts(mParts);
92}
93
94CollisionArea::CollisionArea(int type, const char *pName) : AreaObj(type, pName) {
95 _3C = 0;
96 _40 = 0.0f;
97 _44.zero();
98 _50 = 0;
99 _54 = 0;
100 _58 = false;
101 _5C = 0;
102 _60 = 0;
103 mPolygon = nullptr;
104 mIsValid = false;
105}
106
107CollisionArea::~CollisionArea() {
108
109}
110
112 AreaObj::init(rIter);
113 MR::connectToSceneAreaObj(this);
114
115 _50 = -1;
116 _3C = 0;
117 _40 = 0.0f;
118 _54 = -1;
119 _5C = 0;
120 _60 = -1;
121
122 MR::getJMapInfoArg0NoInit(rIter, &_50);
123 MR::getJMapInfoArg1NoInit(rIter, &_54);
124 MR::getJMapInfoArg2NoInit(rIter, &_5C);
125 MR::getJMapInfoArg3NoInit(rIter, &_60);
126
127 _58 = false;
128
129 if (_60 == 0) {
130 mPolygon = nullptr;
131 }
132 else {
133 mPolygon = new AreaPolygon();
134 mPolygon->mForm = mForm;
135 mPolygon->init(rIter);
136 MR::validateCollisionParts(mPolygon->mParts);
137
138 if (!isValid()) {
139 MR::invalidateCollisionParts(mPolygon->mParts);
140 }
141 }
142
143 mIsValid = isValid();
144}
145
146void CollisionArea::movement() {
147 if (!isValid()) {
148 if (mIsValid) {
149 if (mPolygon != nullptr) {
150 MR::invalidateCollisionParts(mPolygon->mParts);
151 }
152
153 mIsValid = false;
154 }
155 }
156 else {
157 if (!mIsValid) {
158 if (mPolygon != nullptr) {
159 MR::validateCollisionParts(mPolygon->mParts);
160 }
161
162 mIsValid = true;
163 }
164
165 if (_54 == -1 && MR::isPlayerTeresaDisappear()) {
166 _58 = true;
167
168 if (mPolygon != nullptr) {
169 MR::invalidateCollisionParts(mPolygon->mParts);
170 }
171 }
172 else {
173 TVec3f playerPos = *MR::getPlayerCenterPos();
174 f32 dVar4 = static_cast<f32>(_5C);
175
176 if (_5C == 0) {
177 dVar4 = MR::getPlayerHitRadius();
178 }
179
180 if (_58) {
181 dVar4 += 5.0f;
182 }
183
184 TVec3f tStack60;
185 TVec3f tStack72;
186
187 if (!hitCheck(playerPos, dVar4, &tStack60, &tStack72)) {
188 if (_58) {
189 _58 = false;
190
191 if (mPolygon != nullptr) {
192 MR::validateCollisionParts(mPolygon->mParts);
193 }
194 }
195 }
196 else if (!_58 && _50 == -1) {
197 TVec3f tStack84;
198
199 if (_3C == 0) {
200 tStack84 = tStack72;
201 tStack84.setLength(dVar4 + _40);
202 }
203 else {
204 TVec3f tStack96;
205 TVec3f tStack108 = playerPos;
206 tStack108.sub(tStack60);
207
208 tStack84 = tStack108;
209 tStack84.setLength(dVar4);
210
211 tStack96 = tStack60;
212 tStack96.add(tStack84);
213
214 TVec3f tStack120 = tStack96;
215 tStack120.sub(playerPos);
216 tStack84 = tStack120;
217 }
218
219 if (tStack84.dot(tStack72) > 0) {
220 MR::pushPlayerFromArea(tStack84);
221 }
222 }
223 }
224 }
225}
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition AreaObj.cpp:41
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.