A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectHeyhoShipManager.cc
1#include "ObjectHeyhoShipManager.hh"
2
3#include "game/field/ObjectDirector.hh"
4#include "game/field/RailManager.hh"
5#include "game/field/obj/ObjectHeyhoShip.hh"
6
7namespace Kinoko::Field {
8
10ObjectHeyhoShipManager::ObjectHeyhoShipManager() {
11 auto &managedObjs = ObjectDirector::Instance()->managedObjects();
12 size_t count = 0;
13 for (auto *&obj : managedObjs) {
14 if (strcmp(obj->getName(), "HeyhoBallGBA") == 0) {
15 ++count;
16 }
17 }
18
19 m_projectiles = owning_span<ObjectProjectile *>(count);
20 size_t curIdx = 0;
21 for (auto *&obj : managedObjs) {
22 if (strcmp(obj->getName(), "HeyhoBallGBA") == 0) {
23 m_projectiles[curIdx++] = reinterpret_cast<ObjectProjectile *>(obj);
24 } else if (strcmp(obj->getName(), "HeyhoShipGBA") == 0) {
25 m_launcher = reinterpret_cast<ObjectProjectileLauncher *>(obj);
26 }
27 }
28
29 u16 pointCount = m_launcher->railInterpolator()->pointCount();
30 m_pointIdxs = owning_span<s16>(pointCount);
31}
32
34ObjectHeyhoShipManager::~ObjectHeyhoShipManager() = default;
35
39 constexpr f32 PROJECTILE_ANGLE = F_PI / 2.0f;
40 constexpr EGG::Vector3f HEIGHT_OFFSET = EGG::Vector3f::ey * 1600.0f;
41 constexpr f32 FORWARD_OFFSET = 1200.0f;
42 constexpr f32 LATERAL_OFFSET = 700.0f;
43
44 const auto *launcherRailInterp = m_launcher->railInterpolator();
45 for (u16 i = 0; i < launcherRailInterp->pointCount(); ++i) {
46 m_pointIdxs[i] = -1;
47 }
48
49 for (size_t i = 0; i < m_projectiles.size(); ++i) {
50 m_pointIdxs[m_projectiles[i]->idx()] = i;
51 }
52
53 auto *ship = reinterpret_cast<ObjectHeyhoShip *>(m_launcher);
54 auto *launcherRail = RailManager::Instance()->rail(launcherRailInterp->railIdx());
55 for (auto *&obj : m_projectiles) {
56 const s16 idx = obj->idx();
57 const auto &dir = ship->initRailDir(idx);
58 EGG::Vector3f forward = RotateXZByYaw(PROJECTILE_ANGLE, dir) * FORWARD_OFFSET;
59 EGG::Vector3f posOffset = forward + HEIGHT_OFFSET - dir * LATERAL_OFFSET;
60 EGG::Vector3f shipPos = launcherRail->pointPos(idx) + posOffset;
61
62 obj->initProjectile(shipPos);
63 }
64
65 m_launcher->init();
66}
67
69void ObjectHeyhoShipManager::calc() {
70 s32 idx = m_launcher->launchPointIdx();
71
72 if (idx != -1) {
73 s16 pointIdx = m_pointIdxs[idx];
74
75 if (pointIdx != -1) {
76 m_projectiles[pointIdx]->onLaunch();
77 }
78 }
79}
80
81} // namespace Kinoko::Field
static EGG::Vector3f RotateXZByYaw(f32 angle, const EGG::Vector3f &v)
Rotates a vector around the Y-axis and returns the XZ-plane portion of the vector.
The ship on GBA Shy Guy Beach that shoots cannonballs.
virtual s16 launchPointIdx()=0
Used by ObjectSniper to check which object (if any) should be thrown.
Pertains to collision.
A 3D float vector.
Definition Vector.hh:107