| 1 | #include "Library/KeyPose/KeyPoseKeeperUtil.h" |
| 2 | |
| 3 | #include "Library/KeyPose/KeyPoseKeeper.h" |
| 4 | #include "Library/LiveActor/ActorInitUtil.h" |
| 5 | #include "Library/Math/MathUtil.h" |
| 6 | #include "Library/Placement/PlacementFunction.h" |
| 7 | #include "Project/Joint/KeyPose.h" |
| 8 | |
| 9 | namespace al { |
| 10 | KeyPoseKeeper* createKeyPoseKeeper(const ActorInitInfo& info) { |
| 11 | return createKeyPoseKeeper(info: getPlacementInfo(initInfo: info)); |
| 12 | } |
| 13 | |
| 14 | KeyPoseKeeper* createKeyPoseKeeper(const PlacementInfo& info) { |
| 15 | KeyPoseKeeper* keyPoseKeeper = new KeyPoseKeeper(); |
| 16 | keyPoseKeeper->init(info); |
| 17 | |
| 18 | return keyPoseKeeper; |
| 19 | } |
| 20 | |
| 21 | void resetKeyPose(KeyPoseKeeper* keyPoseKeeper) { |
| 22 | keyPoseKeeper->reset(); |
| 23 | } |
| 24 | |
| 25 | void nextKeyPose(KeyPoseKeeper* keyPoseKeeper) { |
| 26 | keyPoseKeeper->next(); |
| 27 | } |
| 28 | |
| 29 | void restartKeyPose(KeyPoseKeeper* keyPoseKeeper, sead::Vector3f* pos, sead::Quatf* orientation) { |
| 30 | resetKeyPose(keyPoseKeeper); |
| 31 | |
| 32 | const KeyPose& keyPose = keyPoseKeeper->getKeyPose(idx: 0); |
| 33 | |
| 34 | if (pos != nullptr) |
| 35 | pos->set(keyPose.getTrans()); |
| 36 | |
| 37 | if (orientation != nullptr) |
| 38 | orientation->set(keyPose.getQuat()); |
| 39 | } |
| 40 | |
| 41 | void reverseKeyPose(KeyPoseKeeper* keyPoseKeeper) { |
| 42 | keyPoseKeeper->reverse(); |
| 43 | } |
| 44 | |
| 45 | const sead::Vector3f& getCurrentKeyTrans(const KeyPoseKeeper* keyPoseKeeper) { |
| 46 | return keyPoseKeeper->getCurrentKeyPose().getTrans(); |
| 47 | } |
| 48 | |
| 49 | const sead::Vector3f& getNextKeyTrans(const KeyPoseKeeper* keyPoseKeeper) { |
| 50 | return keyPoseKeeper->getNextKeyPose().getTrans(); |
| 51 | } |
| 52 | |
| 53 | const sead::Quatf& getCurrentKeyQuat(const KeyPoseKeeper* keyPoseKeeper) { |
| 54 | return keyPoseKeeper->getCurrentKeyPose().getQuat(); |
| 55 | } |
| 56 | |
| 57 | const sead::Quatf& getNextKeyQuat(const KeyPoseKeeper* keyPoseKeeper) { |
| 58 | return keyPoseKeeper->getNextKeyPose().getQuat(); |
| 59 | } |
| 60 | |
| 61 | const PlacementInfo& getCurrentKeyPlacementInfo(const KeyPoseKeeper* keyPoseKeeper) { |
| 62 | return keyPoseKeeper->getCurrentKeyPose().getPlacementInfo(); |
| 63 | } |
| 64 | |
| 65 | const PlacementInfo& getNextKeyPlacementInfo(const KeyPoseKeeper* keyPoseKeeper) { |
| 66 | return keyPoseKeeper->getNextKeyPose().getPlacementInfo(); |
| 67 | } |
| 68 | |
| 69 | s32 getKeyPoseCount(const KeyPoseKeeper* keyPoseKeeper) { |
| 70 | return keyPoseKeeper->getKeyPoseCount(); |
| 71 | } |
| 72 | |
| 73 | void getKeyPoseTrans(sead::Vector3f* out, const KeyPoseKeeper* keyPoseKeeper, s32 idx) { |
| 74 | out->set(keyPoseKeeper->getKeyPose(idx).getTrans()); |
| 75 | } |
| 76 | |
| 77 | void getKeyPoseQuat(sead::Quatf* out, const KeyPoseKeeper* keyPoseKeeper, s32 idx) { |
| 78 | out->set(keyPoseKeeper->getKeyPose(idx).getQuat()); |
| 79 | } |
| 80 | |
| 81 | void calcLerpKeyTrans(sead::Vector3f* out, const KeyPoseKeeper* keyPoseKeeper, f32 rate) { |
| 82 | const KeyPose& current = keyPoseKeeper->getCurrentKeyPose(); |
| 83 | const KeyPose& next = keyPoseKeeper->getNextKeyPose(); |
| 84 | |
| 85 | s32 interpolateType = 0; |
| 86 | tryGetArg(arg: &interpolateType, placementInfo: current.getPlacementInfo(), key: "InterpolateType" ); |
| 87 | |
| 88 | lerpVec(out, current.getTrans(), next.getTrans(), easeByType(t: rate, easeType: interpolateType)); |
| 89 | } |
| 90 | |
| 91 | void calcSlerpKeyQuat(sead::Quatf* out, const KeyPoseKeeper* keyPoseKeeper, f32 rate) { |
| 92 | const KeyPose& current = keyPoseKeeper->getCurrentKeyPose(); |
| 93 | const KeyPose& next = keyPoseKeeper->getNextKeyPose(); |
| 94 | |
| 95 | s32 interpolateType = 0; |
| 96 | tryGetArg(arg: &interpolateType, placementInfo: current.getPlacementInfo(), key: "InterpolateType" ); |
| 97 | |
| 98 | slerpQuat(out, current.getQuat(), next.getQuat(), easeByType(t: rate, easeType: interpolateType)); |
| 99 | } |
| 100 | |
| 101 | bool isMoveSignKey(const KeyPoseKeeper* keyPoseKeeper) { |
| 102 | bool isPlaySign = false; |
| 103 | tryGetArg(arg: &isPlaySign, placementInfo: getCurrentKeyPlacementInfo(keyPoseKeeper), key: "IsPlaySign" ); |
| 104 | |
| 105 | return isPlaySign; |
| 106 | } |
| 107 | |
| 108 | bool isLastKey(const KeyPoseKeeper* keyPoseKeeper) { |
| 109 | return keyPoseKeeper->isLastKey(); |
| 110 | } |
| 111 | |
| 112 | bool isFirstKey(const KeyPoseKeeper* keyPoseKeeper) { |
| 113 | return keyPoseKeeper->isFirstKey(); |
| 114 | } |
| 115 | |
| 116 | bool isGoingToEnd(const KeyPoseKeeper* keyPoseKeeper) { |
| 117 | return keyPoseKeeper->isGoingToEnd(); |
| 118 | } |
| 119 | |
| 120 | bool isStop(const KeyPoseKeeper* keyPoseKeeper) { |
| 121 | return keyPoseKeeper->isStop(); |
| 122 | } |
| 123 | |
| 124 | bool isRestart(const KeyPoseKeeper* keyPoseKeeper) { |
| 125 | return keyPoseKeeper->isRestart(); |
| 126 | } |
| 127 | |
| 128 | f32 calcDistanceNextKeyTrans(const KeyPoseKeeper* keyPoseKeeper) { |
| 129 | return (getCurrentKeyTrans(keyPoseKeeper) - getNextKeyTrans(keyPoseKeeper)).length(); |
| 130 | } |
| 131 | |
| 132 | s32 calcTimeToNextKeyMove(const KeyPoseKeeper* keyPoseKeeper, f32 speed) { |
| 133 | return sead::Mathi::clampMin(val: (s32)(calcDistanceNextKeyTrans(keyPoseKeeper) / speed), min_: 1); |
| 134 | } |
| 135 | |
| 136 | void calcDirToNextKey(sead::Vector3f* out, const KeyPoseKeeper* keyPoseKeeper) { |
| 137 | const sead::Vector3f& currTrans = getCurrentKeyTrans(keyPoseKeeper); |
| 138 | const sead::Vector3f& nextTrans = getNextKeyTrans(keyPoseKeeper); |
| 139 | |
| 140 | out->x = nextTrans.x - currTrans.x; |
| 141 | out->y = nextTrans.y - currTrans.y; |
| 142 | out->z = nextTrans.z - currTrans.z; |
| 143 | |
| 144 | if (!tryNormalizeOrZero(out)) |
| 145 | out->set(sead::Vector3f::ez); |
| 146 | } |
| 147 | |
| 148 | f32 calcKeyMoveSpeed(const KeyPoseKeeper* keyPoseKeeper) { |
| 149 | f32 speed = -1.0f; |
| 150 | tryGetArg(arg: &speed, placementInfo: getCurrentKeyPlacementInfo(keyPoseKeeper), key: "Speed" ); |
| 151 | |
| 152 | if (speed < 0.0f) |
| 153 | return -1.0f; |
| 154 | |
| 155 | return speed; |
| 156 | } |
| 157 | |
| 158 | f32 calcKeyMoveSpeedByTime(const KeyPoseKeeper* keyPoseKeeper) { |
| 159 | s32 speed = -1; |
| 160 | tryGetArg(arg: &speed, placementInfo: getCurrentKeyPlacementInfo(keyPoseKeeper), key: "SpeedByTime" ); |
| 161 | |
| 162 | if (speed < 0.0f) |
| 163 | return -1.0f; |
| 164 | |
| 165 | return speed; |
| 166 | } |
| 167 | |
| 168 | s32 calcKeyMoveWaitTime(const KeyPoseKeeper* keyPoseKeeper) { |
| 169 | s32 waitTime = -1; |
| 170 | tryGetArg(arg: &waitTime, placementInfo: getCurrentKeyPlacementInfo(keyPoseKeeper), key: "WaitTime" ); |
| 171 | |
| 172 | return sead::Mathi::max(a: waitTime, b: -1); |
| 173 | } |
| 174 | |
| 175 | s32 calcKeyMoveMoveTime(const KeyPoseKeeper* keyPoseKeeper) { |
| 176 | s32 t = (s32)calcKeyMoveSpeedByTime(keyPoseKeeper); |
| 177 | if (t >= 1) |
| 178 | return t; |
| 179 | |
| 180 | f32 v = calcKeyMoveSpeed(keyPoseKeeper); |
| 181 | return v > 0.0f ? calcTimeToNextKeyMove(keyPoseKeeper, speed: v) : 60; |
| 182 | } |
| 183 | |
| 184 | // TODO: Implement al::calcKeyMoveClippingInfo and al::setKeyMoveClippingInfo |
| 185 | // void calcKeyMoveClippingInfo(sead::Vector3f*, f32*, const KeyPoseKeeper*, f32) {} |
| 186 | // void setKeyMoveClippingInfo(LiveActor*, sead::Vector3f*, const KeyPoseKeeper*) {} |
| 187 | } // namespace al |
| 188 | |