A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectFireRing.cc
1#include "ObjectFireRing.hh"
2
3namespace Field {
4
6ObjectFireRing::ObjectFireRing(const System::MapdataGeoObj &params)
7 : ObjectCollidable(params), m_phase(0.0f) {
8 size_t fireballCount = std::max<u32>(1, params.setting(0));
9 m_angSpeed = static_cast<f32>(static_cast<s16>(params.setting(1)));
10 m_fireballs = std::span<ObjectFireball *>(new ObjectFireball *[fireballCount], fireballCount);
11 f32 distance = 100.0f * static_cast<f32>(params.setting(3));
12
13 for (size_t i = 0; i < fireballCount; ++i) {
14 m_fireballs[i] = new ObjectFireball(params);
15 m_fireballs[i]->load();
16 m_fireballs[i]->setDistance(distance);
17 m_fireballs[i]->setAngle(static_cast<f32>(i) * (360.0f / fireballCount));
18 }
19
21 mat.makeR(m_rot);
22 m_axis = mat.base(2);
23 m_axis.normalise();
24 m_initDir = m_axis.cross(RotateAxisAngle(F_PI / 2.0f, EGG::Vector3f::ex, m_axis));
25 m_initDir.normalise();
26 m_radiusScale = 0.1f * static_cast<f32>(params.setting(2));
27}
28
30ObjectFireRing::~ObjectFireRing() {
31 delete m_fireballs.data();
32}
33
35void ObjectFireRing::init() {
36 m_degAngle = 0.0f;
37}
38
40void ObjectFireRing::calc() {
41 m_phase += 1.0f;
42 m_degAngle += m_angSpeed / 60.0f;
43
44 if (m_degAngle > 360.0f) {
45 m_degAngle -= 360.0f;
46 } else if (m_degAngle < 0.0f) {
47 m_degAngle += 360.0f;
48 }
49
50 f32 radius = m_radiusScale * EGG::Mathf::sin(m_phase * DEG2RAD);
51
52 for (auto *&fireball : m_fireballs) {
53 EGG::Vector3f dir = m_initDir * fireball->distance() * (1.0f + radius);
54 fireball->setPos(
55 m_pos + RotateAxisAngle((m_degAngle + fireball->angle()) * DEG2RAD, m_axis, dir));
56 }
57}
58
59} // 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:60
void makeR(const Vector3f &r)
Sets 3x3 rotation matrix from a vector of Euler angles.
Definition Matrix.cc:122
static f32 sin(f32 x)
Definition Math.hh:33
Pertains to collision.
A 3D float vector.
Definition Vector.hh:83
f32 normalise()
Normalizes the vector and returns the original length.
Definition Vector.cc:44