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 Kinoko::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
49class KartCollide : KartObjectProxy {
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 findCollision();
72 void FUN_80572F4C();
73 void FUN_805B72B8(f32 param_1, f32 param_2, bool lockXZ, bool addExtVelY);
74 void calcBodyCollision(f32 totalScale, f32 sinkDepth, const EGG::Quatf &rot,
75 const EGG::Vector3f &scale);
76 void calcFloorEffect();
77 void calcTriggers(Field::KCLTypeMask *mask, const EGG::Vector3f &pos, bool twoPoint);
78 void handleTriggers(Field::KCLTypeMask *mask);
79 void calcFallBoundary(Field::KCLTypeMask *mask, bool shortBoundary);
80 void calcBeforeRespawn();
81 void activateOob(bool detachCamera, Field::KCLTypeMask *mask, bool somethingCPU,
82 bool somethingBullet);
83 void calcWheelCollision(u16 wheelIdx, CollisionGroup *hitboxGroup, const EGG::Vector3f &colVel,
84 const EGG::Vector3f &center, f32 radius);
85 void calcSideCollision(CollisionData &collisionData, Hitbox &hitbox,
86 Field::CollisionInfo *colInfo);
87 void calcBoundingRadius();
88 void calcObjectCollision();
89 void calcPoleTimer();
90
91 void processWheel(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo,
92 Field::KCLTypeMask *maskOut);
93 void processBody(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo,
94 Field::KCLTypeMask *maskOut);
95 void processMovingWater(CollisionData &collisionData, 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 handleReactSpinShrink(size_t idx);
127 Action handleReactHighLaunchLoseItem(size_t idx);
128 Action handleReactWeakWall(size_t idx);
129 Action handleReactOffroad(size_t idx);
130 Action handleReactLaunchSpin(size_t idx);
131 Action handleReactWallSpark(size_t idx);
132 Action handleReactRubberWall(size_t idx);
133 Action handleReactUntrickableJumpPad(size_t idx);
134 Action handleReactShortCrushLoseItem(size_t idx);
135 Action handleReactCrushRespawn(size_t idx);
136 Action handleReactExplosionLoseItem(size_t idx);
137
140 void setFloorColInfo(CollisionData &collisionData, const EGG::Vector3f &relPos,
141 const EGG::Vector3f &vel, const EGG::Vector3f &floorNrm) {
142 collisionData.relPos = relPos;
143 collisionData.vel = vel;
144 collisionData.floorNrm = floorNrm;
145 collisionData.bFloor = true;
146 }
147
148 void setTangentOff(const EGG::Vector3f &v) {
149 m_tangentOff = v;
150 }
151 void setMovement(const EGG::Vector3f &v) {
152 m_movement = v;
153 }
154
155 void setWorldInertiaTensor(const EGG::Matrix34f &worldInertiaTensor) {
156 m_worldInertiaTensor = worldInertiaTensor;
157 }
159
161 [[nodiscard]] KartPullPath &pullPath() {
162 return m_pullPath;
163 }
164
165 [[nodiscard]] const KartPullPath &pullPath() const {
166 return m_pullPath;
167 }
168
169 [[nodiscard]] f32 boundingRadius() const {
170 return m_boundingRadius;
171 }
172
173 [[nodiscard]] f32 floorMomentRate() const {
174 return m_floorMomentRate;
175 }
176
177 [[nodiscard]] const SurfaceFlags &surfaceFlags() const {
178 return m_surfaceFlags;
179 }
180
181 [[nodiscard]] const EGG::Vector3f &tangentOff() const {
182 return m_tangentOff;
183 }
184
185 [[nodiscard]] const EGG::Vector3f &movement() const {
186 return m_movement;
187 }
188
189 [[nodiscard]] f32 sumHitboxBottomHeightSoftWall() const {
190 return m_sumHitboxBottomHeightSoftWall;
191 }
192
193 [[nodiscard]] u16 numSoftWallCollisions() const {
194 return m_numSoftWallCollisions;
195 }
196
197 [[nodiscard]] f32 sumHitboxBottomHeightFloorOnly() const {
198 return m_sumHitboxBottomHeightFloorOnly;
199 }
200
201 [[nodiscard]] u16 numFloorOnlyCollisions() const {
202 return m_numFloorOnlyCollisions;
203 }
204
205 [[nodiscard]] f32 colPerpendicularity() const {
206 return m_colPerpendicularity;
207 }
209
210private:
211 typedef Action (KartCollide::*ObjectCollisionHandler)(size_t idx);
212
213 KartPullPath m_pullPath;
214 f32 m_boundingRadius;
215 f32 m_floorMomentRate;
216 EGG::Vector3f m_totalReactionWallNrm;
217 SurfaceFlags m_surfaceFlags;
218 EGG::Vector3f m_tangentOff;
219 EGG::Vector3f m_movement;
220 s16 m_respawnTimer;
221 s16 m_solidOobTimer;
222 s16 m_shrinkTimer;
223 f32 m_smoothedBack; // 0x50
224 f32 m_sumHitboxBottomHeightSoftWall;
225 u16 m_numSoftWallCollisions;
226 f32 m_sumHitboxBottomHeightFloorOnly;
227 u16 m_numFloorOnlyCollisions;
228 s16 m_poleAngVelTimer;
229 f32 m_poleYaw;
230 f32 m_colPerpendicularity;
231
236
237 static std::array<ObjectCollisionHandler, 33> s_objectCollisionHandlers;
238};
239
240} // namespace Kinoko::Kart
A 3 x 4 matrix.
Definition Matrix.hh:10
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 FUN_805B72B8(f32 param_1, f32 param_2, bool lockXZ, bool addExtVelY)
Affects velocity when landing from airtime.
void processFloor(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo, Field::KCLTypeMask *maskOut, bool wheel)
Processes the floor triangles' attributes.
void calcSideCollision(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo)
EGG::Matrix34f m_worldInertiaTensor
The world-space inertia tensor of the kart.
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.
Action handleReactNone(size_t idx)
Object collision functions.
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.
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 calcBodyCollision(f32 totalScale, f32 sinkDepth, const EGG::Quatf &rot, const EGG::Vector3f &scale)
Checks and acts on collision for each kart hitbox.
void applyBodyCollision(CollisionData &collisionData, const EGG::Vector3f &movement, const EGG::Vector3f &posRel, s32 count)
Saves collision info when vehicle body collision occurs.
void processWheel(CollisionData &collisionData, Hitbox &hitbox, Field::CollisionInfo *colInfo, Field::KCLTypeMask *maskOut)
Processes moving water and floor collision effects.
void processCannon(Field::KCLTypeMask *maskOut)
Checks if we are colliding with a cannon trigger and sets the state flag if so.
Pertains to kart-related functionality.
A representation of a bounding cuboid.
Definition BoundBox.hh:37
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:23
A 3D float vector.
Definition Vector.hh:107
Information about the current collision and its properties.
bool bFloor
Set if colliding with KCL which satisfies KCL_TYPE_FLOOR.