Fix Pick distance calculation (#751)

This commit is contained in:
Christian Semmler 2025-12-25 16:03:07 -07:00 committed by GitHub
parent 6531ac4083
commit 0dfbcc901f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -802,16 +802,21 @@ HRESULT Direct3DRMViewportImpl::Pick(float x, float y, LPDIRECT3DRMPICKEDARRAY*
ComputeFrameWorldMatrix(frame, worldMatrix);
D3DRMBOX worldBox = ComputeTransformedAABB(box, worldMatrix);
float distance = FLT_MAX;
if (RayIntersectsBox(pickRay, worldBox, distance) &&
RayIntersectsMeshTriangles(pickRay, *mesh, worldMatrix, distance)) {
auto* arr = new Direct3DRMFrameArrayImpl();
for (IDirect3DRMFrame* f : path) {
arr->AddElement(f);
}
float boxDist = FLT_MAX;
PickRecord rec = {visual, arr, {distance}};
hits.push_back(rec);
// Check box first as an optimization
if (RayIntersectsBox(pickRay, worldBox, boxDist)) {
float meshDist = FLT_MAX;
if (RayIntersectsMeshTriangles(pickRay, *mesh, worldMatrix, meshDist)) {
auto* arr = new Direct3DRMFrameArrayImpl();
for (IDirect3DRMFrame* f : path) {
arr->AddElement(f);
}
PickRecord rec = {visual, arr, {meshDist}};
hits.push_back(rec);
}
}
mesh->Release();
}