Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
ObjectSanbo.cc
1
#include "ObjectSanbo.hh"
2
3
#include "game/field/CollisionDirector.hh"
4
#include "game/field/KColData.hh"
5
6
namespace
Kinoko::Field
{
7
9
ObjectSanbo::ObjectSanbo(
const
System::MapdataGeoObj ¶ms) :
ObjectCollidable
(params) {
10
m_yVel = 0.0f;
11
}
12
14
ObjectSanbo::~ObjectSanbo() =
default
;
15
17
void
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
28
void
ObjectSanbo::calc() {
29
calcMove();
30
}
31
33
void
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
59
void
ObjectSanbo::checkSphere
() {
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
KCL_TYPE_FLOOR
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
Definition
KCollisionTypes.hh:90
Kinoko::Field::ObjectCollidable
Definition
ObjectCollidable.hh:18
Kinoko::Field::ObjectSanbo::checkSphere
void checkSphere()
Handles collision between the pokie and the floor (including sandcones).
Definition
ObjectSanbo.cc:59
Kinoko::Field::ObjectSanbo::m_yVel
f32 m_yVel
Falling speed.
Definition
ObjectSanbo.hh:26
Kinoko::Field
Pertains to collision.
Definition
BoxColManager.cc:10
Kinoko::EGG::Vector3f
A 3D float vector.
Definition
Vector.hh:107
Kinoko::EGG::Vector3f::normalise
constexpr f32 normalise()
Normalizes the vector and returns the original length.
Definition
Vector.hh:278
Kinoko::Field::CollisionInfo
Definition
KColData.hh:23
game
field
obj
ObjectSanbo.cc
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0