| 1 | #include "MapObj/WorldMapParts.h" |
| 2 | |
| 3 | #include "Library/LiveActor/ActorInitUtil.h" |
| 4 | #include "Library/LiveActor/ActorModelFunction.h" |
| 5 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 6 | #include "Library/LiveActor/LiveActorFunction.h" |
| 7 | #include "Library/Math/MathUtil.h" |
| 8 | |
| 9 | void recursivelyInvalidateOcclusionQuery(al::LiveActor* actor) { |
| 10 | al::invalidateOcclusionQuery(actor); |
| 11 | if (al::isExistSubActorKeeper(actor)) |
| 12 | for (s32 i = 0; i < al::getSubActorNum(actor); i++) |
| 13 | recursivelyInvalidateOcclusionQuery(actor: al::getSubActor(actor, index: i)); |
| 14 | } |
| 15 | |
| 16 | WorldMapParts::WorldMapParts(const char* name) : al::LiveActor(name) {} |
| 17 | |
| 18 | void WorldMapParts::setWorldMtx(const sead::Matrix34f& srcMtx) { |
| 19 | sead::Matrix34f copyMtx; |
| 20 | sead::Matrix34f inverse; |
| 21 | |
| 22 | inverse.setInverse(*mWorldMtx); |
| 23 | copyMtx.setMul(a: inverse, b: srcMtx); |
| 24 | setLocalMtx(copyMtx); |
| 25 | } |
| 26 | |
| 27 | void WorldMapParts::updatePose() { |
| 28 | sead::Matrix34f prevWorldMtx = *mWorldMtx; |
| 29 | al::normalize(mtx: &prevWorldMtx); |
| 30 | |
| 31 | prevWorldMtx.setMul(a: prevWorldMtx, b: mLocalMtx); |
| 32 | |
| 33 | al::updatePoseMtx(actor: this, mtx: &prevWorldMtx); |
| 34 | } |
| 35 | |
| 36 | void WorldMapParts::control() { |
| 37 | updatePose(); |
| 38 | } |
| 39 | |
| 40 | void WorldMapParts::setLocalMtx(const sead::Matrix34f& srcMtx) { |
| 41 | mLocalMtx = srcMtx; |
| 42 | } |
| 43 | |
| 44 | void WorldMapParts::initParts(WorldMapParts* mapParts, const char* arcName, |
| 45 | const al::ActorInitInfo& initInfo, const sead::Matrix34f* worldMtx, |
| 46 | const sead::Matrix34f& localMtx, const char* suffix) { |
| 47 | al::initChildActorWithArchiveNameNoPlacementInfo(actor: mapParts, initInfo, archiveName: arcName, suffix); |
| 48 | mapParts->mWorldMtx = worldMtx; |
| 49 | mapParts->setWorldMtx(localMtx); |
| 50 | mapParts->updatePose(); |
| 51 | |
| 52 | if (al::isExistModel(actor: mapParts)) |
| 53 | recursivelyInvalidateOcclusionQuery(actor: mapParts); |
| 54 | |
| 55 | mapParts->makeActorDead(); |
| 56 | } |
| 57 | |
| 58 | WorldMapParts* WorldMapParts::create(const char* name, const char* arcName, |
| 59 | const al::ActorInitInfo& initInfo, |
| 60 | const sead::Matrix34f* worldMtx, |
| 61 | const sead::Matrix34f& localMtx, const char* suffix) { |
| 62 | WorldMapParts* newParts = new WorldMapParts(name); |
| 63 | |
| 64 | initParts(mapParts: newParts, arcName, initInfo, worldMtx, localMtx, suffix); |
| 65 | |
| 66 | return newParts; |
| 67 | } |
| 68 | |