A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectWLWallGC.cc
1#include "ObjectWLWallGC.hh"
2
3#include "game/system/RaceManager.hh"
4
5namespace Field {
6
8ObjectWLWallGC::ObjectWLWallGC(const System::MapdataGeoObj &params) : ObjectKCL(params) {
9 m_extendedDuration = params.setting(1);
10 m_startFrame = params.setting(4);
11 u32 rate = params.setting(2);
12 u16 distance = params.setting(3);
13
14 if (rate == 0) {
15 m_moveDuration = -1;
16 m_hiddenDuration = -1;
17 m_extendedFrame = -1;
18 m_retractingFrame = -1;
19 m_cycleDuration = -1;
20 } else {
21 m_moveDuration = distance / rate;
22 m_hiddenDuration = params.setting(0);
23 m_extendedFrame = m_hiddenDuration + m_moveDuration;
24 m_retractingFrame = m_extendedFrame + m_extendedDuration;
25 m_cycleDuration = m_retractingFrame + m_moveDuration;
26 }
27
28 m_initialPos = m_pos;
29
30 calcTransform();
31
32 m_targetPos = m_initialPos - m_transform.base(2) * static_cast<f32>(distance);
33
34 calcTransform();
35 m_currTransform = m_transform;
36}
37
39ObjectWLWallGC::~ObjectWLWallGC() = default;
40
42void ObjectWLWallGC::init() {
43 m_flags |= 1;
44 m_pos = m_initialPos;
45
46 calcTransform();
47 m_currTransform = m_transform;
48}
49
51void ObjectWLWallGC::calc() {
52 EGG::Vector3f prevPos = m_pos;
53
54 m_flags |= 4;
55 m_transform = getUpdatedMatrix(0);
56 m_pos = m_transform.base(3);
57
58 setMovingObjVel(m_pos - prevPos);
59}
60
62const EGG::Matrix34f &ObjectWLWallGC::getUpdatedMatrix(u32 timeOffset) {
63 s32 time = cycleFrame(System::RaceManager::Instance()->timer() - timeOffset);
64
65 f32 t;
66 if (time < m_hiddenDuration) {
67 t = 0.0f;
68 } else if (time < m_extendedFrame) {
69 t = static_cast<f32>(time - m_hiddenDuration) / static_cast<f32>(m_moveDuration);
70 } else if (time < m_retractingFrame) {
71 t = 1.0f;
72 } else {
73 t = 1.0f - static_cast<f32>(time - m_retractingFrame) / static_cast<f32>(m_moveDuration);
74 }
75
76 m_currTransform.setBase(3, Interpolate(t, m_initialPos, m_targetPos));
77
78 return m_currTransform;
79}
80
82bool ObjectWLWallGC::checkCollision(f32 radius, const EGG::Vector3f &pos,
83 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
84 u32 timeOffset) {
85 update(timeOffset);
86 calcScale(timeOffset);
87
88 return m_objColMgr->checkSphereFullPush(radius, pos, prevPos, mask, info, maskOut);
89}
90
92bool ObjectWLWallGC::checkCollisionCached(f32 radius, const EGG::Vector3f &pos,
93 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut,
94 u32 timeOffset) {
95 update(timeOffset);
96 calcScale(timeOffset);
97
98 return m_objColMgr->checkSphereCachedFullPush(radius, pos, prevPos, mask, info, maskOut);
99}
100
101} // namespace Field
A 3 x 4 matrix.
Definition Matrix.hh:8
Pertains to collision.
A 3D float vector.
Definition Vector.hh:83