A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
CollisionGroup.hh
1#pragma once
2
3#include "game/kart/KartParam.hh"
4
6
7#include <egg/math/Matrix.hh>
8
9#include <array>
10#include <span>
11
13namespace Kinoko::Kart {
14
18 void reset();
19
20 EGG::Vector3f tangentOff;
21 EGG::Vector3f floorNrm;
22 EGG::Vector3f wallNrm;
23 EGG::Vector3f noBounceWallNrm;
24 EGG::Vector3f vel;
25 EGG::Vector3f relPos;
26 EGG::Vector3f movement;
27 EGG::Vector3f roadVelocity;
28 f32 speedFactor;
29 f32 rotFactor;
30 Field::KCLTypeMask closestFloorFlags;
32 Field::KCLTypeMask closestWallFlags;
35 f32 colPerpendicularity;
36
37 bool bFloor;
38 bool bWall;
39 bool bInvisibleWall;
40 bool bTrickable;
42 bool bWall3;
43 bool bInvisibleWallOnly;
45 bool bSoftWall;
48 bool bHasRoadVel;
49 bool bWallAtLeftCloser;
50 bool bWallAtRightCloser;
52};
53
57class Hitbox {
58public:
59 Hitbox();
60 ~Hitbox();
61
62 void calc(f32 totalScale, f32 sinkDepth, const EGG::Vector3f &scale, const EGG::Quatf &rot,
63 const EGG::Vector3f &pos);
64
66 void reset();
67
68 void setRadius(f32 radius) {
69 m_radius = radius;
70 }
71
72 void setBspHitbox(const BSP::Hitbox *hitbox, bool owns = false) {
73 m_ownsBSP = owns;
74 m_bspHitbox = hitbox;
75 }
76
77 void setWorldPos(const EGG::Vector3f &pos) {
78 m_worldPos = pos;
79 }
80
81 void setLastPos(const EGG::Vector3f &pos) {
82 m_lastPos = pos;
83 }
84
85 void setLastPos(const EGG::Vector3f &scale, const EGG::Matrix34f &pose);
87
89 [[nodiscard]] const BSP::Hitbox *bspHitbox() const {
90 return m_bspHitbox;
91 }
92
93 [[nodiscard]] const EGG::Vector3f &worldPos() const {
94 return m_worldPos;
95 }
96
97 [[nodiscard]] const EGG::Vector3f &lastPos() const {
98 return m_lastPos;
99 }
100
101 [[nodiscard]] const EGG::Vector3f &relPos() const {
102 return m_relPos;
103 }
104
105 [[nodiscard]] f32 radius() const {
106 return m_radius;
107 }
109
110private:
111 const BSP::Hitbox *m_bspHitbox;
112 f32 m_radius;
113 EGG::Vector3f m_worldPos;
114 EGG::Vector3f m_lastPos;
115 EGG::Vector3f m_relPos;
116
117 bool m_ownsBSP;
118};
119
123public:
126
127 [[nodiscard]] f32 initHitboxes(const std::array<BSP::Hitbox, 16> &hitboxes);
128 [[nodiscard]] f32 computeCollisionLimits();
129 void createSingleHitbox(f32 radius, const EGG::Vector3f &relPos);
130
132 void reset();
133 void resetCollision();
134 void setHitboxScale(f32 scale);
136
138 [[nodiscard]] f32 boundingRadius() const {
139 return m_boundingRadius;
140 }
141
142 [[nodiscard]] Hitbox &hitbox(u16 hitboxIdx) {
143 return m_hitboxes[hitboxIdx];
144 }
145
146 [[nodiscard]] u16 hitboxCount() const {
147 return m_hitboxes.size();
148 }
149
150 [[nodiscard]] CollisionData &collisionData() {
151 return m_collisionData;
152 }
153
154 [[nodiscard]] const CollisionData &collisionData() const {
155 return m_collisionData;
156 }
158
159private:
160 f32 m_boundingRadius;
161 CollisionData m_collisionData;
162 owning_span<Hitbox> m_hitboxes;
163 f32 m_hitboxScale;
164};
165
166} // namespace Kinoko::Kart
A 3 x 4 matrix.
Definition Matrix.hh:10
Houses hitbox and collision info for an object (body or wheel).
f32 computeCollisionLimits()
Sets the bounding radius.
f32 initHitboxes(const std::array< BSP::Hitbox, 16 > &hitboxes)
Initializes the hitbox array based on the KartParam's BSP hitboxes.
void createSingleHitbox(f32 radius, const EGG::Vector3f &relPos)
Creates a hitbox to represent a tire.
Represents a hitbox for the kart body or a wheel.
void calc(f32 totalScale, f32 sinkDepth, const EGG::Vector3f &scale, const EGG::Quatf &rot, const EGG::Vector3f &pos)
Calculates the position of a given hitbox, both relative to the player and world.
A contiguous storage container that manages the lifecycle of a buffer of a given size.
Definition Types.hh:29
Pertains to kart-related functionality.
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
A 3D float vector.
Definition Vector.hh:107
Represents one of the many hitboxes that make up a vehicle.
Definition KartParam.hh:10
Information about the current collision and its properties.
bool bWall3
Set if colliding with COL_TYPE_WALL_2.
Field::KCLTypeMask closestFloorFlags
The colliding floor KCL flag's KColType.
bool bMovingWaterDecaySpeed
Player speed will drop if not in mushroom.
bool bMovingWaterStickyRoad
KC pipe vertical water section.
s32 intensity
The KCL flag's "wheel depth".
bool bMovingWaterVertical
KC last turn vertical water.
bool bMovingWaterMomentum
Player will maintain speed for a bit after leaving KCL.
bool bFloor
Set if colliding with KCL which satisfies KCL_TYPE_FLOOR.
u32 closestWallSettings
The colliding wall KCL flag's "variant".
bool bMovingWaterDisableAccel
KC last turn prevents mini-turbo acceleration.
u32 closestFloorSettings
The colliding floor KCL flag's "variant".
bool bWall
Set if colliding with KCL which satisfies KCL_TYPE_WALL.
Field::KCLTypeMask closestWallFlags
The colliding wall KCL flag's KColType.