A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectWanwan.hh
1#pragma once
2
3#include "game/field/StateManager.hh"
4#include "game/field/obj/ObjectCollidable.hh"
5
6namespace Field {
7
9class ObjectWanwanPile final : public ObjectCollidable {
10public:
12 ObjectWanwanPile(const EGG::Vector3f &pos, const EGG::Vector3f &rot, const EGG::Vector3f &scale)
13 : ObjectCollidable("pile", pos, rot, scale) {}
14
16 ~ObjectWanwanPile() override = default;
17
19 [[nodiscard]] u32 loadFlags() const override {
20 return 1;
21 }
22
24 [[nodiscard]] const char *getResources() const override {
25 return "wanwan";
26 }
27
29 [[nodiscard]] const char *getKclName() const override {
30 return "pile";
31 }
32};
33
35class ObjectWanwan final : public ObjectCollidable, public StateManager {
36public:
38 ~ObjectWanwan() override;
39
40 void init() override;
41 void calc() override;
42
44 [[nodiscard]] u32 loadFlags() const override {
45 return 3;
46 }
47
48 Kart::Reaction onCollision(Kart::KartObject *kartObj, Kart::Reaction reactionOnKart,
49 Kart::Reaction reactionOnObj, EGG::Vector3f &hitDepth) override;
50
51private:
52 void enterWait();
53 void enterAttack();
54 void enterBack();
55
56 void calcWait();
57 void calcAttack();
58 void calcBack();
59
60 void calcPos();
61 void calcCollision();
62 void calcMat();
63 void calcChainAttachMat();
64 void calcSpeed();
65 void calcBounce();
66
68 void calcWanderTimer() {
69 calcWanderEnd();
70 }
71
73 void calcWanderEnd() {
74 if (m_wanderTimer++ >= m_idleDuration) {
75 m_nextStateId = 1;
76 }
77 }
78
80 void calcChain() {
81 if (m_chainAttachMat.base(3).squaredLength() > std::numeric_limits<f32>::epsilon()) {
82 calcChainAttachPos(m_chainAttachMat);
83 }
84 }
85
86 void calcTangent(f32 t);
87 void calcUp(f32 t);
88 void calcRandomTarget();
89 void initTransformKeyframes();
90 void calcAttackPos();
91 void calcChainAttachPos(EGG::Matrix34f mat);
92
94 [[nodiscard]] static f32 CrossXZ(const EGG::Vector3f &v0, const EGG::Vector3f &v1,
95 const EGG::Vector3f &v2) {
96 return (v2.x - v1.x) * (v0.z - v1.z) - (v0.x - v1.x) * (v2.z - v1.z);
97 }
98
99 static void SampleHermiteInterp(f32 start, f32 end, f32 startTangent, f32 endTangent,
100 std::span<f32> dst);
101
102 EGG::Vector3f m_vel;
103 EGG::Vector3f m_accel;
104 f32 m_speed;
105 f32 m_pitch;
106 EGG::Vector3f m_tangent;
107 EGG::Vector3f m_up;
108 EGG::Vector3f m_targetUp;
109 std::array<EGG::Matrix34f, 15> m_transformKeyframes;
110 const f32 m_chainLength;
111 const f32 m_attackDistance;
112 const f32 m_attackArcTargetX;
113 const f32 m_attackArcTargetZ;
114 u32 m_chainCount;
116 EGG::Vector3f m_initPos;
118 EGG::Vector3f m_attackArcCenter;
119 bool m_touchingFloor;
123 EGG::Vector3f m_targetDir;
127 u32 m_idleDuration;
129 EGG::Vector3f m_backDir;
130
135
136 static constexpr f32 SCALE = 2.0f;
137 static constexpr EGG::Vector3f GRAVITY = EGG::Vector3f(0.0f, 2.5f, 0.0f);
138 static constexpr f32 CHAIN_LENGTH = 135.0f;
139
140 static constexpr std::array<StateManagerEntry, 3> STATE_ENTRIES = {{
141 {StateEntry<ObjectWanwan, &ObjectWanwan::enterWait, &ObjectWanwan::calcWait>(0)},
142 {StateEntry<ObjectWanwan, &ObjectWanwan::enterAttack, &ObjectWanwan::calcAttack>(1)},
143 {StateEntry<ObjectWanwan, &ObjectWanwan::enterBack, &ObjectWanwan::calcBack>(2)},
144 }};
145};
146
147} // namespace Field
A 3 x 4 matrix.
Definition Matrix.hh:8
Vector3f base(size_t col) const
Get a particular column from a matrix.
Definition Matrix.hh:72
The wooden stake that the chain chomp is chained to.
Represents Chain Chomps chained to a stake that attack in a limited arc.
u32 m_frame
Counts up every frame.
EGG::Matrix34f m_chainAttachMat
Represents the position and rotation of where the Chain Chomp attaches to the chain.
EGG::Vector3f m_anchor
Effectively the position of the wooden stake.
f32 m_attackArc
Half of size of the arc the chain chomp can lurch within (in degrees)
EGG::Vector3f m_target
Where the chain chomp is currently moving towards.
bool m_attackStill
True when lurched forward and stationary.
EGG::Vector3f m_chainAttachPos
Where the chain attaches to the Chain Chomp.
bool m_chainTaut
Chain Chomp cannot move further because the chain is fully taut.
u32 m_wanderTimer
How long the chain chomp has been wandering for.
bool m_retarget
Tracks whether the target position has changed in the wait state.
Base class that represents different "states" for an object.
The highest level abstraction for a kart.
Definition KartObject.hh:11
Pertains to collision.
A 3D float vector.
Definition Vector.hh:88
f32 squaredLength() const
The dot product between the vector and itself.
Definition Vector.hh:182