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"
11CollisionParts::CollisionParts() {
27 mPrevBaseMatrix.identity();
28 mBaseMatrix.identity();
30 PSMTXInverse(
reinterpret_cast<MtxPtr
>(&mBaseMatrix),
reinterpret_cast<MtxPtr
>(&mInvBaseMatrix));
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;
40 mBaseMatrix.getScale(scale);
44 s32 zoneID = MR::getCurrentPlacementZoneId();
46 mZone = keeper->getZone(zoneID);
48 MR::initCameraCodeCollection(pHitSensor->mActor->
mName, mZone->mZoneID);
49 mServer->calcFarthestVertexDistance();
50 MR::termCameraCodeCollection();
52 updateBoundingSphereRange(scale);
53 mKeeperIndex = keeperIndex;
56void CollisionParts::addToBelongZone() {
57 s32 index = mKeeperIndex;
58 s32 zoneID = mZone->mZoneID;
61 director->mKeepers[index]->addToZone(
this, zoneID);
64void CollisionParts::removeFromBelongZone() {
65 s32 index = mKeeperIndex;
66 s32 zoneID = mZone->mZoneID;
69 director->mKeepers[index]->removeFromZone(
this, zoneID);
72void CollisionParts::initWithAutoEqualScale(
const TPos3f &a1,
HitSensor *pHitSensor,
const void *pKclData,
const void *pMapInfo,
long keeperIndex,
bool a6) {
76 init(a1, pHitSensor, pKclData, pMapInfo, keeperIndex, a6);
79void CollisionParts::initWithNotUsingScale(
const TPos3f &a1,
HitSensor *pHitSensor,
const void *pKclData,
const void *pMapInfo,
long keeperIndex,
bool a6) {
83 init(a1, pHitSensor, pKclData, pMapInfo, keeperIndex, a6);
86void CollisionParts::resetAllMtx(
const TPos3f &a1) {
97 resetAllMtxPrivate(a1);
100void CollisionParts::resetAllMtx() {
109 JMath::gekko_ps_copy12(&matrix, _0);
110 makeEqualScale(
reinterpret_cast<MtxPtr
>(&matrix));
112 resetAllMtxPrivate(matrix);
116void CollisionParts::forceResetAllMtxAndSetUpdateMtxOneTime() {
118 JMath::gekko_ps_copy12(&matrix, _0);
119 makeEqualScale(
reinterpret_cast<MtxPtr
>(&matrix));
120 resetAllMtxPrivate(matrix);
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));
132void CollisionParts::setMtx(
const TPos3f &matrix) {
133 JMath::gekko_ps_copy12(&mMatrix, &matrix);
136void CollisionParts::setMtx() {
137 JMath::gekko_ps_copy12(&mMatrix, _0);
140void CollisionParts::updateMtx() {
148 if (MR::isSameMtx(
reinterpret_cast<MtxPtr
>(&mMatrix),
reinterpret_cast<MtxPtr
>(&mBaseMatrix))) {
153 if (MR::isSameMtx(
reinterpret_cast<MtxPtr
>(&mMatrix),
reinterpret_cast<MtxPtr
>(&mBaseMatrix))) {
164 f32 dVar4 = makeEqualScale(
reinterpret_cast<MtxPtr
>(&mMatrix));
166 f32 var = dVar4 - _DC;
170 if (!MR::isNearZero(var, 0.001f)) {
171 updateBoundingSphereRangePrivate(dVar4);
178 JMath::gekko_ps_copy12(&mPrevBaseMatrix, &mBaseMatrix);
179 JMath::gekko_ps_copy12(&mBaseMatrix, &mMatrix);
180 PSMTXInverse(
reinterpret_cast<MtxPtr
>(&mBaseMatrix),
reinterpret_cast<MtxPtr
>(&mInvBaseMatrix));
187f32 CollisionParts::makeEqualScale(MtxPtr matrix) {
188 TPos3f &mtx = *
reinterpret_cast<TPos3f *
>(matrix);
194 scaleDiff.x = scale.z - scale.x;
195 scaleDiff.y = scale.y - scale.z;
196 scaleDiff.z = scale.x - scale.y;
198 if (MR::isNearZero(scaleDiff.x, 0.001f) && MR::isNearZero(scaleDiff.y, 0.001f) && MR::isNearZero(scaleDiff.z, 0.001f)) {
202 f32 uniformScale = 1.0f;
206 invScale.set(uniformScale / scale.x, uniformScale / scale.y, uniformScale / scale.z);
210 uniformScale = (scale.x + scale.y + scale.z) / 3.0f;
211 invScale.set(uniformScale / scale.x, uniformScale / scale.y, uniformScale / scale.z);
214 mtx.mMtx[0][0] *= invScale.x;
215 mtx.mMtx[1][0] *= invScale.x;
216 mtx.mMtx[2][0] *= invScale.x;
218 mtx.mMtx[0][1] *= invScale.y;
219 mtx.mMtx[1][1] *= invScale.y;
220 mtx.mMtx[2][1] *= invScale.y;
222 mtx.mMtx[0][2] *= invScale.z;
223 mtx.mMtx[1][2] *= invScale.z;
224 mtx.mMtx[2][2] *= invScale.z;
230void CollisionParts::updateBoundingSphereRange() {
232 JMath::gekko_ps_copy12(&matrix, _0);
233 f32 scale = makeEqualScale(
reinterpret_cast<MtxPtr
>(&matrix));
234 updateBoundingSphereRangePrivate(scale);
237void CollisionParts::updateBoundingSphereRange(TVec3f a1) {
238 f32 range = (a1.x + a1.y + a1.z) / 3.0f;
239 updateBoundingSphereRangePrivate(range);
242void CollisionParts::updateBoundingSphereRangePrivate(
float scale) {
244 _D8 = scale * mServer->mMaxVertexDistance;
247const char *CollisionParts::getHostName()
const {
248 if (mHitSensor ==
nullptr) {
254 if (actor ==
nullptr) {
261s32 CollisionParts::getPlacementZoneID()
const {
262 return mZone->mZoneID;
267void CollisionParts::projectToPlane(TVec3f *pProjected,
const TVec3f &rPos,
const TVec3f &rOrigin,
const TVec3f &rNormal) {
268 TVec3f projected = rPos;
270 TVec3f relative = rPos;
271 relative.sub(rOrigin);
273 f32 distance = relative.dot(rNormal);
275 TVec3f negNormal = TVec3f(-rNormal);
276 negNormal.scale(distance);
277 projected.add(negNormal);
278 pProjected->set(projected);
282void CollisionParts::calcForceMovePower(TVec3f *a1,
const TVec3f &a2)
const {
283 TVec3f tStack88 = a2;
285 PSMTXInverse((MtxPtr)&mPrevBaseMatrix,
reinterpret_cast<MtxPtr
>(&auStack76));
287 auStack76.mult(tStack88, tStack88);
288 mBaseMatrix.mult(tStack88, tStack88);
The basis of a drawable actor that can contain states (see: Nerve)
const char * mName
A string to identify the NameObj.