Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
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
8
namespace
Kinoko::Kart
{
9
11
KartBurnout::KartBurnout() =
default
;
12
14
KartBurnout::~KartBurnout() =
default
;
15
17
void
KartBurnout::start() {
18
activate();
19
m_timer = 0;
20
m_phase = 0;
21
m_amplitude = 1.0f;
22
}
23
25
void
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
39
f32 KartBurnout::pitch()
const
{
40
return
m_pitch;
41
}
42
44
void
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
66
bool
KartBurnout::calcEnd(u32 duration) {
67
return
++m_timer >= duration;
68
}
69
71
void
KartBurnout::activate() {
72
status().setBit(
eStatus::Burnout
);
73
}
74
76
void
KartBurnout::deactivate() {
77
status().resetBit(
eStatus::Burnout
);
78
}
79
81
bool
KartBurnout::isActive()
const
{
82
return
status().onBit(
eStatus::Burnout
);
83
}
84
85
}
// namespace Kinoko::Kart
Kinoko::Kart
Pertains to kart-related functionality.
Definition
BoxColManager.hh:14
Kinoko::Kart::eStatus::Burnout
@ Burnout
Set during a burnout on race start.
Definition
Status.hh:60
game
kart
KartBurnout.cc
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0