A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectEscalator.hh
1#pragma once
2
3#include "game/field/obj/ObjectKCL.hh"
4
5namespace Field {
6
15class ObjectEscalator final : public ObjectKCL {
16 friend class ObjectEscalatorGroup;
17
18public:
19 ObjectEscalator(const System::MapdataGeoObj &params, bool reverse = false);
20 ~ObjectEscalator() override;
21
22 void calc() override;
23
25 [[nodiscard]] ObjectId id() const override {
26 return ObjectId::Escalator;
27 }
28
30 [[nodiscard]] u32 loadFlags() const override {
31 return 1;
32 }
33
34 [[nodiscard]] bool checkPointPartial(const EGG::Vector3f &pos, const EGG::Vector3f &prevPos,
35 KCLTypeMask mask, CollisionInfoPartial *info, KCLTypeMask *maskOut) override;
36 [[nodiscard]] bool checkPointPartialPush(const EGG::Vector3f &pos, const EGG::Vector3f &prevPos,
37 KCLTypeMask mask, CollisionInfoPartial *info, KCLTypeMask *maskOut) override;
38 [[nodiscard]] bool checkPointFull(const EGG::Vector3f &pos, const EGG::Vector3f &prevPos,
39 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut) override;
40 [[nodiscard]] bool checkPointFullPush(const EGG::Vector3f &pos, const EGG::Vector3f &prevPos,
41 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut) override;
42 [[nodiscard]] bool checkSpherePartial(f32 radius, const EGG::Vector3f &pos,
43 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
44 KCLTypeMask *maskOut, u32 timeOffset) override;
45 [[nodiscard]] bool checkSpherePartialPush(f32 radius, const EGG::Vector3f &pos,
46 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
47 KCLTypeMask *maskOut, u32 timeOffset) override;
48 [[nodiscard]] bool checkSphereFull(f32 radius, const EGG::Vector3f &pos,
49 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info,
50 KCLTypeMask *maskOut, u32 timeOffset) override;
51 [[nodiscard]] bool checkSphereFullPush(f32 radius, const EGG::Vector3f &pos,
52 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info,
53 KCLTypeMask *maskOut, u32 timeOffset) override;
54 void narrScLocal(f32 radius, const EGG::Vector3f &pos, KCLTypeMask mask,
55 u32 timeOffset) override;
56 [[nodiscard]] bool checkPointCachedPartial(const EGG::Vector3f &pos,
57 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
58 KCLTypeMask *maskOut) override;
59 [[nodiscard]] bool checkPointCachedPartialPush(const EGG::Vector3f &pos,
60 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
61 KCLTypeMask *maskOut) override;
62 [[nodiscard]] bool checkPointCachedFull(const EGG::Vector3f &pos, const EGG::Vector3f &prevPos,
63 KCLTypeMask mask, CollisionInfo *info, KCLTypeMask *maskOut) override;
64 [[nodiscard]] bool checkPointCachedFullPush(const EGG::Vector3f &pos,
65 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info,
66 KCLTypeMask *maskOut) override;
67 [[nodiscard]] bool checkSphereCachedPartial(f32 radius, const EGG::Vector3f &pos,
68 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
69 KCLTypeMask *maskOut, u32 timeOffset) override;
70 [[nodiscard]] bool checkSphereCachedPartialPush(f32 radius, const EGG::Vector3f &pos,
71 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfoPartial *info,
72 KCLTypeMask *maskOut, u32 timeOffset) override;
73 [[nodiscard]] bool checkSphereCachedFull(f32 radius, const EGG::Vector3f &pos,
74 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info,
75 KCLTypeMask *maskOut, u32 timeOffset) override;
76 [[nodiscard]] bool checkSphereCachedFullPush(f32 radius, const EGG::Vector3f &pos,
77 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info,
78 KCLTypeMask *maskOut, u32 timeOffset) override;
79
80 [[nodiscard]] const EGG::Matrix34f &getUpdatedMatrix(u32 timeOffset) override;
81
83 [[nodiscard]] f32 colRadiusAdditionalLength() const override {
84 return 1000.0f;
85 }
86
87 [[nodiscard]] bool checkCollision(f32 radius, const EGG::Vector3f &pos,
88 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info,
89 KCLTypeMask *maskOut, u32 timeOffset) override;
90 [[nodiscard]] bool checkCollisionCached(f32 radius, const EGG::Vector3f &pos,
91 const EGG::Vector3f &prevPos, KCLTypeMask mask, CollisionInfo *info,
92 KCLTypeMask *maskOut, u32 timeOffset) override;
93
94private:
95 using ShouldCheckFunc = bool (ObjectEscalator::*)() const;
96
97 template <typename T>
98 requires std::is_same_v<T, CollisionInfo> || std::is_same_v<T, CollisionInfoPartial>
99 using CheckPointFunc = bool(ObjColMgr::*)(const EGG::Vector3f &pos,
100 const EGG::Vector3f &prevPos, KCLTypeMask mask, T *info, KCLTypeMask *maskOut);
101
102 template <typename T>
103 requires std::is_same_v<T, CollisionInfo> || std::is_same_v<T, CollisionInfoPartial>
104 using CheckSphereFunc = bool(ObjColMgr::*)(f32 radius, const EGG::Vector3f &pos,
105 const EGG::Vector3f &prevPos, KCLTypeMask mask, T *info, KCLTypeMask *maskOut);
106
107 template <typename T>
108 requires std::is_same_v<T, CollisionInfo> || std::is_same_v<T, CollisionInfoPartial>
109 [[nodiscard]] bool checkPointImpl(ShouldCheckFunc shouldCheckFunc, CheckPointFunc<T> checkFunc,
110 const EGG::Vector3f &pos, const EGG::Vector3f &prevPos, KCLTypeMask mask, T *info,
111 KCLTypeMask *maskOut);
112
113 template <typename T>
114 requires std::is_same_v<T, CollisionInfo> || std::is_same_v<T, CollisionInfoPartial>
115 [[nodiscard]] bool checkSphereImpl(ShouldCheckFunc shouldCheckFunc,
116 CheckSphereFunc<T> checkFunc, f32 radius, const EGG::Vector3f &pos,
117 const EGG::Vector3f &prevPos, KCLTypeMask mask, T *info, KCLTypeMask *maskOut,
118 u32 timeOffset);
119
120 [[nodiscard]] f32 calcStepFactor(s32 t);
121 [[nodiscard]] f32 calcSpeed(s32 t);
122
123 EGG::Vector3f m_initialPos;
124 EGG::Vector3f m_initialRot;
127 EGG::Matrix34f m_workMatrix;
128 const std::array<s32, 2> m_stillFrames;
129 const std::array<f32, 3> m_speed;
132
133 // Helper members that only need to be computed once
134 const std::array<f32, 2> m_stopFrames;
135 const std::array<f32, 2> m_startFrames;
136 const std::array<f32, 2> m_fullSpeedFrames;
137 const f32 m_midDuration;
138
139 static constexpr f32 STEP_HEIGHT = 10.0f;
140
142 static constexpr f32 REVERSE_FRAMES_F32 = 240.0f;
143
145 static constexpr f32 STANDSTILL_FRAMES = 50.0f;
146
147 static constexpr f32 MAX_HEIGHT_OFFSET = STEP_HEIGHT * (17.5f * STEP_HEIGHT);
148 static constexpr f32 MIN_HEIGHT_OFFSET = 0.5f * (17.5f * STEP_HEIGHT);
149};
150
151} // namespace Field
A 3 x 4 matrix.
Definition Matrix.hh:8
Manager for an object's KCL interactions.
Definition ObjColMgr.hh:9
Represents a group of two escalators and the Pianta dancing in the middle.
Represents an individual escalator on Coconut Mall.
static constexpr f32 STEP_HEIGHT
Duration of full speed in between the dir changes.
f32 m_stepFactor
Used so that the steps have a tangible height difference on the escalator.
const std::array< f32, 2 > m_fullSpeedFrames
When escalator reaches max speed.
EGG::Vector3f m_stepDims
Length and height of steps but aligned with its facing direction.
const f32 m_checkColYPosMin
Collision checks early return if you are below this height.
static constexpr f32 REVERSE_FRAMES_F32
Frames the escalator waits before speeding up.
const std::array< f32, 2 > m_stopFrames
When the escalator starts slowing down.
const std::array< s32, 2 > m_stillFrames
When escalators change direction (two times)
const std::array< f32, 3 > m_speed
Velocity for each of the three directions it moves.
const f32 m_checkColYPosMax
Collision checks early return if you are above this height.
const std::array< f32, 2 > m_startFrames
When the escalator starts accelerating.
Pertains to collision.
A 3D float vector.
Definition Vector.hh:88