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
16ObjectSandcone::~ObjectSandcone() = default;
17
19void ObjectSandcone::init() {
20 m_duration = m_finalHeightDelta / m_flowRate;
21 m_currentMtx = m_baseMtx;
22
23 // Moved from getUpdatedMatrix to init b/c this only needs to be computed once per object.
24 m_finalPos = pos() + EGG::Vector3f::ey * (static_cast<f32>(m_duration) * m_flowRate);
25}
26
28const EGG::Matrix34f &ObjectSandcone::getUpdatedMatrix(u32 timeOffset) {
29 m_currentMtx = m_baseMtx;
30
31 u32 t = System::RaceManager::Instance()->timer() - timeOffset;
32
33 if (t > m_startFrame + m_duration) {
34 // The sandcone has finished "flowing", so just return the final position.
35 // For Kinoko, we introduce a slight performance improvement by caching the m_finalPos.
36 m_currentMtx.setBase(3, m_finalPos);
37 } else if (t > m_startFrame) {
38 EGG::Vector3f deltaPos = EGG::Vector3f::ey * ((t - m_startFrame) * m_flowRate);
39 m_currentMtx.setBase(3, m_baseMtx.base(3) + deltaPos);
40 }
41
42 return m_currentMtx;
43}
44
46bool ObjectSandcone::checkCollision(f32 radius, const EGG::Vector3f &pos,
47 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
48 u32 timeOffset) {
49 update(timeOffset);
50 calcScale(timeOffset);
51
52 return m_objColMgr->checkSphereFullPush(radius, pos, prevPos, mask, info, maskOut);
53}
54
56bool ObjectSandcone::checkCollisionCached(f32 radius, const EGG::Vector3f &pos,
57 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
58 u32 timeOffset) {
59 update(timeOffset);
60 calcScale(timeOffset);
61
62 return m_objColMgr->checkSphereCachedFullPush(radius, pos, prevPos, mask, info, maskOut);
63}
64
65} // namespace Kinoko::Field
Pertains to collision.