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
7#include "game/field/CourseColMgr.hh"
8
9#include <egg/core/BitFlag.hh>
10
11namespace Kart {
12
13enum class Reaction {
14 None = 0,
15 UNK_3 = 3,
16 UNK_4 = 4,
17 UNK_5 = 5,
18 UNK_7 = 7,
19 WallAllSpeed = 8,
20 SpinAllSpeed = 9,
21 SpinSomeSpeed = 10,
22 FireSpin = 11,
23 ClipThroughSomeSpeed = 12,
24 SmallLaunch = 13,
25 KnockbackSomeSpeedLoseItem = 14,
26 LaunchSpinLoseItem = 15,
27 KnockbackBumpLoseItem = 16,
28 LongCrushLoseItem = 17,
29 SmallBump = 18,
30 BigBump = 19,
31 SpinShrink = 20,
32 HighLaunchLoseItem = 21,
33 SpinHitSomeSpeed = 22,
34 WeakWall = 23,
35 Wall = 24,
36 LaunchSpin = 25,
37 WallSpark = 26,
38 RubberWall = 27,
39 Wall2 = 28,
40 UntrickableJumpPad = 29,
41 ShortCrushLoseItem = 30,
42 CrushRespawn = 31,
43 ExplosionLoseItem = 32,
44};
45
49public:
50 enum class eSurfaceFlags {
51 Wall = 0,
52 SolidOOB = 1,
53 ObjectWall = 2,
54 ObjectWall3 = 3,
55 BoostRamp = 4,
56 Offroad = 6,
57 GroundBoostPanelOrRamp = 7,
58 Trickable = 11,
59 NotTrickable = 12,
60 StopHalfPipeState = 16,
61 };
62 typedef EGG::TBitFlag<u32, eSurfaceFlags> SurfaceFlags;
63
66
67 void init();
68 void resetHitboxes();
69
70 void calcHitboxes();
71
72 void findCollision();
73 void FUN_80572F4C();
74 void FUN_805B72B8(f32 param_1, f32 param_2, bool lockXZ, bool addExtVelY);
75 void calcBodyCollision(f32 totalScale, f32 sinkDepth, const EGG::Quatf &rot,
76 const EGG::Vector3f &scale);
77 void calcFloorEffect();
78 void calcTriggers(Field::KCLTypeMask *mask, const EGG::Vector3f &pos, bool twoPoint);
79 void handleTriggers(Field::KCLTypeMask *mask);
80 void calcFallBoundary(Field::KCLTypeMask *mask, bool shortBoundary);
81 void calcBeforeRespawn();
82 void activateOob(bool detachCamera, Field::KCLTypeMask *mask, bool somethingCPU,
83 bool somethingBullet);
84 void calcWheelCollision(u16 wheelIdx, CollisionGroup *hitboxGroup, const EGG::Vector3f &colVel,
85 const EGG::Vector3f &center, f32 radius);
86 void calcSideCollision(CollisionData &collisionData, Hitbox &hitbox,
87 Field::CollisionInfo *colInfo);
88 void calcBoundingRadius();
89 void calcObjectCollision();
90 void calcPoleTimer();
91
92 void processWheel(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo,
93 Field::KCLTypeMask *maskOut);
94 void processBody(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo,
95 Field::KCLTypeMask *maskOut);
96 [[nodiscard]] bool processWall(CollisionData &collisionData, Field::KCLTypeMask *maskOut);
97 void processFloor(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo,
98 Field::KCLTypeMask *maskOut, bool wheel);
99 void processCannon(Field::KCLTypeMask *maskOut);
100
101 void applySomeFloorMoment(f32 down, f32 rate, CollisionGroup *hitboxGroup,
102 const EGG::Vector3f &forward, const EGG::Vector3f &nextDir, const EGG::Vector3f &speed,
103 bool b1, bool b2, bool b3);
104
105 [[nodiscard]] bool FUN_805B6A9C(CollisionData &collisionData, const Hitbox &hitbox,
106 EGG::BoundBox3f &minMax, EGG::Vector3f &relPos, s32 &count,
107 const Field::KCLTypeMask &maskOut, const Field::CollisionInfo &colInfo);
108 void applyBodyCollision(CollisionData &collisionData, const EGG::Vector3f &movement,
109 const EGG::Vector3f &posRel, s32 count);
110
111 void startFloorMomentRate();
112 void calcFloorMomentRate();
113
115 Action handleReactNone(size_t idx);
116 Action handleReactWallAllSpeed(size_t idx);
117 Action handleReactSpinAllSpeed(size_t idx);
118 Action handleReactSpinSomeSpeed(size_t idx);
119 Action handleReactFireSpin(size_t idx);
120 Action handleReactSmallLaunch(size_t idx);
121 Action handleReactKnockbackSomeSpeedLoseItem(size_t idx);
122 Action handleReactLaunchSpinLoseItem(size_t idx);
123 Action handleReactKnockbackBumpLoseItem(size_t idx);
124 Action handleReactLongCrushLoseItem(size_t idx);
125 Action handleReactSmallBump(size_t idx);
126 Action handleReactHighLaunchLoseItem(size_t idx);
127 Action handleReactWeakWall(size_t idx);
128 Action handleReactOffroad(size_t idx);
129 Action handleReactLaunchSpin(size_t idx);
130 Action handleReactWallSpark(size_t idx);
131 Action handleReactUntrickableJumpPad(size_t idx);
132 Action handleReactShortCrushLoseItem(size_t idx);
133 Action handleReactCrushRespawn(size_t idx);
134 Action handleReactExplosionLoseItem(size_t idx);
135
138 void setFloorColInfo(CollisionData &collisionData, const EGG::Vector3f &relPos,
139 const EGG::Vector3f &vel, const EGG::Vector3f &floorNrm) {
140 collisionData.relPos = relPos;
141 collisionData.vel = vel;
142 collisionData.floorNrm = floorNrm;
143 collisionData.bFloor = true;
144 }
145
146 void setTangentOff(const EGG::Vector3f &v) {
147 m_tangentOff = v;
148 }
149 void setMovement(const EGG::Vector3f &v) {
150 m_movement = v;
151 }
153
155 [[nodiscard]] f32 boundingRadius() const {
156 return m_boundingRadius;
157 }
158
159 [[nodiscard]] f32 floorMomentRate() const {
160 return m_floorMomentRate;
161 }
162
163 [[nodiscard]] const SurfaceFlags &surfaceFlags() const {
164 return m_surfaceFlags;
165 }
166
167 [[nodiscard]] const EGG::Vector3f &tangentOff() const {
168 return m_tangentOff;
169 }
170
171 [[nodiscard]] const EGG::Vector3f &movement() const {
172 return m_movement;
173 }
174
175 [[nodiscard]] f32 suspBottomHeightSoftWall() const {
176 return m_suspBottomHeightSoftWall;
177 }
178
179 [[nodiscard]] u16 someSoftWallTimer() const {
180 return m_someSoftWallTimer;
181 }
182
183 [[nodiscard]] f32 suspBottomHeightNonSoftWall() const {
184 return m_suspBottomHeightNonSoftWall;
185 }
186
187 [[nodiscard]] u16 someNonSoftWallTimer() const {
188 return m_someNonSoftWallTimer;
189 }
190
191 [[nodiscard]] f32 colPerpendicularity() const {
192 return m_colPerpendicularity;
193 }
195
196private:
197 typedef Action (KartCollide::*ObjectCollisionHandler)(size_t idx);
198
199 f32 m_boundingRadius;
200 f32 m_floorMomentRate;
201 EGG::Vector3f m_totalReactionWallNrm;
202 SurfaceFlags m_surfaceFlags;
203 EGG::Vector3f m_tangentOff;
204 EGG::Vector3f m_movement;
205 s16 m_respawnTimer;
206 s16 m_solidOobTimer;
207 f32 m_smoothedBack; // 0x50
208 f32 m_suspBottomHeightSoftWall;
209 u16 m_someSoftWallTimer;
210 f32 m_suspBottomHeightNonSoftWall;
211 u16 m_someNonSoftWallTimer;
212 s16 m_poleAngVelTimer;
213 f32 m_poleYaw;
214 f32 m_colPerpendicularity;
215
216 static std::array<ObjectCollisionHandler, 33> s_objectCollisionHandlers;
217};
218
219} // 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:16
A 3D float vector.
Definition Vector.hh:87
Information about the current collision and its properties.
bool bFloor
Set if colliding with KCL which satisfies KCL_TYPE_FLOOR.