A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectDossunSyuukai.cc
1#include "ObjectDossunSyuukai.hh"
2
3namespace Kinoko::Field {
4
6ObjectDossunSyuukai::ObjectDossunSyuukai(const System::MapdataGeoObj &params)
7 : ObjectDossun(params) {}
8
10ObjectDossunSyuukai::~ObjectDossunSyuukai() = default;
11
13void ObjectDossunSyuukai::init() {
14 ObjectDossun::init();
15
16 m_state = State::Moving;
17 m_initRotY = rot().y;
18 m_rotating = true;
19}
20
22void ObjectDossunSyuukai::calc() {
23 m_touchingGround = false;
24
25 switch (m_state) {
26 case State::Moving:
27 calcMoving();
28 break;
29 case State::RotatingBeforeStomp:
30 case State::RotatingAfterStomp:
31 calcRotating();
32 break;
33 case State::Stomping:
34 ObjectDossun::calcStomp();
35 break;
36 default:
37 break;
38 }
39}
40
42void ObjectDossunSyuukai::calcMoving() {
43 if (m_railInterpolator->calc() == RailInterpolator::Status::SegmentEnd) {
44 m_state = State::RotatingBeforeStomp;
45 }
46
47 setPos(m_railInterpolator->curPos());
48}
49
52 constexpr f32 ANG_VEL = 0.08726646f;
53 constexpr f32 BEFORE_FALL_FRAMES = 10;
54
55 addRot(EGG::Vector3f(0.0f, ANG_VEL, 0.0f));
56
57 if (m_state == State::RotatingBeforeStomp) {
58 f32 targetRot = m_initRotY;
59 if (targetRot < 0.0f) {
60 targetRot += F_TAU;
61 } else if (targetRot >= F_TAU) {
62 targetRot -= F_TAU;
63 }
64
65 if (targetRot < rot().y) {
66 if (m_rotating) {
67 subRot(EGG::Vector3f(0.0f, F_TAU, 0.0f));
68 } else {
69 setRot(EGG::Vector3f(rot().x, m_initRotY, rot().z));
70 m_anmState = AnmState::BeforeFall;
71 m_beforeFallTimer = BEFORE_FALL_FRAMES;
72
73 m_currRot = rot().y;
74 if (m_currRot >= F_PI) {
75 m_currRot -= F_TAU;
76 }
77
78 m_cycleTimer = m_fullDuration;
79 m_state = State::Stomping;
80 }
81 }
82
83 m_rotating = false;
84 } else if (m_state == State::RotatingAfterStomp) {
85 const auto &curTan = m_railInterpolator->curTangentDir();
86 f32 targetRot = FIDX2RAD * EGG::Mathf::Atan2FIdx(curTan.x, curTan.z);
87
88 if (targetRot < 0.0f) {
89 targetRot += F_TAU;
90 } else if (targetRot >= F_TAU) {
91 targetRot -= F_TAU;
92 }
93
94 if (targetRot < rot().y) {
95 setRot(EGG::Vector3f(rot().x, targetRot, rot().z));
96 m_state = State::Moving;
97 m_rotating = true;
98 }
99 }
100}
101
102} // namespace Kinoko::Field
Base class for the various different Thwomp types in the game.
u32 m_fullDuration
Framecount of an entire animation loop.
@ BeforeFall
The quick upwards motion before slamming down.
s32 m_beforeFallTimer
Number of frames until the Thwomp will stomp down.
Pertains to collision.
A 3D float vector.
Definition Vector.hh:107