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
9namespace al {
10KeyPoseKeeper* createKeyPoseKeeper(const ActorInitInfo& info) {
11 return createKeyPoseKeeper(info: getPlacementInfo(initInfo: info));
12}
13
14KeyPoseKeeper* createKeyPoseKeeper(const PlacementInfo& info) {
15 KeyPoseKeeper* keyPoseKeeper = new KeyPoseKeeper();
16 keyPoseKeeper->init(info);
17
18 return keyPoseKeeper;
19}
20
21void resetKeyPose(KeyPoseKeeper* keyPoseKeeper) {
22 keyPoseKeeper->reset();
23}
24
25void nextKeyPose(KeyPoseKeeper* keyPoseKeeper) {
26 keyPoseKeeper->next();
27}
28
29void 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
41void reverseKeyPose(KeyPoseKeeper* keyPoseKeeper) {
42 keyPoseKeeper->reverse();
43}
44
45const sead::Vector3f& getCurrentKeyTrans(const KeyPoseKeeper* keyPoseKeeper) {
46 return keyPoseKeeper->getCurrentKeyPose().getTrans();
47}
48
49const sead::Vector3f& getNextKeyTrans(const KeyPoseKeeper* keyPoseKeeper) {
50 return keyPoseKeeper->getNextKeyPose().getTrans();
51}
52
53const sead::Quatf& getCurrentKeyQuat(const KeyPoseKeeper* keyPoseKeeper) {
54 return keyPoseKeeper->getCurrentKeyPose().getQuat();
55}
56
57const sead::Quatf& getNextKeyQuat(const KeyPoseKeeper* keyPoseKeeper) {
58 return keyPoseKeeper->getNextKeyPose().getQuat();
59}
60
61const PlacementInfo& getCurrentKeyPlacementInfo(const KeyPoseKeeper* keyPoseKeeper) {
62 return keyPoseKeeper->getCurrentKeyPose().getPlacementInfo();
63}
64
65const PlacementInfo& getNextKeyPlacementInfo(const KeyPoseKeeper* keyPoseKeeper) {
66 return keyPoseKeeper->getNextKeyPose().getPlacementInfo();
67}
68
69s32 getKeyPoseCount(const KeyPoseKeeper* keyPoseKeeper) {
70 return keyPoseKeeper->getKeyPoseCount();
71}
72
73void getKeyPoseTrans(sead::Vector3f* out, const KeyPoseKeeper* keyPoseKeeper, s32 idx) {
74 out->set(keyPoseKeeper->getKeyPose(idx).getTrans());
75}
76
77void getKeyPoseQuat(sead::Quatf* out, const KeyPoseKeeper* keyPoseKeeper, s32 idx) {
78 out->set(keyPoseKeeper->getKeyPose(idx).getQuat());
79}
80
81void 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
91void 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
101bool isMoveSignKey(const KeyPoseKeeper* keyPoseKeeper) {
102 bool isPlaySign = false;
103 tryGetArg(arg: &isPlaySign, placementInfo: getCurrentKeyPlacementInfo(keyPoseKeeper), key: "IsPlaySign");
104
105 return isPlaySign;
106}
107
108bool isLastKey(const KeyPoseKeeper* keyPoseKeeper) {
109 return keyPoseKeeper->isLastKey();
110}
111
112bool isFirstKey(const KeyPoseKeeper* keyPoseKeeper) {
113 return keyPoseKeeper->isFirstKey();
114}
115
116bool isGoingToEnd(const KeyPoseKeeper* keyPoseKeeper) {
117 return keyPoseKeeper->isGoingToEnd();
118}
119
120bool isStop(const KeyPoseKeeper* keyPoseKeeper) {
121 return keyPoseKeeper->isStop();
122}
123
124bool isRestart(const KeyPoseKeeper* keyPoseKeeper) {
125 return keyPoseKeeper->isRestart();
126}
127
128f32 calcDistanceNextKeyTrans(const KeyPoseKeeper* keyPoseKeeper) {
129 return (getCurrentKeyTrans(keyPoseKeeper) - getNextKeyTrans(keyPoseKeeper)).length();
130}
131
132s32 calcTimeToNextKeyMove(const KeyPoseKeeper* keyPoseKeeper, f32 speed) {
133 return sead::Mathi::clampMin(val: (s32)(calcDistanceNextKeyTrans(keyPoseKeeper) / speed), min_: 1);
134}
135
136void 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
148f32 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
158f32 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
168s32 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
175s32 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