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 Kinoko::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;
19 EGG::Matrix34f rotMat;
20 rotMat.makeR(rot());
21 m_tangent = rotMat.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_yVel -= GRAVITY;
52 setPos(EGG::Vector3f(railPos.x, m_yVel + pos().y, railPos.z));
53
54 checkSphere();
55}
56
60 constexpr f32 RADIUS = 10.0f;
61 constexpr EGG::Vector3f POS_OFFSET = EGG::Vector3f(0.0f, RADIUS, 0.0f);
62
63 CollisionInfo colInfo;
64 colInfo.bbox.setZero();
65
66 EGG::Vector3f norm = m_up;
67
68 if (CollisionDirector::Instance()->checkSphereFull(RADIUS, pos() + POS_OFFSET,
69 EGG::Vector3f::inf, KCL_TYPE_FLOOR, &colInfo, nullptr, 0)) {
70 m_yVel = 0.0f;
71 addPos(colInfo.tangentOff);
72 norm = colInfo.floorNrm;
73 }
74
75 EGG::Vector3f upNrm = m_up;
76 upNrm.normalise();
77 norm.normalise();
78
79 m_up += (norm - upNrm).multInv(60.0f);
80 m_up.normalise();
81
82 setMatrixTangentTo(m_up, m_tangent);
83}
84
85} // namespace Kinoko::Field
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
void checkSphere()
Handles collision between the pokie and the floor (including sandcones).
f32 m_yVel
Falling speed.
Pertains to collision.
A 3D float vector.
Definition Vector.hh:107
constexpr f32 normalise()
Normalizes the vector and returns the original length.
Definition Vector.hh:278