A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartCollide.hh
1#pragma once
2
3#include "game/kart/CollisionGroup.hh"
4#include "game/kart/KartAction.hh"
5#include "game/kart/KartObjectProxy.hh"
6#include "game/kart/KartPullPath.hh"
7
8#include "game/field/CourseColMgr.hh"
9
10#include <egg/core/BitFlag.hh>
11
12namespace Kart {
13
14enum class Reaction {
15 None = 0,
16 UNK_3 = 3,
17 UNK_4 = 4,
18 UNK_5 = 5,
19 UNK_7 = 7,
20 WallAllSpeed = 8,
21 SpinAllSpeed = 9,
22 SpinSomeSpeed = 10,
23 FireSpin = 11,
24 ClipThroughSomeSpeed = 12,
25 SmallLaunch = 13,
26 KnockbackSomeSpeedLoseItem = 14,
27 LaunchSpinLoseItem = 15,
28 KnockbackBumpLoseItem = 16,
29 LongCrushLoseItem = 17,
30 SmallBump = 18,
31 BigBump = 19,
32 SpinShrink = 20,
33 HighLaunchLoseItem = 21,
34 SpinHitSomeSpeed = 22,
35 WeakWall = 23,
36 Wall = 24,
37 LaunchSpin = 25,
38 WallSpark = 26,
39 RubberWall = 27,
40 Wall2 = 28,
41 UntrickableJumpPad = 29,
42 ShortCrushLoseItem = 30,
43 CrushRespawn = 31,
44 ExplosionLoseItem = 32,
45};
46
50public:
51 enum class eSurfaceFlags {
52 Wall = 0,
53 SolidOOB = 1,
54 ObjectWall = 2,
55 ObjectWall3 = 3,
56 BoostRamp = 4,
57 Offroad = 6,
58 GroundBoostPanelOrRamp = 7,
59 Trickable = 11,
60 NotTrickable = 12,
61 StopHalfPipeState = 16,
62 };
63 typedef EGG::TBitFlag<u32, eSurfaceFlags> SurfaceFlags;
64
67
68 void init();
69 void resetHitboxes();
70
71 void calcHitboxes();
72
73 void findCollision();
74 void FUN_80572F4C();
75 void FUN_805B72B8(f32 param_1, f32 param_2, bool lockXZ, bool addExtVelY);
76 void calcBodyCollision(f32 totalScale, f32 sinkDepth, const EGG::Quatf &rot,
77 const EGG::Vector3f &scale);
78 void calcFloorEffect();
79 void calcTriggers(Field::KCLTypeMask *mask, const EGG::Vector3f &pos, bool twoPoint);
80 void handleTriggers(Field::KCLTypeMask *mask);
81 void calcFallBoundary(Field::KCLTypeMask *mask, bool shortBoundary);
82 void calcBeforeRespawn();
83 void activateOob(bool detachCamera, Field::KCLTypeMask *mask, bool somethingCPU,
84 bool somethingBullet);
85 void calcWheelCollision(u16 wheelIdx, CollisionGroup *hitboxGroup, const EGG::Vector3f &colVel,
86 const EGG::Vector3f &center, f32 radius);
87 void calcSideCollision(CollisionData &collisionData, Hitbox &hitbox,
88 Field::CollisionInfo *colInfo);
89 void calcBoundingRadius();
90 void calcObjectCollision();
91 void calcPoleTimer();
92
93 void processWheel(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo,
94 Field::KCLTypeMask *maskOut);
95 void processBody(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo,
96 Field::KCLTypeMask *maskOut);
97 void processMovingWater(CollisionData &collisionData, Field::KCLTypeMask *maskOut);
98 [[nodiscard]] bool processWall(CollisionData &collisionData, Field::KCLTypeMask *maskOut);
99 void processFloor(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo,
100 Field::KCLTypeMask *maskOut, bool wheel);
101 void processCannon(Field::KCLTypeMask *maskOut);
102
103 void applySomeFloorMoment(f32 down, f32 rate, CollisionGroup *hitboxGroup,
104 const EGG::Vector3f &forward, const EGG::Vector3f &nextDir, const EGG::Vector3f &speed,
105 bool b1, bool b2, bool b3);
106
107 [[nodiscard]] bool FUN_805B6A9C(CollisionData &collisionData, const Hitbox &hitbox,
108 EGG::BoundBox3f &minMax, EGG::Vector3f &relPos, s32 &count,
109 const Field::KCLTypeMask &maskOut, const Field::CollisionInfo &colInfo);
110 void applyBodyCollision(CollisionData &collisionData, const EGG::Vector3f &movement,
111 const EGG::Vector3f &posRel, s32 count);
112
113 void startFloorMomentRate();
114 void calcFloorMomentRate();
115
117 Action handleReactNone(size_t idx);
118 Action handleReactWallAllSpeed(size_t idx);
119 Action handleReactSpinAllSpeed(size_t idx);
120 Action handleReactSpinSomeSpeed(size_t idx);
121 Action handleReactFireSpin(size_t idx);
122 Action handleReactSmallLaunch(size_t idx);
123 Action handleReactKnockbackSomeSpeedLoseItem(size_t idx);
124 Action handleReactLaunchSpinLoseItem(size_t idx);
125 Action handleReactKnockbackBumpLoseItem(size_t idx);
126 Action handleReactLongCrushLoseItem(size_t idx);
127 Action handleReactSmallBump(size_t idx);
128 Action handleReactSpinShrink(size_t idx);
129 Action handleReactHighLaunchLoseItem(size_t idx);
130 Action handleReactWeakWall(size_t idx);
131 Action handleReactOffroad(size_t idx);
132 Action handleReactLaunchSpin(size_t idx);
133 Action handleReactWallSpark(size_t idx);
134 Action handleReactRubberWall(size_t idx);
135 Action handleReactUntrickableJumpPad(size_t idx);
136 Action handleReactShortCrushLoseItem(size_t idx);
137 Action handleReactCrushRespawn(size_t idx);
138 Action handleReactExplosionLoseItem(size_t idx);
139
142 void setFloorColInfo(CollisionData &collisionData, const EGG::Vector3f &relPos,
143 const EGG::Vector3f &vel, const EGG::Vector3f &floorNrm) {
144 collisionData.relPos = relPos;
145 collisionData.vel = vel;
146 collisionData.floorNrm = floorNrm;
147 collisionData.bFloor = true;
148 }
149
150 void setTangentOff(const EGG::Vector3f &v) {
151 m_tangentOff = v;
152 }
153 void setMovement(const EGG::Vector3f &v) {
154 m_movement = v;
155 }
157
159 [[nodiscard]] KartPullPath &pullPath() {
160 return m_pullPath;
161 }
162
163 [[nodiscard]] const KartPullPath &pullPath() const {
164 return m_pullPath;
165 }
166
167 [[nodiscard]] f32 boundingRadius() const {
168 return m_boundingRadius;
169 }
170
171 [[nodiscard]] f32 floorMomentRate() const {
172 return m_floorMomentRate;
173 }
174
175 [[nodiscard]] const SurfaceFlags &surfaceFlags() const {
176 return m_surfaceFlags;
177 }
178
179 [[nodiscard]] const EGG::Vector3f &tangentOff() const {
180 return m_tangentOff;
181 }
182
183 [[nodiscard]] const EGG::Vector3f &movement() const {
184 return m_movement;
185 }
186
187 [[nodiscard]] f32 suspBottomHeightSoftWall() const {
188 return m_suspBottomHeightSoftWall;
189 }
190
191 [[nodiscard]] u16 someSoftWallTimer() const {
192 return m_someSoftWallTimer;
193 }
194
195 [[nodiscard]] f32 suspBottomHeightNonSoftWall() const {
196 return m_suspBottomHeightNonSoftWall;
197 }
198
199 [[nodiscard]] u16 someNonSoftWallTimer() const {
200 return m_someNonSoftWallTimer;
201 }
202
203 [[nodiscard]] f32 colPerpendicularity() const {
204 return m_colPerpendicularity;
205 }
207
208private:
209 typedef Action (KartCollide::*ObjectCollisionHandler)(size_t idx);
210
211 KartPullPath m_pullPath;
212 f32 m_boundingRadius;
213 f32 m_floorMomentRate;
214 EGG::Vector3f m_totalReactionWallNrm;
215 SurfaceFlags m_surfaceFlags;
216 EGG::Vector3f m_tangentOff;
217 EGG::Vector3f m_movement;
218 s16 m_respawnTimer;
219 s16 m_solidOobTimer;
220 s16 m_shrinkTimer;
221 f32 m_smoothedBack; // 0x50
222 f32 m_suspBottomHeightSoftWall;
223 u16 m_someSoftWallTimer;
224 f32 m_suspBottomHeightNonSoftWall;
225 u16 m_someNonSoftWallTimer;
226 s16 m_poleAngVelTimer;
227 f32 m_poleYaw;
228 f32 m_colPerpendicularity;
229
230 static std::array<ObjectCollisionHandler, 33> s_objectCollisionHandlers;
231};
232
233} // namespace Kart
Houses hitbox and collision info for an object (body or wheel).
Represents a hitbox for the kart body or a wheel.
Manages body+wheel collision and its influence on position/velocity/etc.
void applyBodyCollision(CollisionData &collisionData, const EGG::Vector3f &movement, const EGG::Vector3f &posRel, s32 count)
Saves collision info when vehicle body collision occurs.
void calcWheelCollision(u16 wheelIdx, CollisionGroup *hitboxGroup, const EGG::Vector3f &colVel, const EGG::Vector3f &center, f32 radius)
Checks wheel hitbox collision and stores position/velocity info.
void applySomeFloorMoment(f32 down, f32 rate, CollisionGroup *hitboxGroup, const EGG::Vector3f &forward, const EGG::Vector3f &nextDir, const EGG::Vector3f &speed, bool b1, bool b2, bool b3)
Applies external and angular velocity based on the collision with the floor.
void processCannon(Field::KCLTypeMask *maskOut)
Checks if we are colliding with a cannon trigger and sets the state flag if so.
Action handleReactNone(size_t idx)
Object collision functions.
bool FUN_805B6A9C(CollisionData &collisionData, const Hitbox &hitbox, EGG::BoundBox3f &minMax, EGG::Vector3f &relPos, s32 &count, const Field::KCLTypeMask &maskOut, const Field::CollisionInfo &colInfo)
Called on collision of a new KCL type??? This only happens after airtime so far.
void processWheel(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo, Field::KCLTypeMask *maskOut)
Processes moving water and floor collision effects.
void calcHitboxes()
On each frame, calculates the positions for each hitbox.
void calcSideCollision(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo)
void processFloor(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo, Field::KCLTypeMask *maskOut, bool wheel)
Processes the floor triangles' attributes.
void FUN_805B72B8(f32 param_1, f32 param_2, bool lockXZ, bool addExtVelY)
Affects velocity when landing from airtime.
void calcBodyCollision(f32 totalScale, f32 sinkDepth, const EGG::Quatf &rot, const EGG::Vector3f &scale)
Checks and acts on collision for each kart hitbox.
Base class for most kart-related objects.
Pertains to kart-related functionality.
A representation of a bounding cuboid.
Definition BoundBox.hh:30
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
Wrapper around an integral type with an enum corresponding to its bits.
Definition BitFlag.hh:21
A 3D float vector.
Definition Vector.hh:88
Information about the current collision and its properties.
bool bFloor
Set if colliding with KCL which satisfies KCL_TYPE_FLOOR.