A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectSandcone.cc
1#include "ObjectSandcone.hh"
2
3#include "game/system/RaceManager.hh"
4
5namespace Kinoko::Field {
6
8ObjectSandcone::ObjectSandcone(const System::MapdataGeoObj &params) : ObjectKCL(params) {
9 m_flowRate = static_cast<f32>(params.setting(0)) / 100.0f;
10 m_finalHeightDelta = static_cast<f32>(params.setting(1));
11 m_startFrame = params.setting(2);
12 m_baseMtx.makeRT(rot(), pos());
13
14 // The base game doesn't initialize this explicitly, since EGG::Heaps are memset to 0.
15 // Upon loading the object, `ObjectSandcone::getUpdatedMatrix()` is called before `m_duration`
16 // was set.
17 m_duration = 0;
18}
19
21ObjectSandcone::~ObjectSandcone() = default;
22
24void ObjectSandcone::init() {
25 m_duration = m_finalHeightDelta / m_flowRate;
26 m_currentMtx = m_baseMtx;
27
28 // Moved from getUpdatedMatrix to init b/c this only needs to be computed once per object.
29 m_finalPos = pos() + EGG::Vector3f::ey * (static_cast<f32>(m_duration) * m_flowRate);
30}
31
33const EGG::Matrix34f &ObjectSandcone::getUpdatedMatrix(u32 timeOffset) {
34 m_currentMtx = m_baseMtx;
35
36 u32 t = System::RaceManager::Instance()->timer() - timeOffset;
37
38 if (t > m_startFrame + m_duration) {
39 // The sandcone has finished "flowing", so just return the final position.
40 // For Kinoko, we introduce a slight performance improvement by caching the m_finalPos.
41 m_currentMtx.setBase(3, m_finalPos);
42 } else if (t > m_startFrame) {
43 EGG::Vector3f deltaPos = EGG::Vector3f::ey * ((t - m_startFrame) * m_flowRate);
44 m_currentMtx.setBase(3, m_baseMtx.base(3) + deltaPos);
45 }
46
47 return m_currentMtx;
48}
49
51bool ObjectSandcone::checkCollision(f32 radius, const EGG::Vector3f &pos,
52 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
53 u32 timeOffset) {
54 update(timeOffset);
55 calcScale(timeOffset);
56
57 return m_objColMgr->checkSphereFullPush(radius, pos, prevPos, mask, info, maskOut);
58}
59
61bool ObjectSandcone::checkCollisionCached(f32 radius, const EGG::Vector3f &pos,
62 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
63 u32 timeOffset) {
64 update(timeOffset);
65 calcScale(timeOffset);
66
67 return m_objColMgr->checkSphereCachedFullPush(radius, pos, prevPos, mask, info, maskOut);
68}
69
70} // namespace Kinoko::Field
Pertains to collision.