A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
RailInterpolator.hh
Go to the documentation of this file.
1#pragma once
2
3#include <Common.hh>
4
5#include "game/field/Rail.hh"
6
8
9#include <egg/math/Vector.hh>
10
11namespace Kinoko::Field {
12
14public:
15 enum class Status {
16 InProgress = 0,
17 SegmentEnd = 1,
18 ChangingDirection = 2,
19 };
20
23
24 virtual void init(f32 t, u32 idx) = 0;
25 virtual Status calc() = 0;
26 virtual void setCurrVel(f32 speed) = 0;
27
28 virtual f32 getCurrVel() = 0;
29 virtual void evalCubicBezierOnPath(f32 t, EGG::Vector3f &currDir,
31 virtual void getPathLocation(f32 t, s16 &idx, f32 &len) = 0;
32
33 [[nodiscard]] virtual f32 getCurrSegmentLength() const = 0;
34
35 void setPerPointVelocities(bool isSet) {
37 }
38
40 void setT(f32 t) {
41 m_segmentT = t;
42 }
43
50
51 [[nodiscard]] const EGG::Vector3f &floorNrm(size_t idx) const;
52 [[nodiscard]] f32 railLength() const;
53
54 [[nodiscard]] const System::MapdataPointInfo::Point &curPoint() const {
55 ASSERT(static_cast<size_t>(m_currPointIdx) < m_points.size());
57 }
58
59 [[nodiscard]] const System::MapdataPointInfo::Point &nextPoint() const {
60 ASSERT(static_cast<size_t>(m_nextPointIdx) < m_points.size());
62 }
63
64 [[nodiscard]] s16 railIdx() const {
65 return m_railIdx;
66 }
67
68 [[nodiscard]] u16 pointCount() const {
69 return m_pointCount;
70 }
71
72 [[nodiscard]] f32 speed() const {
73 return m_speed;
74 }
75
76 [[nodiscard]] const EGG::Vector3f &curPos() const {
77 return m_curPos;
78 }
79
80 [[nodiscard]] const EGG::Vector3f &curTangentDir() const {
81 return m_curTangentDir;
82 }
83
84 [[nodiscard]] f32 currVel() const {
85 return m_currVel;
86 }
87
88 [[nodiscard]] f32 segmentT() const {
89 return m_segmentT;
90 }
91
92 [[nodiscard]] bool isMovementDirectionForward() const {
94 }
95
96 [[nodiscard]] s16 curPointIdx() const {
97 return m_currPointIdx;
98 }
99
100 [[nodiscard]] s16 nextPointIdx() const {
101 return m_nextPointIdx;
102 }
103
104protected:
105 void updateVel();
106 void calcVelocities();
107 [[nodiscard]] bool shouldChangeDirection() const;
108 void calcDirectionChange();
109 void calcNextIndices();
110
113 std::span<const System::MapdataPointInfo::Point> m_points;
127 bool m_4a;
128};
129
131public:
134
135 void init(f32 t, u32 idx) override;
136 Status calc() override;
137 void setCurrVel(f32 speed) override;
138
140 [[nodiscard]] f32 getCurrVel() override {
141 return m_currVel;
142 }
143
144 void evalCubicBezierOnPath(f32 t, EGG::Vector3f &currDir,
145 EGG::Vector3f &curTangentDir) override;
146 void getPathLocation(f32 t, s16 &idx, f32 &len) override;
147
149 [[nodiscard]] f32 getCurrSegmentLength() const override {
151 return m_transitions[idx].m_length;
152 }
153
154private:
155 void calcNextSegment();
156 EGG::Vector3f lerp(f32 t, u32 currIdx, u32 nextIdx) const;
157
160
161 std::span<const RailLineTransition> m_transitions;
162
167};
168
170public:
173
174 void init(f32 t, u32 idx) override;
175 Status calc() override;
176 void setCurrVel(f32 speed) override;
177
181 [[nodiscard]] f32 getCurrVel() override {
182 if (m_velocityPending) {
183 m_velocityPending = false;
184 m_velocity = (m_curPos - m_prevPos).length();
185 }
186
187 return m_velocity;
188 }
189
190 void evalCubicBezierOnPath(f32 t, EGG::Vector3f &currDir,
191 EGG::Vector3f &curTangentDir) override;
192 void getPathLocation(f32 t, s16 &idx, f32 &len) override;
193
195 [[nodiscard]] f32 getCurrSegmentLength() const override {
197 return m_transitions[idx].m_length;
198 }
199
200private:
201 void calcCubicBezier(f32 t, u32 currIdx, u32 nextIdx, EGG::Vector3f &pos,
202 EGG::Vector3f &dir) const;
203 [[nodiscard]] EGG::Vector3f calcCubicBezierPos(f32 t, const RailSplineTransition &trans) const;
205 const RailSplineTransition &trans) const;
206 [[nodiscard]] f32 calcT(f32 t) const;
207 void calcNextSegment();
208
209 std::span<const RailSplineTransition> m_transitions;
210 std::span<const f32> m_pathPercentages;
213
218};
219
220} // namespace Kinoko::Field
This header houses common data types such as our integral types and enums.
#define ASSERT(e)
Definition Logger.hh:25
virtual void init(f32 t, u32 idx)=0
virtual void setCurrVel(f32 speed)=0
const System::MapdataPointInfo::Point & curPoint() const
std::span< const System::MapdataPointInfo::Point > m_points
const EGG::Vector3f & curPos() const
const System::MapdataPointInfo::Point & nextPoint() const
virtual f32 getCurrSegmentLength() const =0
const EGG::Vector3f & floorNrm(size_t idx) const
virtual void evalCubicBezierOnPath(f32 t, EGG::Vector3f &currDir, EGG::Vector3f &curTangentDir)=0
virtual void getPathLocation(f32 t, s16 &idx, f32 &len)=0
const EGG::Vector3f & curTangentDir() const
RailInterpolator(f32 speed, u32 idx)
std::span< const RailLineTransition > m_transitions
EGG::Vector3f lerp(f32 t, u32 currIdx, u32 nextIdx) const
void getPathLocation(f32 t, s16 &idx, f32 &len) override
void init(f32 t, u32 idx) override
void evalCubicBezierOnPath(f32 t, EGG::Vector3f &currDir, EGG::Vector3f &curTangentDir) override
f32 m_segmentLength
The length of m_currentDirection.
EGG::Vector3f calcCubicBezierTangentDir(f32 t, const RailSplineTransition &trans) const
void getPathLocation(f32 t, s16 &idx, f32 &len) override
void init(f32 t, u32 idx) override
bool m_velocityPending
Whether m_velocity needs to be recomputed from m_curPos and m_prevPos.
void evalCubicBezierOnPath(f32 t, EGG::Vector3f &currDir, EGG::Vector3f &curTangentDir) override
std::span< const RailSplineTransition > m_transitions
void calcCubicBezier(f32 t, u32 currIdx, u32 nextIdx, EGG::Vector3f &pos, EGG::Vector3f &dir) const
EGG::Vector3f calcCubicBezierPos(f32 t, const RailSplineTransition &trans) const
Pertains to collision.
float f32
Definition Memory.hh:21
int16_t s16
Definition Memory.hh:12
uint16_t u16
Definition Memory.hh:17
uint32_t u32
Definition Memory.hh:18
A 3D float vector.
Definition Vector.hh:108