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 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 = std::span<ObjectProjectile *>(new ObjectProjectile *[count], 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 = std::span<s16>(new s16[pointCount], pointCount);
31}
32
34ObjectHeyhoShipManager::~ObjectHeyhoShipManager() {
35 delete[] m_projectiles.data();
36 delete[] m_pointIdxs.data();
37}
38
42 constexpr f32 PROJECTILE_ANGLE = F_PI / 2.0f;
43 constexpr EGG::Vector3f HEIGHT_OFFSET = EGG::Vector3f::ey * 1600.0f;
44 constexpr f32 FORWARD_OFFSET = 1200.0f;
45 constexpr f32 LATERAL_OFFSET = 700.0f;
46
47 const auto *launcherRailInterp = m_launcher->railInterpolator();
48 for (u16 i = 0; i < launcherRailInterp->pointCount(); ++i) {
49 m_pointIdxs[i] = -1;
50 }
51
52 for (size_t i = 0; i < m_projectiles.size(); ++i) {
53 m_pointIdxs[m_projectiles[i]->idx()] = i;
54 }
55
56 auto *ship = reinterpret_cast<ObjectHeyhoShip *>(m_launcher);
57 auto *launcherRail = RailManager::Instance()->rail(launcherRailInterp->railIdx());
58 for (auto *&obj : m_projectiles) {
59 const s16 idx = obj->idx();
60 const auto &dir = ship->initRailDir(idx);
61 EGG::Vector3f forward = RotateXZByYaw(PROJECTILE_ANGLE, dir) * FORWARD_OFFSET;
62 EGG::Vector3f posOffset = forward + HEIGHT_OFFSET - dir * LATERAL_OFFSET;
63 EGG::Vector3f shipPos = launcherRail->pointPos(idx) + posOffset;
64
65 obj->initProjectile(shipPos);
66 }
67
68 m_launcher->init();
69}
70
72void ObjectHeyhoShipManager::calc() {
73 s32 idx = m_launcher->launchPointIdx();
74
75 if (idx != -1) {
76 s16 pointIdx = m_pointIdxs[idx];
77
78 if (pointIdx != -1) {
79 m_projectiles[pointIdx]->onLaunch();
80 }
81 }
82}
83
84} // namespace 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:88