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 &v, f32 scalar) {
58 m_movingObjVel += (v - m_movingObjVel) * scalar;
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 clearDecayingRot() {
70 m_decayingStuntRot = EGG::Quatf::ident;
71 m_decayingExtraRot = EGG::Quatf::ident;
72 }
74
76 [[nodiscard]] KartDynamics *dynamics() {
77 return m_dynamics;
78 }
79
80 [[nodiscard]] const KartDynamics *dynamics() const {
81 return m_dynamics;
82 }
83
84 [[nodiscard]] const EGG::Matrix34f &pose() const {
85 return m_pose;
86 }
87
88 [[nodiscard]] CollisionGroup *hitboxGroup() {
89 return m_hitboxGroup;
90 }
91
92 [[nodiscard]] const EGG::Vector3f &xAxis() const {
93 return m_xAxis;
94 }
95
96 [[nodiscard]] const EGG::Vector3f &yAxis() const {
97 return m_yAxis;
98 }
99
100 [[nodiscard]] const EGG::Vector3f &zAxis() const {
101 return m_zAxis;
102 }
103
104 [[nodiscard]] const EGG::Vector3f &pos() const {
105 return m_pos;
106 }
107
108 [[nodiscard]] f32 fc() const {
109 return m_fc;
110 }
112
113 [[nodiscard]] static KartPhysics *Create(const KartParam &param);
114
115private:
116 KartDynamics *m_dynamics;
117 CollisionGroup *m_hitboxGroup;
118 EGG::Vector3f m_pos;
119 EGG::Quatf m_decayingStuntRot;
120 EGG::Quatf m_instantaneousStuntRot;
121 EGG::Quatf m_specialRot;
124 EGG::Quatf m_instantaneousExtraRot;
125 EGG::Quatf m_extraRot;
126 EGG::Vector3f m_movingObjVel;
132 f32 m_fc;
133};
134
135} // 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:83