| 1 | #include "Item/CoinStateAppearRotate.h" |
| 2 | |
| 3 | #include <math/seadQuat.h> |
| 4 | |
| 5 | #include "Library/Collision/PartsConnector.h" |
| 6 | #include "Library/LiveActor/ActorActionFunction.h" |
| 7 | #include "Library/LiveActor/ActorModelFunction.h" |
| 8 | #include "Library/LiveActor/ActorMovementFunction.h" |
| 9 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 10 | #include "Library/Math/MathUtil.h" |
| 11 | #include "Library/Nerve/NerveSetupUtil.h" |
| 12 | #include "Library/Nerve/NerveUtil.h" |
| 13 | |
| 14 | namespace { |
| 15 | NERVE_IMPL(CoinStateAppearRotate, Rotate); |
| 16 | |
| 17 | NERVES_MAKE_STRUCT(CoinStateAppearRotate, Rotate); |
| 18 | } // namespace |
| 19 | |
| 20 | CoinStateAppearRotate::CoinStateAppearRotate(al::LiveActor* actor, al::MtxConnector* mtxConnector, |
| 21 | const sead::Vector3f& displayOffset, |
| 22 | const char* rotateHitReaction) |
| 23 | : al::ActorStateBase("回転出現状態" , actor), mMtxConnector(mtxConnector), |
| 24 | mDisplayOffset(displayOffset), mRotateHitReaction(rotateHitReaction) { |
| 25 | initNerve(nerve: &NrvCoinStateAppearRotate.Rotate, stateCount: 0); |
| 26 | } |
| 27 | |
| 28 | void CoinStateAppearRotate::appear() { |
| 29 | al::NerveStateBase::appear(); |
| 30 | al::setNerve(user: this, nerve: &NrvCoinStateAppearRotate.Rotate); |
| 31 | } |
| 32 | |
| 33 | void CoinStateAppearRotate::exeRotate() { |
| 34 | al::LiveActor* actor = mActor; |
| 35 | if (al::isFirstStep(user: this)) { |
| 36 | al::startHitReaction(actor, name: mRotateHitReaction); |
| 37 | mVelocity = sead::Vector3f(0.0f, 22.0f, 0.0f); |
| 38 | mOffset = sead::Vector3f::zero; |
| 39 | mInitialTransY = al::getTransPtr(actor)->y; |
| 40 | al::showModelIfHide(actor); |
| 41 | } |
| 42 | |
| 43 | sead::Vector3f frontDir = sead::Vector3f::zero; |
| 44 | al::calcFrontDir(front: &frontDir, actor); |
| 45 | sead::Vector3f upDir = sead::Vector3f::zero; |
| 46 | al::calcUpDir(up: &upDir, actor); |
| 47 | al::rotateVectorDegree(&frontDir, frontDir, upDir, 15.0f); |
| 48 | |
| 49 | if (mMtxConnector == nullptr) { |
| 50 | al::getTransPtr(actor)->y = mInitialTransY + mOffset.y; |
| 51 | |
| 52 | sead::Quatf quad = sead::Quatf::unit; |
| 53 | al::makeQuatFrontUp(outQuat: &quad, front: frontDir, up: upDir); |
| 54 | al::setQuat(actor, quat: quad); |
| 55 | |
| 56 | mVelocity.y -= 1.5f; |
| 57 | mOffset += mVelocity; |
| 58 | } else { |
| 59 | al::connectPoseQT(actor, mtxConnector: mMtxConnector); |
| 60 | *al::getTransPtr(actor) += mDisplayOffset; |
| 61 | *al::getTransPtr(actor) += mOffset; |
| 62 | |
| 63 | sead::Quatf quad = sead::Quatf::unit; |
| 64 | al::makeQuatFrontUp(outQuat: &quad, front: frontDir, up: upDir); |
| 65 | al::setQuat(actor, quat: quad); |
| 66 | |
| 67 | mVelocity.y -= 1.5f; |
| 68 | mOffset += mVelocity; |
| 69 | } |
| 70 | |
| 71 | if (mOffset.y < 0.0f) { |
| 72 | al::getTransPtr(actor)->y = mInitialTransY; |
| 73 | al::setVelocityZero(actor); |
| 74 | kill(); |
| 75 | } |
| 76 | } |
| 77 | |