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;
33 f32 colPerpendicularity;
34
35 bool bFloor;
36 bool bWall;
37 bool bInvisibleWall;
38 bool bWall3;
39 bool bInvisibleWallOnly;
40 bool bSoftWall;
41 bool bTrickable;
42 bool bHasRoadVel;
43 bool bWallAtLeftCloser;
44 bool bWallAtRightCloser;
45};
46
50class Hitbox {
51public:
52 Hitbox();
53 ~Hitbox();
54
55 void calc(f32 totalScale, f32 sinkDepth, const EGG::Vector3f &scale, const EGG::Quatf &rot,
56 const EGG::Vector3f &pos);
57
59 void reset();
60
61 void setRadius(f32 radius) {
62 m_radius = radius;
63 }
64
65 void setBspHitbox(const BSP::Hitbox *hitbox, bool owns = false) {
66 m_ownsBSP = owns;
67 m_bspHitbox = hitbox;
68 }
69
70 void setWorldPos(const EGG::Vector3f &pos) {
71 m_worldPos = pos;
72 }
73
74 void setLastPos(const EGG::Vector3f &pos) {
75 m_lastPos = pos;
76 }
77
78 void setLastPos(const EGG::Vector3f &scale, const EGG::Matrix34f &pose);
80
82 [[nodiscard]] const BSP::Hitbox *bspHitbox() const {
83 return m_bspHitbox;
84 }
85
86 [[nodiscard]] const EGG::Vector3f &worldPos() const {
87 return m_worldPos;
88 }
89
90 [[nodiscard]] const EGG::Vector3f &lastPos() const {
91 return m_lastPos;
92 }
93
94 [[nodiscard]] const EGG::Vector3f &relPos() const {
95 return m_relPos;
96 }
97
98 [[nodiscard]] f32 radius() const {
99 return m_radius;
100 }
102
103private:
104 const BSP::Hitbox *m_bspHitbox;
105 f32 m_radius;
106 EGG::Vector3f m_worldPos;
107 EGG::Vector3f m_lastPos;
108 EGG::Vector3f m_relPos;
109
110 bool m_ownsBSP;
111};
112
116public:
119
120 [[nodiscard]] f32 initHitboxes(const std::array<BSP::Hitbox, 16> &hitboxes);
121 [[nodiscard]] f32 computeCollisionLimits();
122 void createSingleHitbox(f32 radius, const EGG::Vector3f &relPos);
123
125 void reset();
126 void resetCollision();
127 void setHitboxScale(f32 scale);
129
131 [[nodiscard]] f32 boundingRadius() const {
132 return m_boundingRadius;
133 }
134
135 [[nodiscard]] Hitbox &hitbox(u16 hitboxIdx) {
136 return m_hitboxes[hitboxIdx];
137 }
138
139 [[nodiscard]] u16 hitboxCount() const {
140 return m_hitboxes.size();
141 }
142
143 [[nodiscard]] CollisionData &collisionData() {
144 return m_collisionData;
145 }
146
147 [[nodiscard]] const CollisionData &collisionData() const {
148 return m_collisionData;
149 }
151
152private:
153 f32 m_boundingRadius;
154 CollisionData m_collisionData;
155 std::span<Hitbox> m_hitboxes;
156 f32 m_hitboxScale;
157};
158
159} // 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:83
Represents one of the many hitboxes that make up a vehicle.
Definition KartParam.hh:10
Information about the current collision and its properties.
u32 closestFloorSettings
The KCL flag's "variant".
bool bFloor
Set if colliding with KCL which satisfies KCL_TYPE_FLOOR.
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 KCL flag's KColType.
s32 intensity
The KCL flag's "wheel depth".