mirror of https://github.com/bkaradzic/bgfx
Cleanup. Issue #929.
This commit is contained in:
parent
483d31473f
commit
ab021e0724
|
@ -214,30 +214,32 @@ class ExamplePicking : public entry::AppI
|
|||
bgfx::setViewTransform(RENDER_PASS_SHADING, view, proj);
|
||||
|
||||
// Set up picking pass
|
||||
float pickView[16];
|
||||
float pickAt[4]; // Need to inversly project the mouse pointer to determin what we're looking at
|
||||
float pickEye[3] = { eye[0], eye[1], eye[2] }; // Eye is same location as before
|
||||
float viewProj[16];
|
||||
bx::mtxMul(viewProj, view, proj);
|
||||
|
||||
float invViewProj[16];
|
||||
bx::mtxInverse(invViewProj, viewProj);
|
||||
|
||||
// Mouse coord in NDC
|
||||
float mouseXNDC = (m_mouseState.m_mx / (float)m_width) * 2.0f - 1.0f;
|
||||
float mouseXNDC = ( m_mouseState.m_mx / (float)m_width ) * 2.0f - 1.0f;
|
||||
float mouseYNDC = ((m_height - m_mouseState.m_my) / (float)m_height) * 2.0f - 1.0f;
|
||||
float mousePosNDCEnd[4] = { mouseXNDC, mouseYNDC, 1.0f, 1.0f };
|
||||
// Unproject and perspective divide
|
||||
bx::vec4MulMtx(pickAt, mousePosNDCEnd, invViewProj);
|
||||
pickAt[3] = 1.0f / pickAt[3];
|
||||
pickAt[0] *= pickAt[3];
|
||||
pickAt[1] *= pickAt[3];
|
||||
pickAt[2] *= pickAt[3];
|
||||
|
||||
float pickEye[3];
|
||||
float mousePosNDC[3] = { mouseXNDC, mouseYNDC, 0.0f };
|
||||
bx::vec3MulMtxH(pickEye, mousePosNDC, invViewProj);
|
||||
|
||||
float pickAt[3];
|
||||
float mousePosNDCEnd[3] = { mouseXNDC, mouseYNDC, 1.0f };
|
||||
bx::vec3MulMtxH(pickAt, mousePosNDCEnd, invViewProj);
|
||||
|
||||
// Look at our unprojected point
|
||||
float pickView[16];
|
||||
bx::mtxLookAt(pickView, pickEye, pickAt);
|
||||
float pickProj[16];
|
||||
|
||||
// Tight FOV is best for picking
|
||||
float pickProj[16];
|
||||
bx::mtxProj(pickProj, m_fov, 1, 0.1f, 100.0f);
|
||||
|
||||
// View rect and transforms for picking pass
|
||||
bgfx::setViewRect(RENDER_PASS_ID, 0, 0, ID_DIM, ID_DIM);
|
||||
bgfx::setViewTransform(RENDER_PASS_ID, pickView, pickProj);
|
||||
|
|
Loading…
Reference in New Issue