A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartDynamics.hh
1#pragma once
2
3#include <egg/math/Matrix.hh>
4
5namespace Kart {
6
13public:
15 virtual ~KartDynamics();
16
17 virtual void forceUpright() {}
18 virtual void stabilize();
19
20 void init();
21
22 void resetInternalVelocity() {
23 m_intVel.setZero();
24 }
25
26 void setInertia(const EGG::Vector3f &m, const EGG::Vector3f &n);
27 void setBspParams(f32 rotSpeed, const EGG::Vector3f &m, const EGG::Vector3f &n,
28 bool skipInertia);
29
30 void calc(f32 dt, f32 maxSpeed, bool air);
31 void reset();
32
33 void applySuspensionWrench(const EGG::Vector3f &p, const EGG::Vector3f &Flinear,
34 const EGG::Vector3f &Frot, bool ignoreX);
35 void applyWrenchScaled(const EGG::Vector3f &p, const EGG::Vector3f &f, f32 scale);
36
38 void addForce(const EGG::Vector3f &pos) {
39 m_totalForce += pos;
40 }
41
43 void setPos(const EGG::Vector3f &pos) {
44 m_pos = pos;
45 }
46
47 void setGravity(f32 gravity) {
48 m_gravity = gravity;
49 }
50
51 void setMainRot(const EGG::Quatf &q) {
52 m_mainRot = q;
53 }
54
55 void setFullRot(const EGG::Quatf &q) {
56 m_fullRot = q;
57 }
58
59 void setSpecialRot(const EGG::Quatf &q) {
60 m_specialRot = q;
61 }
62
63 void setExtraRot(const EGG::Quatf &q) {
64 m_extraRot = q;
65 }
66
67 void setIntVel(const EGG::Vector3f &v) {
68 m_intVel = v;
69 }
70
71 void setTop(const EGG::Vector3f &v) {
72 m_top = v;
73 }
74
75 void setStabilizationFactor(f32 val) {
77 }
78
79 void setTotalForce(const EGG::Vector3f &v) {
80 m_totalForce = v;
81 }
82
83 void setExtVel(const EGG::Vector3f &v) {
84 m_extVel = v;
85 }
86
87 void setAngVel0(const EGG::Vector3f &v) {
88 m_angVel0 = v;
89 }
90
91 void setMovingObjVel(const EGG::Vector3f &v) {
93 }
94
95 void setAngVel2(const EGG::Vector3f &v) {
96 m_angVel2 = v;
97 }
98
99 void setAngVel0YFactor(f32 val) {
100 m_angVel0YFactor = val;
101 }
102
103 void setTop_(const EGG::Vector3f &v) {
104 m_top_ = v;
105 }
106
107 void setForceUpright(bool isSet) {
108 m_forceUpright = isSet;
109 }
110
111 void setNoGravity(bool isSet) {
112 m_noGravity = isSet;
113 }
114
115 void setKillExtVelY(bool isSet) {
116 m_killExtVelY = isSet;
117 }
119
121 [[nodiscard]] const EGG::Matrix34f &invInertiaTensor() const {
122 return m_invInertiaTensor;
123 }
124
125 [[nodiscard]] f32 angVel0Factor() const {
126 return m_angVel0Factor;
127 }
128
129 [[nodiscard]] const EGG::Vector3f &pos() const {
130 return m_pos;
131 }
132
133 [[nodiscard]] const EGG::Vector3f &velocity() const {
134 return m_velocity;
135 }
136
137 [[nodiscard]] f32 gravity() const {
138 return m_gravity;
139 }
140
141 [[nodiscard]] const EGG::Vector3f &intVel() const {
142 return m_intVel;
143 }
144
145 [[nodiscard]] const EGG::Quatf &mainRot() const {
146 return m_mainRot;
147 }
148
149 [[nodiscard]] const EGG::Quatf &fullRot() const {
150 return m_fullRot;
151 }
152
153 [[nodiscard]] const EGG::Vector3f &totalForce() const {
154 return m_totalForce;
155 }
156
157 [[nodiscard]] const EGG::Vector3f &extVel() const {
158 return m_extVel;
159 }
160
161 [[nodiscard]] const EGG::Vector3f &angVel0() const {
162 return m_angVel0;
163 }
164
165 [[nodiscard]] const EGG::Vector3f &movingObjVel() const {
166 return m_movingObjVel;
167 }
168
169 [[nodiscard]] const EGG::Vector3f &angVel2() const {
170 return m_angVel2;
171 }
172
173 [[nodiscard]] f32 speedFix() const {
174 return m_speedFix;
175 }
177
178protected:
202 f32 m_speedFix;
204
209};
210
215public:
218
219private:
220 void forceUpright() override;
221 void stabilize() override;
222};
223
224} // namespace Kart
A 3 x 4 matrix.
Definition Matrix.hh:8
State management for most components of a bike's physics.
void stabilize() override
Stabilizes the bike by rotating towards the y-axis unit vector.
State management for most components of a kart's physics.
EGG::Quatf m_specialRot
Rotation from trick animations. Copied from KartPhysics.
EGG::Vector3f m_movingRoadVel
Velocity from Koopa Cape water.
f32 m_speedNorm
Min of the max speed and m_velocity magnitude.
bool m_killExtVelY
Caps external velocity at 0.
EGG::Vector3f m_angVel1
[Unused]
void setBspParams(f32 rotSpeed, const EGG::Vector3f &m, const EGG::Vector3f &n, bool skipInertia)
On init, takes elements from the kart's BSP and computes the moment of inertia tensor.
f32 m_angVel0YFactor
Scalar for damping angular velocity.
EGG::Quatf m_fullRot
The combination of the other rotations.
EGG::Vector3f m_velocity
Sum of the linear velocities.
EGG::Vector3f m_top_
Basically m_top biased towards absolute up.
EGG::Vector3f m_totalTorque
Torque from linear motion and rotation.
EGG::Matrix34f m_invInertiaTensor
The inverse of m_inertiaTensor.
void applySuspensionWrench(const EGG::Vector3f &p, const EGG::Vector3f &Flinear, const EGG::Vector3f &Frot, bool ignoreX)
Every frame, computes torque from linear motion and rotation.
EGG::Vector3f m_top
The unit vector pointing up from the vehicle.
EGG::Vector3f m_intVel
What you typically consider to be the vehicle's speed.
EGG::Vector3f m_acceleration
Basically just m_totalForce.
EGG::Quatf m_extraRot
[Unused]
void applyWrenchScaled(const EGG::Vector3f &p, const EGG::Vector3f &f, f32 scale)
Applies a force linearly and rotationally to the kart.
EGG::Vector3f m_totalForce
Basically just gravity.
bool m_noGravity
Disables gravity. Relevant when respawning.
EGG::Matrix34f m_inertiaTensor
Resistance to rotational change, as a 3x3 matrix.
EGG::Vector3f m_angVel0
Angular velocity from m_totalTorque.
EGG::Vector3f m_pos
The vehicle's position.
EGG::Vector3f m_angVel2
The main component of angular velocity.
f32 m_stabilizationFactor
Scalar for damping the main rotation.
EGG::Vector3f m_movingObjVel
Velocity from things like TF conveyers.
EGG::Vector3f m_extVel
Velocity induced by collisions.
bool m_forceUpright
Specifies if we should return the vehicle to upwards orientation.
EGG::Quatf m_mainRot
Rotation based on the angular velocities.
virtual void stabilize()
Stabilizes the kart by rotating towards the y-axis unit vector.
void calc(f32 dt, f32 maxSpeed, bool air)
Every frame, computes acceleration, velocity, position and rotation of the kart.
f32 m_angVel0Factor
Scalar for damping angular velocity.
f32 m_gravity
Always -1.0f.
Pertains to kart-related functionality.
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
A 3D float vector.
Definition Vector.hh:87