A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartPhysics.hh
1#pragma once
2
3#include "game/kart/CollisionGroup.hh"
4#include "game/kart/KartDynamics.hh"
5#include "game/kart/KartParam.hh"
6
7#include <egg/math/Matrix.hh>
8
9namespace Kart {
10
14public:
15 KartPhysics(bool isBike);
17
18 void reset();
19 void updatePose();
20
21 void calc(f32 dt, f32 maxSpeed, const EGG::Vector3f &scale, bool air);
22
24 void setPos(const EGG::Vector3f &pos) {
25 m_pos = pos;
26 }
27
28 void setVelocity(const EGG::Vector3f &vel) {
29 m_velocity = vel;
30 }
31
32 void set_fc(f32 val) {
33 m_fc = val;
34 }
35
37 void composeStuntRot(const EGG::Quatf &rot) {
38 m_instantaneousStuntRot *= rot;
39 }
40
42 void composeExtraRot(const EGG::Quatf &rot) {
43 m_instantaneousExtraRot *= rot;
44 }
45
47 void composeDecayingStuntRot(const EGG::Quatf &rot) {
48 m_decayingStuntRot *= rot;
49 }
50
52 void composeDecayingExtraRot(const EGG::Quatf &rot) {
53 m_decayingExtraRot *= rot;
54 }
55
57 void composeMovingObjVel(const EGG::Vector3f &vel, f32 t) {
58 m_movingObjVel += (vel - m_movingObjVel) * t;
59 dynamics()->setMovingObjVel(m_movingObjVel);
60 }
61
63 void composeDecayingMovingObjVel(f32 floorScalar, f32 airScalar, bool floor) {
64 m_movingObjVel *= floor ? floorScalar : airScalar;
65 dynamics()->setMovingObjVel(m_movingObjVel);
66 }
67
69 void composeMovingRoadVel(const EGG::Vector3f &vel, f32 t) {
70 m_movingRoadVel += (vel - m_movingRoadVel) * t;
71 dynamics()->setMovingRoadVel(m_movingRoadVel);
72 }
73
74 void shiftDecayMovingRoadVel(const EGG::Vector3f &v, f32 maxPullSpeed);
75
77 void decayMovingRoadVel(f32 floorScalar, f32 airScalar, bool floor) {
78 m_movingRoadVel *= floor ? floorScalar : airScalar;
79 m_movingRoadVel.y = 0.0f;
80 dynamics()->setMovingRoadVel(m_movingRoadVel);
81 }
82
84 void clearDecayingRot() {
85 m_decayingStuntRot = EGG::Quatf::ident;
86 m_decayingExtraRot = EGG::Quatf::ident;
87 }
89
91 [[nodiscard]] KartDynamics *dynamics() {
92 return m_dynamics;
93 }
94
95 [[nodiscard]] const KartDynamics *dynamics() const {
96 return m_dynamics;
97 }
98
99 [[nodiscard]] const EGG::Matrix34f &pose() const {
100 return m_pose;
101 }
102
103 [[nodiscard]] CollisionGroup *hitboxGroup() {
104 return m_hitboxGroup;
105 }
106
107 [[nodiscard]] const EGG::Vector3f &xAxis() const {
108 return m_xAxis;
109 }
110
111 [[nodiscard]] const EGG::Vector3f &yAxis() const {
112 return m_yAxis;
113 }
114
115 [[nodiscard]] const EGG::Vector3f &zAxis() const {
116 return m_zAxis;
117 }
118
119 [[nodiscard]] const EGG::Vector3f &pos() const {
120 return m_pos;
121 }
122
123 [[nodiscard]] f32 fc() const {
124 return m_fc;
125 }
127
128 [[nodiscard]] static KartPhysics *Create(const KartParam &param);
129
130private:
131 KartDynamics *m_dynamics;
132 CollisionGroup *m_hitboxGroup;
133 EGG::Vector3f m_pos;
134 EGG::Quatf m_decayingStuntRot;
135 EGG::Quatf m_instantaneousStuntRot;
136 EGG::Quatf m_specialRot;
139 EGG::Quatf m_instantaneousExtraRot;
140 EGG::Quatf m_extraRot;
141 EGG::Vector3f m_movingObjVel;
142 EGG::Vector3f m_movingRoadVel;
148 f32 m_fc;
149};
150
151} // namespace Kart
A 3 x 4 matrix.
Definition Matrix.hh:8
Houses hitbox and collision info for an object (body or wheel).
State management for most components of a kart's physics.
Houses stats regarding a given character/vehicle combo.
Definition KartParam.hh:51
Manages the lifecycle of KartDynamics, handles moving floors and trick rotation.
void updatePose()
Constructs a transformation matrix from rotation and position.
void calc(f32 dt, f32 maxSpeed, const EGG::Vector3f &scale, bool air)
Computes trick rotation and calls to KartDynamics::calc().
EGG::Quatf m_decayingExtraRot
Rotation that occurs when landing from a trick.
EGG::Vector3f m_zAxis
The third column of the pose.
EGG::Vector3f m_xAxis
The first column of the pose.
EGG::Vector3f m_velocity
Copied from KartDynamics.
EGG::Vector3f m_yAxis
The second column of the pose.
EGG::Matrix34f m_pose
The kart's current rotation and position.
Pertains to kart-related functionality.
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
A 3D float vector.
Definition Vector.hh:88