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 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(m_rot, m_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 = m_pos + EGG::Vector3f::ey * (static_cast<f32>(m_duration) * m_flowRate);
25}
26
28void ObjectSandcone::calc() {
29 m_flags.setBit(eFlags::Matrix);
30 m_transform = getUpdatedMatrix(0);
31 m_pos = m_transform.base(3);
32}
33
35const EGG::Matrix34f &ObjectSandcone::getUpdatedMatrix(u32 timeOffset) {
36 m_currentMtx = m_baseMtx;
37
38 u32 t = System::RaceManager::Instance()->timer() - timeOffset;
39
40 if (t > m_startFrame + m_duration) {
41 // The sandcone has finished "flowing", so just return the final position.
42 // For Kinoko, we introduce a slight performance improvement by caching the m_finalPos.
43 m_currentMtx.setBase(3, m_finalPos);
44 } else if (t > m_startFrame) {
45 EGG::Vector3f deltaPos = EGG::Vector3f::ey * ((t - m_startFrame) * m_flowRate);
46 m_currentMtx.setBase(3, m_baseMtx.base(3) + deltaPos);
47 }
48
49 return m_currentMtx;
50}
51
53bool ObjectSandcone::checkCollision(f32 radius, const EGG::Vector3f &pos,
54 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
55 u32 timeOffset) {
56 update(timeOffset);
57 calcScale(timeOffset);
58
59 return m_objColMgr->checkSphereFullPush(radius, pos, prevPos, mask, info, maskOut);
60}
61
63bool ObjectSandcone::checkCollisionCached(f32 radius, const EGG::Vector3f &pos,
64 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
65 u32 timeOffset) {
66 update(timeOffset);
67 calcScale(timeOffset);
68
69 return m_objColMgr->checkSphereCachedFullPush(radius, pos, prevPos, mask, info, maskOut);
70}
71
72} // namespace Field
A 3 x 4 matrix.
Definition Matrix.hh:8
Pertains to collision.
A 3D float vector.
Definition Vector.hh:87