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

Method PickObject

trinity/Sprite2d/Tr2Sprite2dScene.cpp:295–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293}
294
295ITr2SpriteObject* Tr2Sprite2dScene::PickObject( int x, int y, const TriProjection* proj, const TriView* view, const TriViewport* vp, Be::Optional<int> )
296{
297 CCP_ASSERT( m_transformStack->empty() );
298
299 float finalX;
300 float finalY;
301 if( !m_is2dPick )
302 {
303 float fx, fy;
304 Vector3 startWorld;
305 Vector3 dirWorld;
306
307 gTriDev->ScreenToProjection( x, y, &fx, &fy, vp );
308
309 Matrix worldTransform = TransformationMatrix( m_scaling, m_rotation, m_translation );
310
311 Matrix worldViewTransform;
312 Matrix viewTransform = view->GetTransform();
313 worldViewTransform = worldTransform * viewTransform;
314
315 Matrix worldViewProjectionTransform;
316 Matrix projectionTransform = proj->GetTransform();
317 worldViewProjectionTransform = worldViewTransform * projectionTransform;
318
319 Matrix invWorldViewProjectionTransform = Inverse( worldViewProjectionTransform );
320
321 Vector3 rayStart = TransformCoord( Vector3( fx, fy, 0.0f ), invWorldViewProjectionTransform );
322
323 Vector3 rayEnd = TransformCoord( Vector3( fx, fy, 0.5f ), invWorldViewProjectionTransform );
324
325 float slopeX = ( rayEnd.z - rayStart.z ) / ( rayEnd.x - rayStart.x );
326 finalX = ( slopeX * rayStart.x - rayStart.z ) / slopeX;
327
328 float slopeY = ( rayEnd.z - rayStart.z ) / ( rayEnd.y - rayStart.y );
329 finalY = ( slopeY * rayStart.y - rayStart.z ) / slopeY;
330
331 finalY = 1.0f - finalY;
332
333 if( m_is2dRender )
334 {
335 finalX *= m_displayWidth;
336 finalY *= m_displayHeight;
337 finalX += m_displayWidth / 2.0f;
338 finalY -= m_displayHeight / 2.0f;
339 }
340 else
341 {
342 // Rendering
343 finalX += m_displayWidth / 2.0f;
344 finalY += m_displayHeight / 2.0f;
345 }
346
347 extern ITr2DebugRendererPtr g_debugRenderer;
348 if( g_debugRenderer )
349 {
350 g_debugRenderer->DrawLine( rayStart, rayEnd );
351 g_debugRenderer->Printf( 50, 50, 0xffffffff, "%d, %d, %d, %d", vp->x, vp->y, vp->width, vp->height );
352 g_debugRenderer->Printf( 50, 60, 0xffffffff, "%4.2f, %4.2f, %4.2f", rayStart.x, rayStart.y, rayStart.z );

Callers

nothing calls this directly

Calls 9

emptyMethod · 0.80
ScreenToProjectionMethod · 0.80
Vector3Class · 0.50
GetTransformMethod · 0.45
DrawLineMethod · 0.45
PrintfMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
PickPointMethod · 0.45

Tested by

no test coverage detected