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 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;
35 f32 colPerpendicularity;
36
37 bool bFloor;
38 bool bWall;
39 bool bInvisibleWall;
40 bool bWall3;
41 bool bInvisibleWallOnly;
42 bool bSoftWall;
43 bool bTrickable;
44 bool bHasRoadVel;
45 bool bWallAtLeftCloser;
46 bool bWallAtRightCloser;
47};
48
52class Hitbox {
53public:
54 Hitbox();
55 ~Hitbox();
56
57 void calc(f32 totalScale, f32 sinkDepth, const EGG::Vector3f &scale, const EGG::Quatf &rot,
58 const EGG::Vector3f &pos);
59
61 void reset();
62
63 void setRadius(f32 radius) {
64 m_radius = radius;
65 }
66
67 void setBspHitbox(const BSP::Hitbox *hitbox, bool owns = false) {
68 m_ownsBSP = owns;
69 m_bspHitbox = hitbox;
70 }
71
72 void setWorldPos(const EGG::Vector3f &pos) {
73 m_worldPos = pos;
74 }
75
76 void setLastPos(const EGG::Vector3f &pos) {
77 m_lastPos = pos;
78 }
79
80 void setLastPos(const EGG::Vector3f &scale, const EGG::Matrix34f &pose);
82
84 [[nodiscard]] const BSP::Hitbox *bspHitbox() const {
85 return m_bspHitbox;
86 }
87
88 [[nodiscard]] const EGG::Vector3f &worldPos() const {
89 return m_worldPos;
90 }
91
92 [[nodiscard]] const EGG::Vector3f &lastPos() const {
93 return m_lastPos;
94 }
95
96 [[nodiscard]] const EGG::Vector3f &relPos() const {
97 return m_relPos;
98 }
99
100 [[nodiscard]] f32 radius() const {
101 return m_radius;
102 }
104
105private:
106 const BSP::Hitbox *m_bspHitbox;
107 f32 m_radius;
108 EGG::Vector3f m_worldPos;
109 EGG::Vector3f m_lastPos;
110 EGG::Vector3f m_relPos;
111
112 bool m_ownsBSP;
113};
114
118public:
121
122 [[nodiscard]] f32 initHitboxes(const std::array<BSP::Hitbox, 16> &hitboxes);
123 [[nodiscard]] f32 computeCollisionLimits();
124 void createSingleHitbox(f32 radius, const EGG::Vector3f &relPos);
125
127 void reset();
128 void resetCollision();
129 void setHitboxScale(f32 scale);
131
133 [[nodiscard]] f32 boundingRadius() const {
134 return m_boundingRadius;
135 }
136
137 [[nodiscard]] Hitbox &hitbox(u16 hitboxIdx) {
138 return m_hitboxes[hitboxIdx];
139 }
140
141 [[nodiscard]] u16 hitboxCount() const {
142 return m_hitboxes.size();
143 }
144
145 [[nodiscard]] CollisionData &collisionData() {
146 return m_collisionData;
147 }
148
149 [[nodiscard]] const CollisionData &collisionData() const {
150 return m_collisionData;
151 }
153
154private:
155 f32 m_boundingRadius;
156 CollisionData m_collisionData;
157 std::span<Hitbox> m_hitboxes;
158 f32 m_hitboxScale;
159};
160
161} // namespace Kart
A 3 x 4 matrix.
Definition Matrix.hh:8
Houses hitbox and collision info for an object (body or wheel).
void createSingleHitbox(f32 radius, const EGG::Vector3f &relPos)
Creates a hitbox to represent a tire.
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.
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.
Pertains to kart-related functionality.
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
A 3D float vector.
Definition Vector.hh:87
Represents one of the many hitboxes that make up a vehicle.
Definition KartParam.hh:10
Information about the current collision and its properties.
Field::KCLTypeMask closestWallFlags
The colliding wall KCL flag's KColType.
u32 closestFloorSettings
The colliding floor KCL flag's "variant".
bool bFloor
Set if colliding with KCL which satisfies KCL_TYPE_FLOOR.
u32 closestWallSettings
The colliding wall KCL flag's "variant".
bool bWall3
Set if colliding with COL_TYPE_WALL_2.
bool bWall
Set if colliding with KCL which satisfies KCL_TYPE_WALL.
Field::KCLTypeMask closestFloorFlags
The colliding floor KCL flag's KColType.
s32 intensity
The KCL flag's "wheel depth".