A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartModel.cc
1#include "KartModel.hh"
2
3#include "game/kart/KartBody.hh"
4#include "game/kart/KartMove.hh"
5#include "game/kart/KartParam.hh"
6#include "game/kart/KartState.hh"
7
8#include <egg/math/Math.hh>
9
10namespace Render {
11
12KartModel::KartModel() {
13 m_somethingLeft = false;
14 m_somethingRight = false;
15 _58 = 0.0f;
16 _54 = 1.0f;
17 _5c = 0.0f;
18 _64 = 0.0f;
19 _2e8 = 0.0f;
20}
21
22KartModel::~KartModel() = default;
23
25void KartModel::vf_1c() {
26 if (state()->isBurnout()) {
27 _54 = 1.0f;
28
29 f32 pitch = move()->burnout().pitch();
30 f32 fVar2 = pitch + 75.0f * (pitch - _2e8);
31 f32 fVar4 = std::min(0.2f, 0.04f * EGG::Mathf::abs(fVar2));
32 fVar4 = fVar2 > 0.0f ? fVar4 : -fVar4;
33
34 _2e8 = pitch;
35 _58 += fVar4;
36 } else {
37 _2e8 = 0.0f;
38 _58 *= 0.9f;
39 }
40
41 f32 xStick = inputs()->currentState().stick.x;
42 bool isInCannon = state()->isInCannon();
43 f32 fVar2 = isInCannon ? 0.02f : 0.1f;
44
45 f32 local_f31 = _58;
46 if (xStick <= 0.2f) {
47 if (xStick < -0.2f) {
48 _58 -= fVar2;
49 }
50 } else {
51 _58 += fVar2;
52 }
53
54 xStick = EGG::Mathf::abs(xStick);
55
56 if (isInCannon) {
57 xStick *= 0.8f;
58 fVar2 = 0.05f;
59 }
60
61 _54 += fVar2 * (xStick - _54);
62
63 if (local_f31 < -_54 || _54 < local_f31) {
64 if (-_54 <= _58) {
65 if (_54 < _58) {
66 _58 -= 0.1f;
67 }
68 } else {
69 _58 += 0.1f;
70 }
71 } else if (-_54 <= _58) {
72 _58 = std::min(_54, _58);
73 } else {
74 _58 = -_54;
75 }
76
77 f32 dVar13 = _58;
78
79 if (isBike()) {
80 if (state()->isDrifting()) {
81 dVar13 = m_isInsideDrift ? 5.0f : 20.0f;
82 } else {
83 dVar13 = 15.0f;
84 }
85 } else {
86 dVar13 = 15.0f;
87 }
88
89 f32 dVar12 = 0.0f;
90 _64 = dVar13 * 0.1f;
91
92 if (isBike()) {
93 dVar12 = -_58 * dVar13;
94
95 if (m_somethingLeft) {
96 dVar12 += m_isInsideDrift ? 5.0f : 10.0f;
97 } else if (m_somethingRight) {
98 dVar12 -= m_isInsideDrift ? 5.0f : 10.0f;
99 }
100 } else {
101 if (!m_somethingLeft && m_somethingRight) {
102 dVar12 -= 5.0f;
103 } else {
104 dVar12 += 5.0f;
105 }
106 }
107
108 if (dVar12 <= _5c) {
109 _5c -= _64;
110 _5c = std::max(_5c, dVar12);
111 } else {
112 _5c += _64;
113 _5c = std::min(_5c, dVar12);
114 }
115
116 body()->setAngle(_5c);
117}
118
120void KartModel::init() {
121 FUN_807C7828(param()->playerIdx(), isBike());
122
123 _2e8 = 0.0f;
124}
125
127void KartModel::calc() {
128 FUN_807CB530();
129}
130
134 m_somethingRight = false;
135 m_somethingLeft = false;
136
137 bool turnInput = state()->isStickLeft() || state()->isStickRight();
138 if (state()->isDrifting() || (state()->isChargingSsmt() && turnInput)) {
139 if (move()->hopStickX() == 1) {
140 m_somethingLeft = true;
141 } else {
142 if (move()->hopStickX() == -1) {
143 m_somethingRight = true;
144 } else if (!state()->isStickLeft()) {
145 m_somethingRight = true;
146 } else {
147 m_somethingLeft = true;
148 }
149 }
150 }
151}
152
156 FUN_807CB198();
157 vf_1c();
158}
159
162void KartModel::FUN_807C7828(u8 /*playerIdx*/, bool /*isBike*/) {
163 m_isInsideDrift =
164 param()->stats().driftType == Kart::KartParam::Stats::DriftType::Inside_Drift_Bike;
165}
166
168KartModelKart::KartModelKart() = default;
169
171KartModelKart::~KartModelKart() = default;
172
174KartModelBike::KartModelBike() = default;
175
177KartModelBike::~KartModelBike() = default;
178
179} // namespace Render
void FUN_807C7828(u8 playerIdx, bool isBike)
Definition KartModel.cc:162
Pertains to rendering the kart model.