Loading [MathJax]/jax/input/TeX/config.js
A reimplementation of Mario Kart Wii's physics engine in C++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages Concepts
KartBody.cc
1#include "KartBody.hh"
2
3#include <egg/math/Math.hh>
4
5namespace 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
16EGG::Matrix34f KartBody::wheelMatrix(u16) {
18 mat.makeQT(fullRot(), pos());
19 return mat;
20}
21
23void KartBody::reset() {
24 m_physics->reset();
25 m_anAngle = 0.0f;
26 m_sinkDepth = 0.0f;
27 m_targetSinkDepth = 0.0f;
28}
29
31void KartBody::calcSinkDepth() {
32 m_sinkDepth += (m_targetSinkDepth - m_sinkDepth) * 0.1f;
33}
34
36void KartBody::trySetTargetSinkDepth(f32 val) {
37 m_targetSinkDepth = std::max(val, m_targetSinkDepth);
38}
39
41void KartBody::calcTargetSinkDepth() {
42 m_targetSinkDepth = 3.0f * static_cast<f32>(collisionData().intensity);
43}
44
46KartBodyKart::KartBodyKart(KartPhysics *physics) : KartBody(physics) {}
47
49KartBodyKart::~KartBodyKart() {
50 delete m_physics;
51}
52
54KartBodyBike::KartBodyBike(KartPhysics *physics) : KartBody(physics) {}
55
57KartBodyBike::~KartBodyBike() {
58 delete m_physics;
59}
60
68
69 mat.makeQT(fullRot(), pos());
70 if (wheelIdx != 0) {
71 return mat;
72 }
73
74 EGG::Vector3f position = param()->bikeDisp().m_handlePos * scale();
75 EGG::Vector3f rotation = DEG2RAD * param()->bikeDisp().m_handleRot;
76
77 EGG::Matrix34f handleMatrix;
78 handleMatrix.makeRT(rotation, position);
79 EGG::Matrix34f tmp = mat.multiplyTo(handleMatrix);
80
81 EGG::Vector3f yRotation = EGG::Vector3f(0.0f, DEG2RAD * m_anAngle, 0.0f);
82 EGG::Matrix34f yRotMatrix;
83 yRotMatrix.makeR(yRotation);
84 mat = tmp.multiplyTo(yRotMatrix);
85
86 return mat;
87}
88
89KartBodyQuacker::KartBodyQuacker(KartPhysics *physics) : KartBodyBike(physics) {}
90
91KartBodyQuacker::~KartBodyQuacker() = default;
92
95 mat.makeQT(fullRot(), pos());
96 return mat;
97}
98
99} // namespace Kart
A 3 x 4 matrix.
Definition Matrix.hh:8
Matrix34f multiplyTo(const Matrix34f &rhs) const
Multiplies two matrices.
Definition Matrix.cc:197
void makeR(const Vector3f &r)
Sets 3x3 rotation matrix from a vector of Euler angles.
Definition Matrix.cc:122
void makeRT(const Vector3f &r, const Vector3f &t)
Sets rotation-translation matrix.
Definition Matrix.cc:95
void makeQT(const Quatf &q, const Vector3f &t)
Sets matrix from rotation and position.
Definition Matrix.cc:35
EGG::Matrix34f wheelMatrix(u16 wheelIdx) override
Computes a matrix to represent the rotation of a wheel.
Definition KartBody.cc:66
EGG::Matrix34f wheelMatrix(u16 wheelIdx) override
Computes a matrix to represent the rotation of a wheel.
Definition KartBody.cc:93
Manages the lifecycle of KartDynamics, handles moving floors and trick rotation.
Pertains to kart-related functionality.
A 3D float vector.
Definition Vector.hh:83