A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectDokan.cc
1#include "ObjectDokan.hh"
2
3#include "game/field/CollisionDirector.hh"
4
5#include "game/kart/KartCollide.hh"
6
7namespace Kinoko::Field {
8
10ObjectDokan::ObjectDokan(const System::MapdataGeoObj &params) : ObjectCollidable(params) {}
11
13ObjectDokan::~ObjectDokan() = default;
14
16void ObjectDokan::init() {
17 m_b0 = false;
18}
19
21void ObjectDokan::calc() {
22 constexpr f32 ACCEL = 2.0f;
23
24 if (!m_b0) {
25 return;
26 }
27
28 m_velocity.y -= ACCEL;
29 addPos(m_velocity);
30
31 calcFloor();
32}
33
35void ObjectDokan::calcCollisionTransform() {
36 if (m_id == ObjectId::DokanSFC) {
37 ObjectCollidable::calcCollisionTransform();
38 } else {
39 // rMR piranhas
40 calcTransform();
41 EGG::Matrix34f mat = transform();
42 mat.setBase(3, mat.translation() + EGG::Vector3f::ey * 300.0f);
43 m_collision->transform(mat, scale(), getCollisionTranslation());
44 }
45}
46
48Kart::Reaction ObjectDokan::onCollision(Kart::KartObject * /*kartObj*/,
49 Kart::Reaction reactionOnKart, Kart::Reaction reactionOnObj, EGG::Vector3f & /*hitDepth*/) {
50 constexpr f32 INITIAL_VELOCITY = 100.0f;
51
52 if (reactionOnObj == Kart::Reaction::UNK_3 || reactionOnObj == Kart::Reaction::UNK_5) {
53 if (!m_b0) {
54 m_b0 = true;
55 m_velocity = INITIAL_VELOCITY * EGG::Vector3f::ey;
56 }
57 }
58
59 return reactionOnKart;
60}
61
63void ObjectDokan::calcFloor() {
64 constexpr f32 PIPE_RADIUS = 100.0f;
65 constexpr f32 PIPE_SQRT_RADIUS = 10.0f;
66 constexpr f32 ACCELERATION = 0.2f;
67
68 CollisionInfo colInfo;
69 EGG::Vector3f colPos = pos();
70 colPos.y += PIPE_RADIUS;
71 KCLTypeMask typeMask;
72
73 if (!CollisionDirector::Instance()->checkSphereFull(PIPE_RADIUS, colPos, EGG::Vector3f::inf,
74 KCL_TYPE_64EBDFFF, &colInfo, &typeMask, 0)) {
75 return;
76 }
77
78 addPos(EGG::Vector3f(0.0f, colInfo.tangentOff.y, 0.0f));
79
80 if (typeMask & KCL_TYPE_FLOOR) {
81 m_velocity.y *= -ACCELERATION;
82 if (m_velocity.length() < ACCELERATION * PIPE_SQRT_RADIUS) {
83 m_b0 = false;
84 }
85 }
86}
87
88} // namespace Kinoko::Field
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
Pertains to collision.