summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/30-picking/picking.cpp
diff options
context:
space:
mode:
author Branimir Karadžić <branimirkaradzic@gmail.com>2016-10-29 09:11:50 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2016-10-29 09:11:50 +0200
commita3b4058bf7266f1291cf38c30425d9948250fcd9 (patch)
tree46116c48b60368ac9c782c1d5e6e8ae16e558987 /3rdparty/bgfx/examples/30-picking/picking.cpp
parentb99be73f2db5d3f81edc96a92ac4839e7f1cc3ab (diff)
Updated BGFX and BX and recompiled shaders (nw)
Diffstat (limited to '3rdparty/bgfx/examples/30-picking/picking.cpp')
-rw-r--r--3rdparty/bgfx/examples/30-picking/picking.cpp26
1 files changed, 14 insertions, 12 deletions
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);