| 513 | |
| 514 | |
| 515 | void AABBTree::TraceRecursive(uint32_t nodeIndex, const Vec3& start, const Vector3& dir, float& outT, float& outU, float& outV, float& outW, float& faceSign, uint32_t& faceIndex) const |
| 516 | { |
| 517 | const Node& node = m_nodes[nodeIndex]; |
| 518 | |
| 519 | if (node.m_faces == NULL) |
| 520 | { |
| 521 | #if _WIN32 |
| 522 | ++s_traceDepth; |
| 523 | #endif |
| 524 | |
| 525 | #if TRACE_STATS |
| 526 | extern uint32_t g_nodesChecked; |
| 527 | ++g_nodesChecked; |
| 528 | #endif |
| 529 | |
| 530 | // find closest node |
| 531 | const Node& leftChild = m_nodes[node.m_children+0]; |
| 532 | const Node& rightChild = m_nodes[node.m_children+1]; |
| 533 | |
| 534 | float dist[2] = {FLT_MAX, FLT_MAX}; |
| 535 | |
| 536 | IntersectRayAABB(start, dir, leftChild.m_minExtents, leftChild.m_maxExtents, dist[0], NULL); |
| 537 | IntersectRayAABB(start, dir, rightChild.m_minExtents, rightChild.m_maxExtents, dist[1], NULL); |
| 538 | |
| 539 | uint32_t closest = 0; |
| 540 | uint32_t furthest = 1; |
| 541 | |
| 542 | if (dist[1] < dist[0]) |
| 543 | { |
| 544 | closest = 1; |
| 545 | furthest = 0; |
| 546 | } |
| 547 | |
| 548 | if (dist[closest] < outT) |
| 549 | TraceRecursive(node.m_children+closest, start, dir, outT, outU, outV, outW, faceSign, faceIndex); |
| 550 | |
| 551 | if (dist[furthest] < outT) |
| 552 | TraceRecursive(node.m_children+furthest, start, dir, outT, outU, outV, outW, faceSign, faceIndex); |
| 553 | |
| 554 | } |
| 555 | else |
| 556 | { |
| 557 | Vector3 normal; |
| 558 | float t, u, v, w, s; |
| 559 | |
| 560 | for (uint32_t i=0; i < node.m_numFaces; ++i) |
| 561 | { |
| 562 | uint32_t indexStart = node.m_faces[i]*3; |
| 563 | |
| 564 | const Vec3& a = m_vertices[m_indices[indexStart+0]]; |
| 565 | const Vec3& b = m_vertices[m_indices[indexStart+1]]; |
| 566 | const Vec3& c = m_vertices[m_indices[indexStart+2]]; |
| 567 | #if TRACE_STATS |
| 568 | extern uint32_t g_trisChecked; |
| 569 | ++g_trisChecked; |
| 570 | #endif |
| 571 | |
| 572 | if (IntersectRayTriTwoSided(start, dir, a, b, c, t, u, v, w, s)) |
nothing calls this directly
no test coverage detected