SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
IKJoint.cpp
1#include "Game/Util/IKJoint.hpp"
2#include "Game/Util.hpp"
3
4IKJoint::IKJoint() : mRootBoneLength(100.0f), mMiddleBoneLength(100.0f), _0(), _30(), _60() {
5 _0.identity();
6 _60.identity();
7 _30.identity();
8}
9
10void IKJoint::setRootBoneLength(f32 boneLength) {
11 mRootBoneLength = boneLength;
12}
13
14void IKJoint::setMiddleBoneLength(f32 boneLength) {
15 mMiddleBoneLength = boneLength;
16}
17
18void IKJoint::setFirstPose(const TVec3f &a1, const TVec3f &a2) {
19 MR::makeMtxSideUp(&_0, a1, a2);
20}
21
22s32 IKJoint::checkReachIKTarget(f32 a1, f32 a2, f32 a3) {
23 int res = 0;
24
25 if (a1 > (a2 + a3)) {
26 res = 2;
27 }
28 else {
29 if (a1 < __fabs(a2 - a3)) {
30 res = 1;
31 }
32 else {
33 return res;
34 }
35
36 }
37
38 return res;
39}
40
41#ifdef NON_MATCHING
42// regalloc
43f32 IKJoint::calcIKRootAngleCosign(f32 a1, f32 a2, f32 a3) {
44 s32 targ = checkReachIKTarget(a1, a2, a3);
45
46 if (targ == 1) {
47 return 1.0f;
48 }
49
50 if (targ == -1) {
51 if (a2 < a3) {
52 return -1.0f;
53 }
54
55 return 1.0f;
56 }
57
58 f32 a3_sqr = a3 * a3;
59 f32 a2_sqr = a2 * a2;
60 f32 a1_sqr = a1 * a2;
61
62 f32 more_val = (a3_sqr - a1_sqr) - a2_sqr;
63 f32 val = (more_val / ((-2.0f * a2) * a1));
64
65 if (val < -1.0f) {
66 return -1.0f;
67 }
68
69 if (val > 1.0f) {
70 return 1.0f;
71 }
72
73 return val;
74}
75#endif