A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectHeyhoShip.cc
1#include "ObjectHeyhoShip.hh"
2
3namespace Kinoko::Field {
4
6ObjectHeyhoShip::ObjectHeyhoShip(const System::MapdataGeoObj &params)
8 m_yAmplitude(static_cast<f32>(static_cast<s16>(params.setting(1)))), m_frame(0) {
9 registerManagedObject();
10}
11
13ObjectHeyhoShip::~ObjectHeyhoShip() = default;
14
16void ObjectHeyhoShip::init() {
17 m_railInterpolator->init(0.0f, 0);
18 m_railInterpolator->setPerPointVelocities(true);
19 setPos(m_railInterpolator->curPos());
20
21 const EGG::Vector3f &railTan = m_railInterpolator->curTangentDir();
22 EGG::Vector3f tangent = EGG::Vector3f(railTan.x, 0.0f, railTan.z);
23 tangent.normalise2();
24 tangent = RotateXZByYaw(F_PI / 2.0f, tangent);
25
26 if (EGG::Mathf::abs(tangent.y) > 0.1f) {
27 tangent.y = 0.01f;
28 }
29
30 if (tangent.squaredLength() > std::numeric_limits<f32>::epsilon()) {
31 tangent.normalise2();
32 } else {
33 tangent = EGG::Vector3f::ey;
34 }
35
36 m_framesSinceLastLaunch = 1000;
37 setMatrixTangentTo(EGG::Vector3f::ey, tangent);
38}
39
41void ObjectHeyhoShip::calc() {
42 if (m_railInterpolator->calc() == RailInterpolator::Status::SegmentEnd) {
43 m_framesSinceLastLaunch = 0;
44 } else {
45 ++m_framesSinceLastLaunch;
46 }
47
48 calcPos();
49}
50
52void ObjectHeyhoShip::calcPos() {
53 constexpr f32 PERIOD = 100.0f;
54
55 setPos(m_railInterpolator->curPos());
56
57 f32 fidx = DEG2FIDX * (360.0f * static_cast<f32>(++m_frame) / PERIOD);
58 f32 posY = m_yAmplitude * EGG::Mathf::SinFIdx(fidx) + pos().y;
59 setPos(EGG::Vector3f(pos().x, posY, pos().z));
60}
61
62} // namespace Kinoko::Field
Abstract class that moves along its own rail and throws projectiles.
Pertains to collision.