A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KColData.cc
Go to the documentation of this file.
1#include "KColData.hh"
2
3#include <egg/geom/Sphere.hh>
4#include <egg/math/Math.hh>
5
6#include <cmath>
7
8// Credit: em-eight/mkw
9// Credit: stblr/Hanachan
10
11namespace Kinoko::Field {
12
14KColData::KColData(const void *file) {
15 auto addOffset = [](const void *file, u32 offset) -> const void * {
16 return reinterpret_cast<const void *>(reinterpret_cast<const u8 *>(file) + offset);
17 };
18 EGG::RamStream stream = EGG::RamStream(file, sizeof(KColHeader));
19
20 u32 posOffset = stream.read_u32();
21 u32 nrmOffset = stream.read_u32();
22 u32 prismOffset = stream.read_u32();
23 u32 blockOffset = stream.read_u32();
24
25 m_posData = addOffset(file, posOffset);
26 m_nrmData = addOffset(file, nrmOffset);
27 m_prismData = addOffset(file, prismOffset);
28 m_blockData = addOffset(file, blockOffset);
29
30 m_prismThickness = stream.read_f32();
31 m_areaMinPos.read(stream);
32 m_areaXWidthMask = stream.read_u32();
33 m_areaYWidthMask = stream.read_u32();
34 m_areaZWidthMask = stream.read_u32();
35 m_blockWidthShift = stream.read_u32();
38 m_sphereRadius = stream.read_f32();
39
40 m_pos.setZero();
43 m_radius = 0.0f;
44 m_prismIter = nullptr;
46
47 // NOTE: Collision is expensive on the CPU, so we preload all of the prism data to ensure we're
48 // not constantly handling endianness.
50
52}
53
54KColData::~KColData() = default;
55
59 m_pos = pos;
60 m_radius = radius;
61 m_typeMask = mask;
62 m_cachedPos = pos;
63 m_cachedRadius = radius;
64
65 if (radius <= m_sphereRadius) {
67 }
68
69 *m_prismCacheTop = 0;
70}
71
73void KColData::narrowPolygon_EachBlock(const u16 *prismArray) {
74 m_prismIter = prismArray;
75
76 while (checkSphereSingle(nullptr, nullptr, nullptr)) {
80
81 if (m_prismCacheTop == m_prismCache.end()) {
83 return;
84 }
85 }
86}
87
91 m_bbox.max.set(-999999.0f);
92 m_bbox.min.set(999999.0f);
93
94 for (size_t i = 1; i < m_prismGeometry.size(); ++i) {
96 const EGG::Vector3f &vtx1 = geom.vtx;
97
98 const EGG::Vector3f vtx2 = GetVertex(geom.height, vtx1, geom.fnrm, geom.enrm3, geom.enrm1);
99 const EGG::Vector3f vtx3 = GetVertex(geom.height, vtx1, geom.fnrm, geom.enrm3, geom.enrm2);
100
101 m_bbox.min = m_bbox.min.minimize(vtx1);
102 m_bbox.min = m_bbox.min.minimize(vtx2);
103 m_bbox.min = m_bbox.min.minimize(vtx3);
104 m_bbox.max = m_bbox.max.maximize(vtx1);
105 m_bbox.max = m_bbox.max.maximize(vtx2);
106 m_bbox.max = m_bbox.max.maximize(vtx3);
107 }
108}
109
111bool KColData::checkPointCollision(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut) {
112 return std::isfinite(m_prevPos.y) ? checkPointMovement(distOut, fnrmOut, flagsOut) :
113 checkPoint(distOut, fnrmOut, flagsOut);
114}
115
117bool KColData::checkSphereCollision(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut) {
118 return std::isfinite(m_prevPos.y) ? checkSphereMovement(distOut, fnrmOut, flagsOut) :
119 checkSphere(distOut, fnrmOut, flagsOut);
120}
121
128bool KColData::checkSphere(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut) {
129 // If there's no list of triangles to check, there's no collision
130 if (!m_prismIter) {
131 return false;
132 }
133
134 // Check collision for all triangles, and continuously call the function until we're out
135 while (*++m_prismIter != 0) {
136 if (checkCollision<CollisionCheckType::Plane>(parse<u16>(*m_prismIter), distOut, fnrmOut,
137 flagsOut)) {
138 return true;
139 }
140 }
141
142 // We're out of triangles to check - another list must be prepared for subsequent calls
143 m_prismIter = nullptr;
144 return false;
145}
146
148bool KColData::checkSphereSingle(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut) {
149 if (!m_prismIter) {
150 return false;
151 }
152
153 while (*++m_prismIter != 0) {
154 if (m_prismCacheTop != m_prismCache.begin()) {
155 u16 *puVar10 = m_prismCacheTop - 1;
156 while (*m_prismIter != *puVar10) {
157 if (puVar10-- < m_prismCache.begin()) {
158 break;
159 }
160 }
161
162 if (puVar10 >= m_prismCache.begin()) {
163 continue;
164 }
165 }
166
167 if (checkCollision<CollisionCheckType::Edge>(parse<u16>(*m_prismIter), distOut, fnrmOut,
168 flagsOut)) {
169 return true;
170 }
171 }
172
173 m_prismIter = nullptr;
174 return false;
175}
176
179void KColData::lookupPoint(const EGG::Vector3f &pos, const EGG::Vector3f &prevPos,
180 KCLTypeMask typeMask) {
182 m_pos = pos;
183 m_prevPos = prevPos;
184 m_movement = pos - prevPos;
185 m_typeMask = typeMask;
186}
187
190void KColData::lookupSphere(f32 radius, const EGG::Vector3f &pos, const EGG::Vector3f &prevPos,
191 KCLTypeMask typeMask) {
193 m_pos = pos;
194 m_prevPos = prevPos;
195 m_movement = pos - prevPos;
196 m_radius = std::min(radius, m_sphereRadius);
197 m_typeMask = typeMask;
198}
199
202 f32 radius) {
203 EGG::Sphere3f sphere1(p1, radius);
205
206 if (!sphere1.isInsideOtherSphere(sphere2)) {
208 m_radius = std::min(m_sphereRadius, radius);
209 } else {
210 m_radius = radius;
212 }
213
214 m_pos = p1;
215 m_prevPos = p2;
216 m_movement = p1 - p2;
217 m_typeMask = typeMask;
218}
219
225 // Calculate the x, y, and z offsets of the point from the minimum
226 // corner of the tree's bounding box.
227 const int x = point.x - m_areaMinPos.x;
228 const int y = point.y - m_areaMinPos.y;
229 const int z = point.z - m_areaMinPos.z;
230
231 // Check if the point is outside the tree's bounding box in the x, y,
232 // or z dimensions. If it is, return 0.
233 if (x & m_areaXWidthMask || y & m_areaYWidthMask || z & m_areaZWidthMask) {
234 return nullptr;
235 }
236
237 // Initialize the current tree node to the root node of the tree.
238 u32 shift = m_blockWidthShift;
239 const u8 *curBlock = reinterpret_cast<const u8 *>(m_blockData);
240 s32 offset;
241
242 // Traverse the tree to find the leaf node containing the input point.
243 u32 index = 4 *
244 (((u32)z >> shift) << m_areaXYBlocksShift | ((u32)y >> shift) << m_areaXBlocksShift |
245 (u32)x >> shift);
246
247 while (true) {
248 // Get the offset of the current node's child node.
249 offset = parse<u32>(*reinterpret_cast<const u32 *>(curBlock + index));
250
251 // If the offset is negative, the current node is a leaf node.
252 if ((offset & 0x80000000) != 0) {
253 break;
254 }
255
256 // If the offset is non-negative, update the current node to be
257 // the child node and continue traversing the tree.
258 shift--;
259 curBlock += offset;
260
261 u32 x_shift = ((1 * ((u32)x >> shift)) & 1);
262 u32 y_shift = ((2 * ((u32)y >> shift)) & 2);
263 u32 z_shift = ((4 * ((u32)z >> shift)) & 4);
264
265 index = 4 * (x_shift | y_shift | z_shift);
266 }
267
268 // We have to remove the MSB since it's solely used to identify leaves.
269 return reinterpret_cast<const u16 *>(curBlock + (offset & ~0x80000000));
270}
271
283 const EGG::Vector3f &fnrm, const EGG::Vector3f &enrm3, const EGG::Vector3f &enrm) {
284 EGG::Vector3f cross = fnrm.cross(enrm);
285 f32 dp = cross.ps_dot(enrm3);
286 cross *= (height / dp);
287
288 return cross + vertex1;
289}
290
296 size_t prismCount =
297 (reinterpret_cast<uintptr_t>(m_blockData) - reinterpret_cast<uintptr_t>(m_prismData)) /
298 sizeof(KCollisionPrism);
299
300 // Prisms are one-indexed, so the normal data runs up to the (unused) zeroth prism
301 size_t nrmSize = reinterpret_cast<uintptr_t>(m_prismData) + sizeof(KCollisionPrism) -
302 reinterpret_cast<uintptr_t>(m_nrmData);
303 size_t posSize =
304 reinterpret_cast<uintptr_t>(m_nrmData) - reinterpret_cast<uintptr_t>(m_posData);
305
306 EGG::RamStream prismStream(m_prismData, sizeof(KCollisionPrism) * prismCount);
307 EGG::RamStream nrmStream(m_nrmData, nrmSize);
308 EGG::RamStream posStream(m_posData, posSize);
309
310 auto readVec = [](EGG::RamStream &stream, u16 idx) {
311 EGG::Vector3f vec;
312 stream.jump(idx * sizeof(EGG::Vector3f));
313 vec.read(stream);
314 return vec;
315 };
316
319
320 // Prisms are one-indexed, so the first entry is left empty
321 prismStream.skip(sizeof(KCollisionPrism));
322
323 for (size_t i = 1; i < prismCount; ++i) {
325
326 geom.height = prismStream.read_f32();
327 u16 pos_i = prismStream.read_u16();
328 u16 fnrm_i = prismStream.read_u16();
329 u16 enrm1_i = prismStream.read_u16();
330 u16 enrm2_i = prismStream.read_u16();
331 u16 enrm3_i = prismStream.read_u16();
332 m_prismAttributes[i] = prismStream.read_u16();
333
334 geom.vtx = readVec(posStream, pos_i);
335 geom.fnrm = readVec(nrmStream, fnrm_i);
336 geom.enrm1 = readVec(nrmStream, enrm1_i);
337 geom.enrm2 = readVec(nrmStream, enrm2_i);
338 geom.enrm3 = readVec(nrmStream, enrm3_i);
339 }
340}
341
348template <KColData::CollisionCheckType Type>
349bool KColData::checkCollision(u16 prismIdx, f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut) {
350 const u16 attribute = m_prismAttributes[prismIdx];
351 const KCollisionPrismGeometry &geom = m_prismGeometry[prismIdx];
352
353 // Responsible for updating the output params
354 auto out = [&](f32 dist) {
355 if (distOut) {
356 *distOut = dist;
357 }
358 if (fnrmOut) {
359 *fnrmOut = geom.fnrm;
360 }
361 if (flagsOut) {
362 *flagsOut = attribute;
363 }
364 return true;
365 };
366
367 // The flag check occurs earlier than in the base game here. We don't want to do math if the tri
368 // we're checking doesn't have matching flags.
369 u32 attributeMask = KCL_ATTRIBUTE_TYPE_BIT(attribute);
370 if (!(attributeMask & m_typeMask)) {
371 return false;
372 }
373
374 const EGG::Vector3f relativePos = m_pos - geom.vtx;
375
376 // For Kinoko, we check the plane distance first since this is a more common early return than
377 // the edge normal checks.
378 const EGG::Vector3f &fnrm = geom.fnrm;
379 f32 plane_dist = relativePos.ps_dot(fnrm);
380 f32 dist_in_plane = m_radius - plane_dist;
381 if (dist_in_plane <= 0.0f) {
382 return false;
383 }
384
385 // Edge normals point outside the triangle
386 const EGG::Vector3f &enrm1 = geom.enrm1;
387 f32 dist_ca = relativePos.ps_dot(enrm1);
388 if (m_radius <= dist_ca) {
389 return false;
390 }
391
392 const EGG::Vector3f &enrm2 = geom.enrm2;
393 f32 dist_ab = relativePos.ps_dot(enrm2);
394 if (m_radius <= dist_ab) {
395 return false;
396 }
397
398 const EGG::Vector3f &enrm3 = geom.enrm3;
399 f32 dist_bc = relativePos.ps_dot(enrm3) - geom.height;
400 if (m_radius <= dist_bc) {
401 return false;
402 }
403
404 f32 typeDistance = m_prismThickness;
405 if constexpr (Type == CollisionCheckType::Edge) {
406 typeDistance += m_radius;
407 }
408
409 if (dist_in_plane >= typeDistance) {
410 return false;
411 }
412
413 if constexpr (Type == CollisionCheckType::Movement) {
414 if (attributeMask & KCL_TYPE_DIRECTIONAL && m_movement.dot(fnrm) > 0.0f) {
415 return false;
416 }
417 }
418
419 // Originally part of the edge searching, but moved out for simplicity
420 // If these are all zero, then we're inside the triangle
421 if (dist_ab <= 0.0f && dist_bc <= 0.0f && dist_ca <= 0.0f) {
422 if constexpr (Type == CollisionCheckType::Movement) {
423 EGG::Vector3f lastPos = relativePos - m_movement;
424 // We're only colliding if we are moving towards the face
425 if (plane_dist < 0.0f && lastPos.ps_dot(fnrm) < 0.0f) {
426 return false;
427 }
428 }
429 return out(dist_in_plane);
430 }
431
432 EGG::Vector3f edge_nor, other_edge_nor;
433 f32 edge_dist, other_edge_dist;
434 bool swap = false;
435 bool swapNorms = false;
436 // > means further, < means closer, = means same distance
437 if (dist_ab >= dist_ca && dist_ab > dist_bc) {
438 // AB is the furthest edge
439 edge_nor = enrm2;
440 edge_dist = dist_ab;
441 if (dist_ca >= dist_bc) {
442 // CA is the second furthest edge
443 other_edge_nor = enrm1;
444 other_edge_dist = dist_ca;
445 swapNorms = true;
446 } else {
447 // BC is the second furthest edge
448 other_edge_nor = enrm3;
449 other_edge_dist = dist_bc;
450 swap = true;
451 }
452 } else if (dist_bc >= dist_ca) {
453 // BC is the furthest edge
454 edge_nor = enrm3;
455 edge_dist = dist_bc;
456 if (dist_ab >= dist_ca) {
457 // AB is the second furthest edge
458 other_edge_nor = enrm2;
459 other_edge_dist = dist_ab;
460 swapNorms = true;
461 } else {
462 // CA is the second furthest edge
463 other_edge_nor = enrm1;
464 other_edge_dist = dist_ca;
465 swap = true;
466 }
467 } else {
468 // CA is the furthest edge
469 edge_nor = enrm1;
470 edge_dist = dist_ca;
471 if (dist_bc >= dist_ab) {
472 // BC is the second furthest edge
473 other_edge_nor = enrm3;
474 other_edge_dist = dist_bc;
475 swapNorms = true;
476 } else {
477 // AB is the second furthest edge
478 other_edge_nor = enrm2;
479 other_edge_dist = dist_ab;
480 swap = true;
481 }
482 }
483
484 f32 cos = edge_nor.ps_dot(other_edge_nor);
485 f32 sq_dist;
486 if (cos * edge_dist > other_edge_dist) {
487 if constexpr (Type == CollisionCheckType::Plane) {
488 if (edge_dist > plane_dist) {
489 return false;
490 }
491 }
492 sq_dist = m_radius * m_radius - edge_dist * edge_dist;
493 } else {
494 f32 sq_sin = cos * cos - 1.0f;
495
496 if (swap) {
497 std::swap(edge_dist, other_edge_dist);
498 }
499
500 if (swapNorms) {
501 std::swap(edge_nor, other_edge_nor);
502 }
503
504 f32 t = (cos * edge_dist - other_edge_dist) / sq_sin;
505 f32 s = edge_dist - t * cos;
506 const EGG::Vector3f corner_pos = edge_nor * t + other_edge_nor * s;
507
508 f32 cornerDot = corner_pos.ps_squareMag();
509 if constexpr (Type == CollisionCheckType::Plane) {
510 if (cornerDot > plane_dist * plane_dist) {
511 return false;
512 }
513 }
514
515 sq_dist = m_radius * m_radius - cornerDot;
516 }
517
518 if (sq_dist < plane_dist * plane_dist || sq_dist <= 0.0f) {
519 return false;
520 }
521
522 f32 dist = EGG::Mathf::sqrt(sq_dist) - plane_dist;
523 if (dist <= 0.0f) {
524 return false;
525 }
526
527 if constexpr (Type == CollisionCheckType::Movement) {
528 EGG::Vector3f lastPos = relativePos - m_movement;
529 // We're only colliding if we are moving towards the face
530 if (lastPos.ps_dot(fnrm) < 0.0f) {
531 return false;
532 }
533 }
534
535 return out(dist);
536}
537
541bool KColData::checkPointCollision(u16 prismIdx, f32 *distOut, EGG::Vector3f *fnrmOut,
542 u16 *flagsOut, bool movement) {
543 const u16 attribute = m_prismAttributes[prismIdx];
544 KCLTypeMask attrMask = KCL_ATTRIBUTE_TYPE_BIT(attribute);
545 if (!(attrMask & m_typeMask)) {
546 return false;
547 }
548
549 const KCollisionPrismGeometry &geom = m_prismGeometry[prismIdx];
550 const EGG::Vector3f relativePos = m_pos - geom.vtx;
551
552 // For Kinoko, we check the plane distance first since this is a more common early return than
553 // the edge normal checks.
554 const EGG::Vector3f &fnrm = geom.fnrm;
555 f32 plane_dist = relativePos.ps_dot(fnrm);
556 f32 dist_in_plane = 0.01f - plane_dist;
557 if (dist_in_plane <= 0.0f) {
558 return false;
559 }
560
561 const EGG::Vector3f &enrm1 = geom.enrm1;
562 f32 dist_ca = relativePos.ps_dot(enrm1);
563 if (dist_ca >= 0.01f) {
564 return false;
565 }
566
567 const EGG::Vector3f &enrm2 = geom.enrm2;
568 f32 dist_ab = relativePos.ps_dot(enrm2);
569 if (dist_ab >= 0.01f) {
570 return false;
571 }
572
573 const EGG::Vector3f &enrm3 = geom.enrm3;
574 f32 dist_bc = relativePos.ps_dot(enrm3) - geom.height;
575 if (dist_bc >= 0.01f) {
576 return false;
577 }
578
579 if (m_prismThickness <= dist_in_plane && 0.02f + m_prismThickness <= dist_in_plane) {
580 return false;
581 }
582
583 if (movement && (attrMask & KCL_TYPE_DIRECTIONAL) && m_movement.dot(fnrm) < 0.0f) {
584 return false;
585 }
586
587 if (distOut) {
588 *distOut = dist_in_plane;
589 }
590
591 if (fnrmOut) {
592 *fnrmOut = fnrm;
593 }
594
595 if (flagsOut) {
596 *flagsOut = attribute;
597 }
598
599 return true;
600}
601
608bool KColData::checkSphereMovement(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *attributeOut) {
609 // If there's no list of triangles to check, there's no collision
610 if (!m_prismIter) {
611 return false;
612 }
613
614 // Check collision for all triangles, and continuously call the function until we're out
615 while (*++m_prismIter != 0) {
616 if (checkCollision<CollisionCheckType::Movement>(parse<u16>(*m_prismIter), distOut, fnrmOut,
617 attributeOut)) {
618 return true;
619 }
620 }
621
622 // We're out of triangles to check - another list must be prepared for subsequent calls
623 m_prismIter = nullptr;
624 return false;
625}
626
628bool KColData::checkPoint(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *attributeOut) {
629 // If there's no list of triangles to check, there's no collision
630 if (!m_prismIter) {
631 return false;
632 }
633
634 // Check collision for all triangles, and continuously call the function until we're out
635 while (*++m_prismIter != 0) {
636 if (checkPointCollision(parse<u16>(*m_prismIter), distOut, fnrmOut, attributeOut, false)) {
637 return true;
638 }
639 }
640
641 // We're out of triangles to check - another list must be prepared for subsequent calls
642 m_prismIter = nullptr;
643 return false;
644}
645
647bool KColData::checkPointMovement(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *attributeOut) {
648 // If there's no list of triangles to check, there's no collision
649 if (!m_prismIter) {
650 return false;
651 }
652
653 // Check collision for all triangles, and continuously call the function until we're out
654 while (*++m_prismIter != 0) {
655 if (checkPointCollision(parse<u16>(*m_prismIter), distOut, fnrmOut, attributeOut, true)) {
656 return true;
657 }
658 }
659
660 // We're out of triangles to check - another list must be prepared for subsequent calls
661 m_prismIter = nullptr;
662 return false;
663}
664
666
668 u16 edge1NormIndex, u16 edge2NormIndex, u16 edge3NormIndex, u16 attribute)
669 : height(height),
670 pos_i(posIndex),
671 fnrm_i(faceNormIndex),
672 enrm1_i(edge1NormIndex),
673 enrm2_i(edge2NormIndex),
674 enrm3_i(edge3NormIndex),
676
677} // namespace Kinoko::Field
#define KCL_ATTRIBUTE_TYPE_BIT(x)
Given the full 2 byte KCL flag for a triangle, extracts the "Base Type" portion of the flag.
#define KCL_TYPE_DIRECTIONAL
0x05070000
A stream of data stored in memory.
Definition Stream.hh:81
void jump(u32 index)
Definition Stream.cc:16
void skip(u32 count)
Definition Stream.cc:11
bool checkSphereMovement(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *attributeOut)
Iterates the local data block to check for directional collision.
Definition KColData.cc:608
const void * m_nrmData
Definition KColData.hh:101
void narrowScopeLocal(const EGG::Vector3f &pos, f32 radius, KCLTypeMask mask)
Definition KColData.cc:57
bool checkPoint(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *attributeOut)
Definition KColData.cc:628
const u16 * searchBlock(const EGG::Vector3f &pos)
Finds the data block corresponding to the provided position.
Definition KColData.cc:224
std::array< u16, 256 > m_prismCache
Definition KColData.hh:120
bool checkSphereCollision(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut)
Definition KColData.cc:117
owning_span< KCollisionPrismGeometry > m_prismGeometry
One-indexed array of each prism's geometry.
Definition KColData.hh:128
bool checkCollision(u16 prismIdx, f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut)
This is a combination of the three collision checks in the base game.
Definition KColData.cc:349
bool checkSphereSingle(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut)
Definition KColData.cc:148
EGG::Vector3f m_prevPos
Definition KColData.hh:114
EGG::Vector3f m_pos
Definition KColData.hh:113
void lookupPoint(const EGG::Vector3f &pos, const EGG::Vector3f &prevPos, KCLTypeMask typeMask)
Sets members in preparation of a subsequent point collision check call.
Definition KColData.cc:179
owning_span< u16 > m_prismAttributes
One-indexed array of each prism's KCL attribute.
Definition KColData.hh:133
KColData(const void *file)
Definition KColData.cc:14
void preloadPrismGeometry()
Resolves each prism's vertex, height, and normal indices into a contiguous struct.
Definition KColData.cc:295
EGG::Vector3f m_movement
Definition KColData.hh:115
u32 m_areaXBlocksShift
Used to initialize octree navigation.
Definition KColData.hh:110
bool checkPointMovement(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *attributeOut)
Definition KColData.cc:647
void computeBBox()
Calculates a EGG::BoundBox3f that describes the boundary of the track's KCL.
Definition KColData.cc:90
u32 m_blockWidthShift
Used to initialize octree navigation.
Definition KColData.hh:109
const void * m_blockData
Definition KColData.hh:103
u32 m_areaXWidthMask
The x dimension of the octree's bounding box.
Definition KColData.hh:106
EGG::BoundBox3f m_bbox
Definition KColData.hh:119
const void * m_prismData
Definition KColData.hh:102
const u16 * m_prismIter
Definition KColData.hh:118
void lookupSphereCached(const EGG::Vector3f &p1, const EGG::Vector3f &p2, u32 typeMask, f32 radius)
Definition KColData.cc:201
void narrowPolygon_EachBlock(const u16 *prismArray)
Definition KColData.cc:73
void lookupSphere(f32 radius, const EGG::Vector3f &pos, const EGG::Vector3f &prevPos, KCLTypeMask typeMask)
Sets members in preparation of a subsequent sphere collision check call.
Definition KColData.cc:190
const void * m_posData
Definition KColData.hh:100
u32 m_areaXYBlocksShift
Used to initialize octree navigation.
Definition KColData.hh:111
f32 m_sphereRadius
Clamps the sphere we check collision against.
Definition KColData.hh:112
static EGG::Vector3f GetVertex(f32 height, const EGG::Vector3f &vertex1, const EGG::Vector3f &fnrm, const EGG::Vector3f &enrm3, const EGG::Vector3f &enrm)
Computes a prism vertex based off of the triangle's normal vectors.
Definition KColData.cc:282
EGG::Vector3f m_cachedPos
Definition KColData.hh:123
bool checkPointCollision(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut)
Definition KColData.cc:111
u32 m_areaYWidthMask
The y dimension of the octree's bounding box.
Definition KColData.hh:107
EGG::Vector3f m_areaMinPos
Definition KColData.hh:105
u32 m_areaZWidthMask
The z dimension of the octree's bounding box.
Definition KColData.hh:108
bool checkSphere(f32 *distOut, EGG::Vector3f *fnrmOut, u16 *flagsOut)
Iterates the list of looked-up triangles to see if we are colliding.
Definition KColData.cc:128
owning_span()
Uninitialized buffer.
Definition Types.hh:35
Pertains to collision.
float f32
Definition Memory.hh:21
uint8_t u8
Definition Memory.hh:16
uint16_t u16
Definition Memory.hh:17
int32_t s32
Definition Memory.hh:13
uint32_t u32
Definition Memory.hh:18
Represents a sphere in 3D space.
Definition Sphere.hh:8
constexpr bool isInsideOtherSphere(const Sphere3f &rhs) const
Not actually part of EGG. Included here for compartmentalization.
Definition Sphere.hh:14
A 3D float vector.
Definition Vector.hh:108
constexpr f32 ps_dot() const
Paired-singles dot product implementation.
Definition Vector.hh:257
void read(Stream &stream)
Initializes a Vector3f by reading 12 bytes from the stream.
Definition Vector.hh:376
constexpr void set(f32 val)
Definition Vector.hh:126
constexpr f32 dot(const Vector3f &rhs) const
The dot product between two vectors.
Definition Vector.hh:207
constexpr void setZero()
Definition Vector.hh:122
constexpr Vector3f cross(const Vector3f &rhs) const
Definition Vector.hh:197
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
constexpr f32 ps_squareMag() const
Differs from ps_dot due to variation in which operands are fused.
Definition Vector.hh:270
Stores the vertex, height and normals of a collision prism.
Definition KColData.hh:42
EGG::Vector3f enrm2
The second edge's normal.
Definition KColData.hh:45
EGG::Vector3f vtx
The first vertex of the tri.
Definition KColData.hh:43
EGG::Vector3f enrm1
The first edge's normal.
Definition KColData.hh:44
EGG::Vector3f enrm3
The third edge's normal.
Definition KColData.hh:46
The header of the KCL file format. It is 0x3C bytes long (for Mario Kart Wii).