| 1 | #include "Player/CapTargetInfo.h" |
| 2 | |
| 3 | #include "Library/Base/StringUtil.h" |
| 4 | #include "Library/LiveActor/ActorModelFunction.h" |
| 5 | #include "Library/LiveActor/ActorPoseUtil.h" |
| 6 | #include "Library/LiveActor/LiveActor.h" |
| 7 | #include "Library/Math/MathUtil.h" |
| 8 | #include "Library/Matrix/MatrixUtil.h" |
| 9 | |
| 10 | CapTargetInfo::CapTargetInfo() {} |
| 11 | |
| 12 | void CapTargetInfo::init(const al::LiveActor* actor, const char* name) { |
| 13 | mActor = actor; |
| 14 | mIsExistModel = al::isExistModel(actor); |
| 15 | mHackName = nullptr; |
| 16 | mPlayerCollision = nullptr; |
| 17 | mPoseMatrix = nullptr; |
| 18 | mJointMtx = nullptr; |
| 19 | mLocalTrans = {0.0f, 0.0f, 0.0f}; |
| 20 | mLocalRotate = {0.0f, 0.0f, 0.0f}; |
| 21 | mLockOnScale = 1.0f; |
| 22 | mIsUseLockOnFollowMtxScale = false; |
| 23 | mLockOnAnimName = "Capture" ; |
| 24 | mIsEscapeLocalOffset = false; |
| 25 | mEscapeLocalOffset = {0.0f, 0.0f, 0.0f}; |
| 26 | mName = name; |
| 27 | _72 = false; |
| 28 | mIsUseDepthShadow = false; |
| 29 | _74 = false; |
| 30 | mIsLockOn = true; |
| 31 | mIsLockOnStart = false; |
| 32 | mIsSetHackNameToCamera = false; |
| 33 | _78 = false; |
| 34 | _79 = false; |
| 35 | mIsInvalidHackThrow = false; |
| 36 | mIsInvalidCapEye = false; |
| 37 | _7c = false; |
| 38 | _7d = false; |
| 39 | _7e = false; |
| 40 | } |
| 41 | |
| 42 | void CapTargetInfo::setFollowLockOnMtx(const char* jointName, const sead::Vector3f& localTrans, |
| 43 | const sead::Vector3f& localRotate) { |
| 44 | if (jointName) |
| 45 | mJointMtx = al::getJointMtxPtr(actor: mActor, jointName); |
| 46 | else |
| 47 | mJointMtx = mActor->getBaseMtx(); |
| 48 | |
| 49 | mLocalTrans = localTrans; |
| 50 | mLocalRotate = localRotate; |
| 51 | } |
| 52 | |
| 53 | void CapTargetInfo::setLockOnStartAnimName(const char* animName) { |
| 54 | mLockOnStartAnimName = animName; |
| 55 | mIsLockOnStart = !al::isEqualString(str1: animName, str2: "Capture" ); |
| 56 | mIsLockOn = |
| 57 | al::isEqualString(str1: animName, str2: "Capture" ) && al::isEqualString(str1: mLockOnAnimName, str2: "Capture" ); |
| 58 | } |
| 59 | |
| 60 | void CapTargetInfo::setLockOnAnimName(const char* animName) { |
| 61 | mLockOnAnimName = animName; |
| 62 | mIsLockOn = al::isEqualString(str1: mLockOnAnimName, str2: "Capture" ) && |
| 63 | al::isEqualString(str1: mLockOnStartAnimName, str2: "Capture" ); |
| 64 | } |
| 65 | |
| 66 | void CapTargetInfo::setHackName(const char* hackName) { |
| 67 | mHackName = hackName; |
| 68 | } |
| 69 | |
| 70 | void CapTargetInfo::makeLockOnMtx(sead::Matrix34f* outMtx) const { |
| 71 | if (mPoseMatrix) { |
| 72 | *outMtx = *mPoseMatrix; |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | if (!mJointMtx) { |
| 77 | al::makeMtxRT(mtx: outMtx, actor: mActor); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | sead::Matrix34f rotationMatrix; |
| 82 | sead::Vector3f rotate(sead::Mathf::deg2rad(deg: mLocalRotate.x), |
| 83 | sead::Mathf::deg2rad(deg: mLocalRotate.y), |
| 84 | sead::Mathf::deg2rad(deg: mLocalRotate.z)); |
| 85 | rotationMatrix.makeR(r: rotate); |
| 86 | |
| 87 | sead::Matrix34f translationMatrix; |
| 88 | translationMatrix.makeRT(r: {0.0f, 0.0f, 0.0f}, t: mLocalTrans * al::getScaleY(actor: mActor)); |
| 89 | |
| 90 | sead::Matrix34f poseMatrix = rotationMatrix * translationMatrix; |
| 91 | |
| 92 | if (mIsUseFollowScaleLocalOffset) { |
| 93 | sead::Matrix34f baseMtx = sead::Matrix34f::ident; |
| 94 | baseMtx = *mJointMtx * rotationMatrix; |
| 95 | |
| 96 | sead::Vector3f mtxScale = {0.0f, 0.0f, 0.0f}; |
| 97 | al::calcMtxScale(outMtx: &mtxScale, mtx: baseMtx); |
| 98 | poseMatrix.m[0][3] *= mtxScale.x; |
| 99 | poseMatrix.m[1][3] *= mtxScale.y; |
| 100 | poseMatrix.m[2][3] *= mtxScale.z; |
| 101 | } |
| 102 | |
| 103 | sead::Matrix34f baseMtx = *mJointMtx; |
| 104 | al::normalize(mtx: &baseMtx); |
| 105 | *outMtx = baseMtx * poseMatrix; |
| 106 | } |
| 107 | |
| 108 | void CapTargetInfo::calcLockOnFollowTargetScale(sead::Vector3f* targetScale) const { |
| 109 | if (!mIsUseLockOnFollowMtxScale) { |
| 110 | *targetScale = {mLockOnScale, mLockOnScale, mLockOnScale}; |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | if (mPoseMatrix) { |
| 115 | al::calcMtxScale(outMtx: targetScale, mtx: *mPoseMatrix); |
| 116 | *targetScale *= mLockOnScale; |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | sead::Matrix34f baseMtx = sead::Matrix34f::ident; |
| 121 | if (mJointMtx) |
| 122 | baseMtx = *mJointMtx; |
| 123 | else |
| 124 | al::makeMtxRT(mtx: &baseMtx, actor: mActor); |
| 125 | |
| 126 | sead::Matrix34f rotationMatrix; |
| 127 | sead::Vector3f rotate(sead::Mathf::deg2rad(deg: mLocalRotate.x), |
| 128 | sead::Mathf::deg2rad(deg: mLocalRotate.y), |
| 129 | sead::Mathf::deg2rad(deg: mLocalRotate.z)); |
| 130 | rotationMatrix.makeR(r: rotate); |
| 131 | |
| 132 | al::calcMtxScale(outMtx: targetScale, mtx: baseMtx * rotationMatrix); |
| 133 | *targetScale *= mLockOnScale; |
| 134 | } |
| 135 | |