MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / mProjectScreenToWorld

Function mProjectScreenToWorld

Engine/source/math/mathUtils.cpp:481–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479//-----------------------------------------------------------------------------
480
481void mProjectScreenToWorld( const Point3F &in,
482 Point3F *out,
483 const RectI &view,
484 const MatrixF &world,
485 const MatrixF &projection,
486 F32 zfar,
487 F32 znear )
488{
489 MatrixF invWorldProjection = projection;
490 invWorldProjection.mul(world);
491 invWorldProjection.inverse();
492
493 Point3F vec;
494 vec.x = (in.x - view.point.x) * 2.0f / view.extent.x - 1.0f;
495 vec.y = -(in.y - view.point.y) * 2.0f / view.extent.y + 1.0f;
496 vec.z = (znear + in.z * (zfar - znear))/zfar;
497
498 invWorldProjection.mulV(vec);
499 vec *= 1.0f + in.z * zfar;
500
501 invWorldProjection.getColumn(3, out);
502 (*out) += vec;
503}
504
505//-----------------------------------------------------------------------------
506

Callers 1

unprojectMethod · 0.85

Calls 4

mulVMethod · 0.80
getColumnMethod · 0.80
mulMethod · 0.45
inverseMethod · 0.45

Tested by

no test coverage detected