Fix Pick distance calculation

This commit is contained in:
Christian Semmler 2025-12-25 09:58:40 -07:00
parent 6531ac4083
commit 45c91d4ca7

View File

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