A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartBody.cc
1#include "KartBody.hh"
2
3#include <egg/math/Math.hh>
4
5namespace Kinoko::Kart {
6
8KartBody::KartBody(KartPhysics *physics) : m_physics(physics) {
9 m_anAngle = 0.0f;
10 m_sinkDepth = 0.0f;
11 m_targetSinkDepth = 0.0f;
12}
13
20 return bodyMat;
21}
22
24void KartBody::init(const KartParam::KartDisp &kartDisp, const KartParam::BikeDisp &bikeDisp) {
25 setParams(kartDisp, bikeDisp);
26}
27
29void KartBody::reset() {
30 m_physics->reset();
31 m_anAngle = 0.0f;
32 m_sinkDepth = 0.0f;
33 m_targetSinkDepth = 0.0f;
34}
35
37void KartBody::calcSinkDepth() {
38 m_sinkDepth += (m_targetSinkDepth - m_sinkDepth) * 0.1f;
39}
40
42void KartBody::trySetTargetSinkDepth(f32 val) {
43 m_targetSinkDepth = std::max(val, m_targetSinkDepth);
44}
45
47void KartBody::calcTargetSinkDepth() {
48 m_targetSinkDepth = 3.0f * static_cast<f32>(collisionData().intensity);
49}
50
52KartBodyKart::KartBodyKart(KartPhysics *physics) : KartBody(physics) {}
53
55KartBodyKart::~KartBodyKart() {
56 EGG::egg_delete(m_physics);
57}
58
60KartBodyBike::KartBodyBike(KartPhysics *physics) : KartBody(physics) {}
61
63KartBodyBike::~KartBodyBike() {
64 EGG::egg_delete(m_physics);
65}
66
76 if (wheelIdx != 0) {
77 return bodyMat;
78 }
79
80 m_handleRotMat.setBase(3, m_handlePos * scale());
82
83 EGG::Vector3f yRotation = EGG::Vector3f(0.0f, DEG2RAD * m_anAngle, 0.0f);
84 EGG::Matrix34f yRotMatrix;
85 yRotMatrix.makeR(yRotation);
86
87 return tmp.multiplyTo(yRotMatrix);
88}
89
91void KartBodyBike::setParams(const KartParam::KartDisp & /* kartDisp */,
92 const KartParam::BikeDisp &bikeDisp) {
93 m_handlePos = bikeDisp.m_handlePos;
94 m_handleRotMat.makeR(DEG2RAD * bikeDisp.m_handleRot);
95}
96
97KartBodyQuacker::KartBodyQuacker(KartPhysics *physics) : KartBodyBike(physics) {}
98
99KartBodyQuacker::~KartBodyQuacker() = default;
100
104EGG::Matrix34f KartBodyQuacker::wheelMatrix(u16 /* wheelIdx */, const EGG::Matrix34f &bodyMat) {
105 return bodyMat;
106}
107
108} // namespace Kinoko::Kart
A 3 x 4 matrix.
Definition Matrix.hh:10
constexpr void makeR(const Vector3f &r)
Sets 3x3 rotation matrix from a vector of Euler angles.
Definition Matrix.hh:129
constexpr Matrix34f multiplyTo(const Matrix34f &rhs) const
Multiplies two matrices.
Definition Matrix.hh:238
EGG::Matrix34f wheelMatrix(u16 wheelIdx, const EGG::Matrix34f &bodyMat) override
Computes a matrix to represent the rotation of a wheel.
Definition KartBody.cc:75
EGG::Vector3f m_handlePos
The relative position of the handlebar.
Definition KartBody.hh:68
EGG::Matrix34f m_handleRotMat
The rotation of the handlebar.
Definition KartBody.hh:73
EGG::Matrix34f wheelMatrix(u16 wheelIdx, const EGG::Matrix34f &bodyMat) override
Definition KartBody.cc:104
virtual EGG::Matrix34f wheelMatrix(u16, const EGG::Matrix34f &bodyMat)
Computes a matrix to represent wheel rotation. For Karts, this is wheel-agnostic.
Definition KartBody.cc:19
Manages the lifecycle of KartDynamics, handles moving floors and trick rotation.
Pertains to kart-related functionality.
A 3D float vector.
Definition Vector.hh:107