1#include "ObjectCollidable.hh"
3#include "game/field/ObjectCollisionBox.hh"
4#include "game/field/ObjectCollisionCylinder.hh"
5#include "game/field/ObjectCollisionSphere.hh"
6#include "game/field/ObjectDirector.hh"
8#include "game/kart/KartObject.hh"
16ObjectCollidable::~ObjectCollidable() {
21void ObjectCollidable::load() {
28 ObjectDirector::Instance()->addObject(
this);
32void ObjectCollidable::calcCollisionTransform() {
34 m_collision->transform(m_transform, m_scale, getCollisionTranslation());
41f32 ObjectCollidable::getCollisionRadius()
const {
42 const auto &flowTable = ObjectDirector::Instance()->flowTable();
43 const auto *collisionSet = flowTable.set(flowTable.slot(m_id));
45 f32 zRadius = m_scale.z *
static_cast<f32
>(parse<s16>(collisionSet->params.box.z));
46 f32 xRadius = m_scale.x *
static_cast<f32
>(parse<s16>(collisionSet->params.box.x));
48 return std::max(xRadius, zRadius);
52void ObjectCollidable::loadAABB(f32 maxSpeed) {
53 loadAABB(getCollisionRadius(), maxSpeed);
57void ObjectCollidable::loadAABB(f32 radius, f32 maxSpeed) {
58 auto *boxColMgr = BoxColManager::Instance();
60 bool alwaysRecalc = loadFlags() & 0x5;
61 m_boxColUnit = boxColMgr->insertObject(radius, maxSpeed, &pos, alwaysRecalc,
this);
66 Kart::Reaction &reactionOnKart, Kart::Reaction &reactionOnObj) {
68 if (kartObj->speedRatioCapped() < 0.5f) {
69 if (reactionOnKart == Kart::Reaction::SpinSomeSpeed) {
70 reactionOnKart = Kart::Reaction::WallAllSpeed;
71 }
else if (reactionOnKart == Kart::Reaction::SpinHitSomeSpeed) {
72 reactionOnKart = Kart::Reaction::None;
75 if (reactionOnKart == Kart::Reaction::SpinHitSomeSpeed) {
76 reactionOnKart = Kart::Reaction::SpinSomeSpeed;
81 if (reactionOnObj == Kart::Reaction::UNK_3 || reactionOnObj == Kart::Reaction::UNK_4) {
82 reactionOnObj = Kart::Reaction::None;
87bool ObjectCollidable::checkCollision(ObjectCollisionBase *lhs,
EGG::Vector3f &dist) {
88 return lhs->check(*collision(), dist);
92void ObjectCollidable::createCollision() {
93 const auto &flowTable = ObjectDirector::Instance()->flowTable();
94 const auto *collisionSet = flowTable.set(flowTable.slot(m_id));
97 PANIC(
"Invalid object ID when creating primitive collision! ID: %d",
98 static_cast<size_t>(m_id));
101 switch (
static_cast<CollisionMode>(parse<s16>(collisionSet->mode))) {
102 case CollisionMode::Sphere:
103 m_collision =
new ObjectCollisionSphere(parse<s16>(collisionSet->params.sphere.radius),
106 case CollisionMode::Cylinder:
107 m_collision =
new ObjectCollisionCylinder(parse<s16>(collisionSet->params.cylinder.radius),
108 parse<s16>(collisionSet->params.cylinder.height), collisionCenter());
110 case CollisionMode::Box:
111 m_collision =
new ObjectCollisionBox(parse<s16>(collisionSet->params.box.x),
112 parse<s16>(collisionSet->params.box.y), parse<s16>(collisionSet->params.box.z),
116 PANIC(
"Invalid collision mode when creating primitive collision! ID: %d; Mode: %d",
117 static_cast<size_t>(m_id), parse<s16>(collisionSet->mode));
The highest level abstraction for a kart.
CollisionMode
Maps to SObjectCollisionSet::mode. Determines what type of collision an object has.