From a3b4058bf7266f1291cf38c30425d9948250fcd9 Mon Sep 17 00:00:00 2001 From: Branimir Karadžić Date: Sat, 29 Oct 2016 09:11:50 +0200 Subject: Updated BGFX and BX and recompiled shaders (nw) --- 3rdparty/bgfx/examples/30-picking/picking.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to '3rdparty/bgfx/examples/30-picking/picking.cpp') diff --git a/3rdparty/bgfx/examples/30-picking/picking.cpp b/3rdparty/bgfx/examples/30-picking/picking.cpp index 4ed99066cae..a4fc99ffe7c 100644 --- a/3rdparty/bgfx/examples/30-picking/picking.cpp +++ b/3rdparty/bgfx/examples/30-picking/picking.cpp @@ -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 mousePosNDC[4] = { mouseXNDC, mouseYNDC, 0, 1.0f }; - // Unproject and perspective divide - bx::vec4MulMtx(pickAt, mousePosNDC, 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); -- cgit v1.2.3-70-g09d2