Loading [MathJax]/extensions/tex2jax.js
A reimplementation of Mario Kart Wii's physics engine in C++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages Concepts
ObjectDokan.cc
1#include "ObjectDokan.hh"
2
3#include "game/field/CollisionDirector.hh"
4
5#include "game/kart/KartCollide.hh"
6
7namespace 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 m_pos += m_velocity;
30 m_flags |= 1;
31
32 calcFloor();
33}
34
36void ObjectDokan::calcCollisionTransform() {
37 if (m_id == ObjectId::DokanSFC) {
38 ObjectCollidable::calcCollisionTransform();
39 } else {
40 // rMR piranhas
41 calcTransform();
42 EGG::Matrix34f mat = m_transform;
43 mat.setBase(3, mat.translation() + EGG::Vector3f::ey * 300.0f);
44 m_collision->transform(mat, m_scale, getCollisionTranslation());
45 }
46}
47
49Kart::Reaction ObjectDokan::onCollision(Kart::KartObject * /*kartObj*/,
50 Kart::Reaction reactionOnKart, Kart::Reaction reactionOnObj, EGG::Vector3f & /*hitDepth*/) {
51 constexpr f32 INITIAL_VELOCITY = 100.0f;
52
53 if (reactionOnObj == Kart::Reaction::UNK_3 || reactionOnObj == Kart::Reaction::UNK_5) {
54 if (!m_b0) {
55 m_b0 = true;
56 m_velocity = INITIAL_VELOCITY * EGG::Vector3f::ey;
57 }
58 }
59
60 return reactionOnKart;
61}
62
64void ObjectDokan::calcFloor() {
65 constexpr f32 PIPE_RADIUS = 100.0f;
66 constexpr f32 PIPE_SQRT_RADIUS = 10.0f;
67 constexpr f32 ACCELERATION = 0.2f;
68
69 CollisionInfo colInfo;
70 EGG::Vector3f pos = m_pos;
71 pos.y += PIPE_RADIUS;
72 KCLTypeMask typeMask;
73
74 if (!CollisionDirector::Instance()->checkSphereFull(PIPE_RADIUS, pos, EGG::Vector3f::inf,
75 KCL_TYPE_64EBDFFF, &colInfo, &typeMask, 0)) {
76 return;
77 }
78
79 if (typeMask & KCL_TYPE_FLOOR) {
80 m_pos.y += colInfo.tangentOff.y;
81 m_flags |= 1;
82 } else {
83 m_velocity.y *= -ACCELERATION;
84 m_flags |= 1;
85 m_pos.y += colInfo.tangentOff.y;
86
87 if (m_velocity.length() < ACCELERATION * PIPE_SQRT_RADIUS) {
88 m_b0 = false;
89 }
90 }
91}
92
93} // 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
void setBase(size_t col, const Vector3f &base)
Sets one column of a matrix.
Definition Matrix.cc:189
The highest level abstraction for a kart.
Definition KartObject.hh:11
Pertains to collision.
A 3D float vector.
Definition Vector.hh:83