MCPcopy Create free account
hub / github.com/carbonengine/trinity / PickObject

Method PickObject

trinity/ITr2PickableScene.cpp:37–165  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Picks an object and its properties in the given pixel. Arguments: renderContext - Current render context x - X viewport coordinate of the pixel to perform picking in y - Y viewport coordinate of the pixel to perform picking in proj - Current projection transform view - Current view transform viewpor

Source from the content-addressed store, hash-verified

35// of the properties).
36// --------------------------------------------------------------------------------------
37void ITr2PickableScene::PickObject( Tr2RenderContext& renderContext, int x, int y, TriProjection* proj, TriView* view, TriViewport* viewport, PickResults& results )
38{
39 CCP_STATS_ZONE( __FUNCTION__ );
40
41 // Backup current state
42 Tr2Renderer::PushProjection();
43 ON_BLOCK_EXIT( Tr2Renderer::PopProjection );
44 Tr2Renderer::PushViewTransform();
45 ON_BLOCK_EXIT( Tr2Renderer::PopViewTransform );
46 renderContext.m_esm.PushViewport();
47 ON_BLOCK_EXIT( [&] { renderContext.m_esm.PopViewport(); } );
48
49 float fx, fy;
50 Vector3 startWorld;
51 Vector3 dirWorld;
52 gTriDev->ScreenToProjection( x, y, &fx, &fy, viewport );
53
54 results.object = NULL;
55
56 if( !Tr2Renderer::GetPoolAllocator() )
57 {
58 results.components = 0;
59 return;
60 }
61
62 // Get view and projection transforms
63 Matrix projTransform;
64 proj->GetMatrixWithoutViewAdjustment( projTransform );
65 const Matrix& viewTransform = view->GetTransform();
66
67 ConvertProjectionCoordToWorldPickRay( fx, fy, &projTransform, &viewTransform, &startWorld, &dirWorld );
68
69 // Render for picking, limit our view to the pick ray
70 SetupTransformsForPicking( fx, fy, proj, view, viewport );
71 SetPerFrameDataForPicking( renderContext );
72
73 const std::vector<ITr2Renderable*>& visibleObjects = GetPickingObjectsToRender( dirWorld );
74
75 // Collect vector of objects to render
76 std::vector<ITr2Renderable*> pickableObjects;
77 for( std::vector<ITr2Renderable*>::const_iterator it = visibleObjects.begin(); it != visibleObjects.end(); ++it )
78 {
79 ITr2PickablePtr pickedObj( BlueCastPtr( *it ) );
80 if( pickedObj )
81 {
82 pickableObjects.push_back( *it );
83 }
84 }
85
86 PickComponents passes[MAX_PICK_PASSES];
87 unsigned int count = GetRequiredPasses( results.components, passes );
88
89 results.components = 0;
90
91 if( !pickableObjects.empty() )
92 {
93 if( count == 0 )
94 {

Callers 1

PyPickPointAndObjectFunction · 0.45

Calls 15

GetBatchesFunction · 0.85
GetFrontClipFunction · 0.85
PushViewportMethod · 0.80
PopViewportMethod · 0.80
ScreenToProjectionMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.80
GetTransformMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected