SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
SpinDriverShootPath.cpp
1#include "Game/MapObj/SpinDriverShootPath.hpp"
2#include "JSystem/JMath/JMath.hpp"
3
4SpinDriverShootPath::SpinDriverShootPath() {
5 mRailRider = nullptr;
6 mPath = nullptr;
7 mStartPosition.x = 0.0f;
8 mStartPosition.y = 0.0f;
9 mStartPosition.z = 0.0f;
10 mUsesParabolic = false;
11}
12
13void SpinDriverShootPath::init(const JMapInfoIter &rIter) {
14 mRailRider = new RailRider(rIter);
15 mUsesParabolic = false;
16}
17
18void SpinDriverShootPath::initUsingParabolic(const JMapInfoIter &rIter, const TVec3f &rStartingPosition) {
19 mRailRider = new RailRider(rIter);
20 mUsesParabolic = mRailRider->getPointNum() <= 2;
21
22 if (mUsesParabolic) {
23 mPath = new ParabolicPath();
24 }
25
26 setStartPosition(rStartingPosition);
27}
28
29void SpinDriverShootPath::setStartPosition(const TVec3f &rStartPos) {
30 if (mUsesParabolic) {
31 TVec3f start(mRailRider->mStartPos);
32 TVec3f end(mRailRider->mEndPos);
33 mPath->initFromMaxHeight(rStartPos, end, start);
34 }
35
36 TVec3f position;
37 TVec3f pos_diff;
38
39 calcPosition(&position, 0.0f);
40 TVec3f startPos(rStartPos);
41 JMathInlineVEC::PSVECSubtract(startPos.toCVec(), position.toCVec(), startPos.toVec());
42 mStartPosition.setInlinePS(startPos);
43}
44
45void SpinDriverShootPath::calcPosition(TVec3f *pOutPosition, f32 a2) const {
46 if (mUsesParabolic) {
47 mPath->calcPosition(pOutPosition, a2);
48 }
49 else {
50 f32 length = mRailRider->getTotalLength();
51 mRailRider->calcPosAtCoord(pOutPosition, a2 * length);
52 f32 norm = MR::normalize(a2, 0.0f, 0.5f);
53 f32 easeOut = MR::getEaseOutValue(norm, 1.0f, 0.0f, 1.0f);
54 TVec3f pos(mStartPosition);
55 pos.x *= easeOut;
56 pos.y *= easeOut;
57 pos.z *= easeOut;
58 pOutPosition->add(pos);
59 }
60}
61
62void SpinDriverShootPath::calcDirection(TVec3f *pOutDirection, f32 a2, f32 a3) const {
63 f32 v6;
64 f32 v7;
65
66 if (a2 < a3) {
67 v6 = a3;
68 v7 = 0.0f;
69 }
70 else {
71 v6 = 1.0f;
72 v7 = (1.0f - a3);
73
74 if (a2 > v7) {
75 v7 = v7;
76 }
77 else {
78 v7 = a2;
79 v6 = (a2 + a3);
80 }
81 }
82
83 TVec3f stack_20;
84 calcPosition(&stack_20, v7);
85 TVec3f stack_14;
86 calcPosition(&stack_14, v6);
87 TVec3f stack_8(stack_14);
88 JMathInlineVEC::PSVECSubtract(stack_8.toCVec(), stack_14.toCVec(), stack_8.toVec());
89 pOutDirection->set(stack_8);
90 MR::normalize(pOutDirection);
91}
92
93// SpinDriverShootPath::calcInitPose
94
95f32 SpinDriverShootPath::getTotalLength() const {
96 if (mUsesParabolic) {
97 return mPath->getTotalLength(0x20);
98 }
99
100 return mRailRider->getTotalLength();
101}