A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectPakkunF.cc
1#include "ObjectPakkunF.hh"
2
3namespace Field {
4
6ObjectPakkunF::ObjectPakkunF(const System::MapdataGeoObj &params)
7 : ObjectCollidable(params), m_attackFrames(0), m_currAttackFrame(0),
8 m_waitDuration(static_cast<s32>(m_mapObj->setting(0))) {}
9
11ObjectPakkunF::~ObjectPakkunF() = default;
12
14void ObjectPakkunF::init() {
15 m_state = State::Wait;
16 m_waitFrames = m_waitDuration;
17
18 calcTransform();
19}
20
22void ObjectPakkunF::calc() {
23 switch (m_state) {
24 case State::Wait:
25 calcWait();
26 break;
27 case State::Attack:
28 calcAttack();
29 break;
30 default:
31 break;
32 }
33
34 calcCollisionTransform();
35}
36
38void ObjectPakkunF::loadAnims() {
39 std::array<const char *, 3> names = {{
40 "attack",
41 "damage",
42 "wait",
43 }};
44
45 std::array<Render::AnmType, 3> types = {{
46 Render::AnmType::Chr,
47 Render::AnmType::Chr,
48 Render::AnmType::Chr,
49 }};
50
51 linkAnims(names, types);
52}
53
55void ObjectPakkunF::calcCollisionTransform() {
56 constexpr EGG::Vector3f INIT_POS = EGG::Vector3f(0.0f, 620.0f, 70.0f);
57 constexpr EGG::Vector3f FINAL_POS = EGG::Vector3f(0.0f, 160.0f, 550.0f);
58
59 if (!m_collision) {
60 return;
61 }
62
63 EGG::Vector3f posOffset;
64
65 if (m_state == State::Attack) {
66 if (m_currAttackFrame <= 10) {
67 posOffset = INIT_POS * m_scale.x;
68 } else if (m_currAttackFrame <= 20) {
69 f32 fVar1 = 0.1f * static_cast<f32>(m_currAttackFrame - 10);
70 posOffset = FINAL_POS * m_scale.x * fVar1 + INIT_POS * m_scale.x * (1.0f - fVar1);
71 } else if (m_currAttackFrame <= 30) {
72 f32 fVar1 = 0.1f * static_cast<f32>(m_currAttackFrame - 20);
73 posOffset = INIT_POS * m_scale.x * fVar1 + FINAL_POS * m_scale.x * (1.0f - fVar1);
74 } else {
75 posOffset = INIT_POS * m_scale.x;
76 }
77 } else {
78 posOffset = INIT_POS * m_scale.x;
79 }
80
81 EGG::Matrix34f rotMat;
82 rotMat.makeR(m_rot);
83
84 // Probably always evaluates to the identity matrix in time trials
85 EGG::Matrix34f damageRotMat = EGG::Matrix34f::ident;
86 damageRotMat.setAxisRotation(0.0f, EGG::Vector3f::ey);
87
88 EGG::Matrix34f transformMat;
89 transformMat.makeT(m_pos + rotMat.multiplyTo(damageRotMat).ps_multVector(posOffset));
90
91 m_collision->transform(transformMat, m_scale);
92}
93
95void ObjectPakkunF::calcWait() {
96 if (--m_waitFrames == 0) {
97 enterAttack();
98 }
99}
100
102void ObjectPakkunF::calcAttack() {
103 ++m_currAttackFrame;
104
105 if (--m_attackFrames == 0) {
106 m_state = State::Wait;
107 m_waitFrames = m_waitDuration;
108 }
109}
110
112void ObjectPakkunF::enterAttack() {
113 constexpr s32 LINGERING_FRAMES = 60;
114
115 m_state = State::Attack;
116 auto *anmMgr = m_drawMdl->anmMgr();
117 anmMgr->playAnim(0.0f, 1.0f, 0);
118 m_currAttackFrame = 0;
119 auto *attackAnm = anmMgr->activeAnim(Render::AnmType::Chr);
120 m_attackFrames = static_cast<s32>(attackAnm->frameCount()) + LINGERING_FRAMES;
121}
122
123} // namespace Field
A 3 x 4 matrix.
Definition Matrix.hh:8
Matrix34f multiplyTo(const Matrix34f &rhs) const
Multiplies two matrices.
Definition Matrix.cc:189
void setAxisRotation(f32 angle, const Vector3f &axis)
Rotates the matrix about an axis.
Definition Matrix.cc:167
void makeR(const Vector3f &r)
Sets 3x3 rotation matrix from a vector of Euler angles.
Definition Matrix.cc:98
Vector3f ps_multVector(const Vector3f &vec) const
Paired-singles impl. of multVector.
Definition Matrix.cc:224
Pertains to collision.
A 3D float vector.
Definition Vector.hh:88