A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartBurnout.cc
1#include "KartBurnout.hh"
2
3#include "game/kart/KartPhysics.hh"
4#include "game/kart/KartState.hh"
5
6#include <egg/math/Math.hh>
7
8namespace Kart {
9
11KartBurnout::KartBurnout() = default;
12
14KartBurnout::~KartBurnout() = default;
15
17void KartBurnout::start() {
18 activate();
19 m_timer = 0;
20 m_phase = 0;
21 m_amplitude = 1.0f;
22}
23
25void KartBurnout::calc() {
26 constexpr u32 BURNOUT_DURATION = 120;
27
28 if (!isActive()) {
29 return;
30 }
31
32 calcRotation();
33
34 if (calcEnd(BURNOUT_DURATION)) {
35 deactivate();
36 }
37}
38
39f32 KartBurnout::pitch() const {
40 return m_pitch;
41}
42
44void KartBurnout::calcRotation() {
45 constexpr u16 PHASE_INCREMENT = 800;
46 constexpr f32 PHASE_TO_FIDX = 1.0f / 256.0f;
47 constexpr f32 AMPLITUDE_FACTOR = 40.0f;
48 constexpr f32 DAMPENING_THRESHOLD = 30.0f;
49 constexpr f32 DAMPENING_FACTOR = 0.97f;
50
51 m_phase += PHASE_INCREMENT;
52
53 f32 sin = EGG::Mathf::SinFIdx(static_cast<f32>(m_phase) * PHASE_TO_FIDX);
54
55 // Apply a dampening effect after burning out for 30 frames
56 if (static_cast<f32>(m_timer) > DAMPENING_THRESHOLD) {
57 m_amplitude *= DAMPENING_FACTOR;
58 }
59
60 m_pitch = DEG2RAD * (AMPLITUDE_FACTOR * sin) * m_amplitude;
61
62 physics()->composeStuntRot(EGG::Quatf::FromRPY(0.0f, m_pitch, 0.0f));
63}
64
66bool KartBurnout::calcEnd(u32 duration) {
67 return ++m_timer >= duration;
68}
69
71void KartBurnout::activate() {
72 state()->setBurnout(true);
73}
74
76void KartBurnout::deactivate() {
77 state()->setBurnout(false);
78}
79
81bool KartBurnout::isActive() const {
82 return state()->isBurnout();
83}
84
85} // namespace Kart
Pertains to kart-related functionality.