A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectHeyhoShip.cc
1#include "ObjectHeyhoShip.hh"
2
3namespace Field {
4
6ObjectHeyhoShip::ObjectHeyhoShip(const System::MapdataGeoObj &params)
7 : ObjectProjectileLauncher(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 m_pos = m_railInterpolator->curPos();
20 m_flags.setBit(eFlags::Position);
21
22 const EGG::Vector3f &railTan = m_railInterpolator->curTangentDir();
23 EGG::Vector3f tangent = EGG::Vector3f(railTan.x, 0.0f, railTan.z);
24 tangent.normalise2();
25 tangent = RotateXZByYaw(F_PI / 2.0f, tangent);
26
27 if (EGG::Mathf::abs(tangent.y) > 0.1f) {
28 tangent.y = 0.01f;
29 }
30
31 if (tangent.squaredLength() > std::numeric_limits<f32>::epsilon()) {
32 tangent.normalise2();
33 } else {
34 tangent = EGG::Vector3f::ey;
35 }
36
37 m_framesSinceLastLaunch = 1000;
38 setMatrixTangentTo(EGG::Vector3f::ey, tangent);
39}
40
42void ObjectHeyhoShip::calc() {
43 if (m_railInterpolator->calc() == RailInterpolator::Status::SegmentEnd) {
44 m_framesSinceLastLaunch = 0;
45 } else {
46 ++m_framesSinceLastLaunch;
47 }
48
49 calcPos();
50}
51
53void ObjectHeyhoShip::calcPos() {
54 constexpr f32 PERIOD = 100.0f;
55
56 m_pos = m_railInterpolator->curPos();
57 m_flags.setBit(eFlags::Position);
58
59 f32 fidx = DEG2FIDX * (360.0f * static_cast<f32>(++m_frame) / PERIOD);
60 m_pos.y = m_yAmplitude * EGG::Mathf::SinFIdx(fidx) + m_pos.y;
61}
62
63} // namespace Field
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