A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectKinoko.cc
1#include "ObjectKinoko.hh"
2
3namespace Field {
4
6ObjectKinoko::ObjectKinoko(const System::MapdataGeoObj &params)
7 : ObjectKCL(params), m_objPos(m_pos), m_objRot(m_rot) {
8 m_type = static_cast<KinokoType>(params.setting(0));
9
10 m_restFrame = 0;
11 m_pulseFrame = 1; // (-1*-1) % PULSE_DURATION;
12 m_pulseFalloff = 0.1f;
13}
14
16ObjectKinoko::~ObjectKinoko() = default;
17
19void ObjectKinoko::calc() {
20 constexpr s16 REST_DURATION = 10;
21 constexpr s16 PULSE_DURATION = 40;
22 constexpr f32 PULSE_SCALE = 0.0008f;
23 constexpr f32 PULSE_FREQ = 6.0f * F_PI / 40.0f;
24
25 if (m_restFrame == 0) {
26 ++m_pulseFrame;
27 }
28 if (m_pulseFrame == PULSE_DURATION) {
29 ++m_restFrame;
30 }
31 if (m_restFrame > REST_DURATION) {
32 m_restFrame = 0;
33 }
34 if (m_pulseFrame > PULSE_DURATION) {
35 m_pulseFrame = 0;
36 }
37
38 m_pulseFalloff = PULSE_SCALE * static_cast<f32>(PULSE_DURATION - m_pulseFrame);
39 m_flags |= 8; // |= SCALE_DIRTY
40 m_scale.set(
41 m_pulseFalloff * EGG::Mathf::sin(PULSE_FREQ * static_cast<f32>(m_pulseFrame)) + 1.0f);
42
43 calcOscillation();
44}
45
47ObjectKinokoUd::ObjectKinokoUd(const System::MapdataGeoObj &params) : ObjectKinoko(params) {
48 m_waitFrame = 0;
49 m_oscFrame = params.setting(3);
50 m_waitDuration = params.setting(4);
51 m_amplitude = params.setting(1);
52 m_period = std::max<u16>(params.setting(2), 2);
53 m_angFreq = F_TAU / static_cast<f32>(m_period);
54}
55
57ObjectKinokoUd::~ObjectKinokoUd() = default;
58
60void ObjectKinokoUd::calcOscillation() {
61 m_flags |= 1; // |= POSITION_DIRTY;
62 m_pos.y = m_objPos.y +
63 static_cast<f32>(m_amplitude) *
64 (EGG::Mathf::cos(m_angFreq * static_cast<f32>(m_oscFrame)) + 1.0f) * 0.5f;
65
66 if (m_waitFrame == 0) {
67 ++m_oscFrame;
68 }
69 if (m_oscFrame == (m_period / 2)) {
70 ++m_waitFrame;
71 }
72 if (m_waitFrame > m_waitDuration) {
73 m_waitFrame = 0;
74 }
75 if (m_oscFrame > m_period) {
76 m_oscFrame = 0;
77 }
78}
79
81ObjectKinokoBend::ObjectKinokoBend(const System::MapdataGeoObj &params) : ObjectKinoko(params) {
82 m_currentFrame = params.setting(3);
83 m_amplitude = static_cast<f32>(params.setting(1)) * DEG2RAD;
84 m_period = std::max<u16>(params.setting(2), 2);
85 m_angFreq = F_TAU / static_cast<f32>(m_period);
86}
87
89ObjectKinokoBend::~ObjectKinokoBend() = default;
90
92void ObjectKinokoBend::calcOscillation() {
93 const f32 s = EGG::Mathf::sin(m_angFreq * static_cast<f32>(m_currentFrame));
94 EGG::Vector3f rot = m_objRot + (EGG::Vector3f::ez * s) * m_amplitude;
95
96 calcTransform();
97
98 m_flags |= 2; // |= ROTATION_DIRTY;
99 m_rot = m_transform.multVector33(rot);
100
101 if (++m_currentFrame >= m_period) {
102 m_currentFrame = 0;
103 }
104}
105
106ObjectKinokoNm::ObjectKinokoNm(const System::MapdataGeoObj &params) : ObjectKCL(params) {
107 m_type = static_cast<KinokoType>(params.setting(0));
108}
109
111ObjectKinokoNm::~ObjectKinokoNm() = default;
112
113} // namespace Field
static f32 sin(f32 x)
Definition Math.hh:33
static f32 cos(f32 x)
Definition Math.hh:39
Pertains to collision.
A 3D float vector.
Definition Vector.hh:83