| 3550 | } |
| 3551 | |
| 3552 | void EveSpaceScene::PerformPicking( EvePickingContext* listener, bool immediate, int x, int y, TriProjection* proj, TriView* view, TriViewport* viewport, Tr2PickTypes pickTypes, Tr2PrimaryRenderContext& renderContext ) |
| 3553 | { |
| 3554 | if( !renderContext.IsValid() ) |
| 3555 | { |
| 3556 | return; |
| 3557 | } |
| 3558 | |
| 3559 | float fx, fy; |
| 3560 | Vector3 startWorld; |
| 3561 | Vector3 dirWorld; |
| 3562 | gTriDev->ScreenToProjection( x, y, &fx, &fy, viewport ); |
| 3563 | |
| 3564 | // Get view and projection transforms |
| 3565 | Matrix projTransform; |
| 3566 | proj->GetMatrixWithoutViewAdjustment( projTransform ); |
| 3567 | const Matrix& viewTransform = view->GetTransform(); |
| 3568 | |
| 3569 | ConvertProjectionCoordToWorldPickRay( fx, fy, &projTransform, &viewTransform, &startWorld, &dirWorld ); |
| 3570 | |
| 3571 | EvePendingPickingReadback& readback = *listener->m_readbacks.emplace_back( std::make_unique<EvePendingPickingReadback>( x, y ) ); |
| 3572 | |
| 3573 | |
| 3574 | |
| 3575 | // Backup current state |
| 3576 | Tr2Renderer::PushProjection(); |
| 3577 | ON_BLOCK_EXIT( Tr2Renderer::PopProjection ); |
| 3578 | Tr2Renderer::PushViewTransform(); |
| 3579 | ON_BLOCK_EXIT( Tr2Renderer::PopViewTransform ); |
| 3580 | renderContext.m_esm.PushViewport(); |
| 3581 | ON_BLOCK_EXIT( [&] { renderContext.m_esm.PopViewport(); } ); |
| 3582 | |
| 3583 | // Render for picking, limit our view to the pick ray |
| 3584 | SetupTransformsForPicking( fx, fy, proj, view, viewport, renderContext ); |
| 3585 | |
| 3586 | |
| 3587 | if( m_debugRenderer ) |
| 3588 | { |
| 3589 | m_debugRenderer->Pick( readback, immediate, renderContext ); |
| 3590 | } |
| 3591 | |
| 3592 | std::vector<ITr2Renderable*> visibleObjects; |
| 3593 | GetPickingObjectsToRender( visibleObjects ); |
| 3594 | |
| 3595 | |
| 3596 | std::vector<std::pair<ITr2PickablePtr, ITr2Renderable*>>& collisionSet = readback.m_collisionSet; |
| 3597 | collisionSet.reserve( visibleObjects.size() ); |
| 3598 | |
| 3599 | for( std::vector<ITr2Renderable*>::const_iterator it = visibleObjects.begin(); it != visibleObjects.end(); ++it ) |
| 3600 | { |
| 3601 | ITr2PickablePtr pickedObj( BlueCastPtr( *it ) ); |
| 3602 | if( pickedObj ) |
| 3603 | { |
| 3604 | collisionSet.push_back( std::make_pair( pickedObj, *it ) ); |
| 3605 | } |
| 3606 | } |
| 3607 | |
| 3608 | // Get batches from shared instanced meshes |
| 3609 | { |
nothing calls this directly
no test coverage detected