A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectSanbo.cc
1#include "ObjectSanbo.hh"
2
3#include "game/field/CollisionDirector.hh"
4#include "game/field/KColData.hh"
5
6namespace Field {
7
9ObjectSanbo::ObjectSanbo(const System::MapdataGeoObj &params) : ObjectCollidable(params) {
10 m_yVel = 0.0f;
11}
12
14ObjectSanbo::~ObjectSanbo() = default;
15
17void ObjectSanbo::init() {
18 m_up = EGG::Vector3f::ey;
20 rot.makeR(m_rot);
21 m_tangent = rot.base(2);
22 m_tangent.normalise();
23 m_standstill = false;
24 m_railInterpolator->init(0.0f, 0);
25}
26
28void ObjectSanbo::calc() {
29 calcMove();
30}
31
33void ObjectSanbo::calcMove() {
34 constexpr f32 GRAVITY = 2.0f;
35
36 if (m_standstill) {
37 if (--m_stillDuration == 0) {
38 m_standstill = false;
39 }
40
41 return;
42 }
43
44 auto railStatus = m_railInterpolator->calc();
45 if (railStatus == RailInterpolator::Status::ChangingDirection) {
46 m_standstill = true;
47 m_stillDuration = m_railInterpolator->curPoint().setting[0];
48 }
49
50 const EGG::Vector3f &railPos = m_railInterpolator->curPos();
51 m_pos.x = railPos.x;
52 m_pos.z = railPos.z;
53 m_yVel -= GRAVITY;
54 m_flags.setBit(eFlags::Position);
55 m_pos.y = m_yVel + m_pos.y;
56
57 checkSphere();
58}
59
62void ObjectSanbo::checkSphere() {
63 constexpr f32 RADIUS = 10.0f;
64 constexpr EGG::Vector3f POS_OFFSET = EGG::Vector3f(0.0f, RADIUS, 0.0f);
65
66 CollisionInfo colInfo;
67 colInfo.bbox.setZero();
68
69 EGG::Vector3f norm = m_up;
70
71 if (CollisionDirector::Instance()->checkSphereFull(RADIUS, m_pos + POS_OFFSET,
72 EGG::Vector3f::inf, KCL_TYPE_FLOOR, &colInfo, nullptr, 0)) {
73 m_yVel = 0.0f;
74 m_flags.setBit(eFlags::Position);
75 m_pos += colInfo.tangentOff;
76 norm = colInfo.floorNrm;
77 }
78
79 EGG::Vector3f upNrm = m_up;
80 upNrm.normalise();
81 norm.normalise();
82
83 m_up += (norm - upNrm).multInv(60.0f);
84 m_up.normalise();
85
86 setMatrixTangentTo(m_up, m_tangent);
87}
88
89} // namespace Field
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
A 3 x 4 matrix.
Definition Matrix.hh:8
Vector3f base(size_t col) const
Get a particular column from a matrix.
Definition Matrix.hh:70
void makeR(const Vector3f &r)
Sets 3x3 rotation matrix from a vector of Euler angles.
Definition Matrix.cc:98
Pertains to collision.
A 3D float vector.
Definition Vector.hh:87
f32 normalise()
Normalizes the vector and returns the original length.
Definition Vector.cc:44