3#include "game/system/RaceManager.hh"
4#include "game/system/ResourceManager.hh"
6#include <egg/math/Math.hh>
12 : ObjectDrivable(params), m_lastMtxUpdateFrame(-2000), m_lastScaleUpdateFrame(-2000) {}
15ObjectKCL::~ObjectKCL() {
20void ObjectKCL::createCollision() {
22 snprintf(filepath,
sizeof(filepath),
"%s.kcl", getKclName());
24 auto *resMgr = System::ResourceManager::Instance();
25 m_objColMgr =
new ObjColMgr(resMgr->getFile(filepath,
nullptr, System::ArchiveId::Course));
29void ObjectKCL::calcCollisionTransform() {
34void ObjectKCL::initCollision() {
40 m_objColMgr->setMtx(mat);
41 m_objColMgr->setInvMtx(matInv);
42 m_objColMgr->setScale(getScaleY(0));
47 m_kclMidpoint = (high + low).multInv(2.0f);
50 f32 maxDiff = std::max(highLowDiffAbs.x, highLowDiffAbs.z);
51 m_bboxHalfSideLength = maxDiff * 0.5f;
56 KCLTypeMask mask, CollisionInfoPartial *info, KCLTypeMask *maskOut) {
57 if (!shouldCheckColNoPush()) {
61 return m_objColMgr->checkPointPartial(pos, prevPos, mask, info, maskOut);
66 KCLTypeMask mask, CollisionInfoPartial *info, KCLTypeMask *maskOut) {
67 if (!shouldCheckColPush()) {
71 return m_objColMgr->checkPointPartialPush(pos, prevPos, mask, info, maskOut);
76 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut) {
77 if (!shouldCheckColNoPush()) {
81 return m_objColMgr->checkPointFull(pos, prevPos, mask, info, maskOut);
86 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut) {
87 if (!shouldCheckColPush()) {
91 return m_objColMgr->checkPointFullPush(pos, prevPos, mask, info, maskOut);
95bool ObjectKCL::checkSpherePartial(f32 radius,
const EGG::Vector3f &pos,
96 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
97 KCLTypeMask *maskOut, u32 timeOffset) {
98 if (!shouldCheckColNoPush()) {
102 calcScale(timeOffset);
105 return m_objColMgr->checkSpherePartial(radius, pos, prevPos, mask, info, maskOut);
109bool ObjectKCL::checkSpherePartialPush(f32 radius,
const EGG::Vector3f &pos,
110 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
111 KCLTypeMask *maskOut, u32 timeOffset) {
112 if (!shouldCheckColPush()) {
116 calcScale(timeOffset);
119 return m_objColMgr->checkSpherePartialPush(radius, pos, prevPos, mask, info, maskOut);
124 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut, u32 timeOffset) {
125 if (!shouldCheckColNoPush()) {
129 calcScale(timeOffset);
132 return m_objColMgr->checkSphereFull(radius, pos, prevPos, mask, info, maskOut);
136bool ObjectKCL::checkSphereFullPush(f32 radius,
const EGG::Vector3f &pos,
137 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
139 return checkCollision(radius, pos, prevPos, mask, info, maskOut, timeOffset);
143void ObjectKCL::narrScLocal(f32 radius,
const EGG::Vector3f &pos, KCLTypeMask mask,
145 m_objColMgr->narrScLocal(radius, pos, mask);
150 KCLTypeMask mask, CollisionInfoPartial *info, KCLTypeMask *maskOut) {
151 if (!shouldCheckColNoPush()) {
155 return m_objColMgr->checkPointCachedPartial(pos, prevPos, mask, info, maskOut);
160 KCLTypeMask mask, CollisionInfoPartial *info, KCLTypeMask *maskOut) {
161 if (!shouldCheckColPush()) {
165 return m_objColMgr->checkPointCachedPartialPush(pos, prevPos, mask, info, maskOut);
170 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut) {
171 if (!shouldCheckColNoPush()) {
175 return m_objColMgr->checkPointCachedFull(pos, prevPos, mask, info, maskOut);
180 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut) {
181 if (!shouldCheckColPush()) {
185 return m_objColMgr->checkPointCachedFullPush(pos, prevPos, mask, info, maskOut);
189bool ObjectKCL::checkSphereCachedPartial(f32 radius,
const EGG::Vector3f &pos,
190 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
191 KCLTypeMask *maskOut, u32 timeOffset) {
192 if (!shouldCheckColNoPush()) {
197 calcScale(timeOffset);
199 return m_objColMgr->checkSphereCachedPartial(radius, pos, prevPos, mask, info, maskOut);
203bool ObjectKCL::checkSphereCachedPartialPush(f32 radius,
const EGG::Vector3f &pos,
204 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
205 KCLTypeMask *maskOut, u32 timeOffset) {
206 if (!shouldCheckColPush()) {
211 calcScale(timeOffset);
213 return m_objColMgr->checkSphereCachedPartialPush(radius, pos, prevPos, mask, info, maskOut);
217bool ObjectKCL::checkSphereCachedFull(f32 radius,
const EGG::Vector3f &pos,
218 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
220 if (!shouldCheckColNoPush()) {
225 calcScale(timeOffset);
227 return m_objColMgr->checkSphereCachedFull(radius, pos, prevPos, mask, info, maskOut);
231bool ObjectKCL::checkSphereCachedFullPush(f32 radius,
const EGG::Vector3f &pos,
232 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
234 return checkCollisionCached(radius, pos, prevPos, mask, info, maskOut, timeOffset);
238void ObjectKCL::update(u32 timeOffset) {
239 u32 time = System::RaceManager::Instance()->timer() - timeOffset;
240 if (m_lastMtxUpdateFrame ==
static_cast<s32
>(time)) {
246 if (timeOffset == 0) {
250 mat = getUpdatedMatrix(timeOffset);
255 m_objColMgr->setMtx(mat);
256 m_objColMgr->setInvMtx(matInv);
258 m_lastMtxUpdateFrame = time;
262void ObjectKCL::calcScale(u32 timeOffset) {
263 u32 time = System::RaceManager::Instance()->timer() - timeOffset;
264 if (m_lastScaleUpdateFrame ==
static_cast<s32
>(time)) {
269 m_objColMgr->setScale(m_scale.y);
271 m_objColMgr->setScale(getScaleY(timeOffset));
274 m_lastScaleUpdateFrame = time;
285 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut, u32 timeOffset) {
286 if (!shouldCheckColPush()) {
291 calcScale(timeOffset);
293 return m_objColMgr->checkSphereFullPush(radius, pos, prevPos, mask, info, maskOut);
297bool ObjectKCL::checkCollisionCached(f32 radius,
const EGG::Vector3f &pos,
298 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
300 if (!shouldCheckColPush()) {
305 calcScale(timeOffset);
307 return m_objColMgr->checkSphereCachedFullPush(radius, pos, prevPos, mask, info, maskOut);
bool ps_inverse(Matrix34f &out) const