A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
CollisionInfo.cc
Go to the documentation of this file.
1#include "CollisionInfo.hh"
2
3namespace Kinoko::Field {
4
9
13 bbox.min = bbox.min.minimize(offset);
14 bbox.max = bbox.max.maximize(offset);
15}
16
33
37 bbox.min = bbox.min.minimize(offset);
38 bbox.max = bbox.max.maximize(offset);
39}
40
46 if (dist > floorDist) {
47 floorDist = dist;
48 floorNrm = fnrm;
49 }
50}
51
57 if (dist > wallDist) {
58 wallDist = dist;
59 wallNrm = fnrm;
60 }
61}
62
65 bbox.setZero();
66 movingFloorDist = -std::numeric_limits<f32>::min();
67 wallDist = -std::numeric_limits<f32>::min();
68 floorDist = -std::numeric_limits<f32>::min();
69 perpendicularity = 0.0f;
70}
71
77void CollisionInfo::update(f32 dist, const EGG::Vector3f &offset, const EGG::Vector3f &fnrm,
78 KCLTypeMask mask) {
79 bbox.min = bbox.min.minimize(offset);
80 bbox.max = bbox.max.maximize(offset);
81
82 if (mask & KCL_TYPE_FLOOR) {
83 updateFloor(dist, fnrm);
84 } else if (mask & KCL_TYPE_WALL) {
85 if (wallDist > -std::numeric_limits<f32>::min()) {
86 f32 dot = 1.0f - wallNrm.ps_dot(fnrm);
87 if (dot > perpendicularity) {
88 perpendicularity = std::min(dot, 1.0f);
89 }
90 }
91
92 updateWall(dist, fnrm);
93 }
94}
95
107 const EGG::Vector3f &v) {
108 EGG::Vector3f min = mtx.ps_multVector33(rhs.bbox.min);
109 EGG::Vector3f max = mtx.ps_multVector33(rhs.bbox.max);
110
111 bbox.min = bbox.min.minimize(min.minimize(max));
112 bbox.max = bbox.max.maximize(min.maximize(max));
113
114 if (floorDist < rhs.floorDist) {
115 floorDist = rhs.floorDist;
117 }
118
119 if (wallDist < rhs.wallDist) {
120 wallDist = rhs.wallDist;
122 }
123
124 if (movingFloorDist < rhs.floorDist) {
126 roadVelocity = v;
127 }
128
130}
131
132} // namespace Kinoko::Field
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
#define KCL_TYPE_WALL
0xD010F000
A 3 x 4 matrix.
Definition Matrix.hh:10
constexpr Vector3f ps_multVector33(const Vector3f &vec) const
Paired-singles impl. of multVector33.
Definition Matrix.hh:317
Pertains to collision.
float f32
Definition Memory.hh:21
constexpr void setZero()
Definition BoundBox.hh:46
A 3D float vector.
Definition Vector.hh:108
constexpr f32 ps_dot() const
Paired-singles dot product implementation.
Definition Vector.hh:257
constexpr Vector3f minimize(const Vector3f &rhs) const
Returns a vector whose elements are the min of the elements of both vectors.
Definition Vector.hh:328
constexpr Vector3f maximize(const Vector3f &rhs) const
Returns a vector whose elements are the max of the elements of both vectors.
Definition Vector.hh:316
Stores partial information pertaining to a collision.
void updateBBox(const EGG::Vector3f &offset)
Expands the bounding box to include the provided position vector.
void transformInfo(const CollisionInfoPartial &rhs, const EGG::Matrix34f &mtx)
Maps the provided collision info from local to world space based on the provided transformation matri...
EGG::BoundBox3f bbox
Bounding box of "push out" vectors.
void reset()
Initializes the bounding box to zero.
Stores information pertaining to a collision.
void updateBBox(const EGG::Vector3f &offset)
Expands the bounding box to include the provided position vector.
EGG::Vector3f roadVelocity
Velocity induced by moving object collisions.
f32 wallDist
Distance from the colliding wall tri.
void updateFloor(f32 dist, const EGG::Vector3f &fnrm)
Updates the floor collision info if the provided distance is closer than the currently tracked floor ...
EGG::Vector3f wallNrm
Colliding wall face's normal vector.
void updateWall(f32 dist, const EGG::Vector3f &fnrm)
Updates the wall collision info if the provided distance is closer than the currently tracked wall co...
EGG::Vector3f floorNrm
Colliding floor's up vector.
EGG::BoundBox3f bbox
Bounding box of "push out" vectors.
f32 perpendicularity
Measures how much two colliding wall normals diverge.
f32 movingFloorDist
Distance from the colliding moving floor tri.
void update(f32 dist, const EGG::Vector3f &offset, const EGG::Vector3f &fnrm, KCLTypeMask mask)
Updates members to reflect a new collision.
f32 floorDist
Distance from the colliding floor tri.
void reset()
Sets all members to their default values.
void transformInfo(const CollisionInfo &rhs, const EGG::Matrix34f &mtx, const EGG::Vector3f &v)
Maps the provided collision info from local to world space based on the provided transformation matri...