{"action":"closed","issue":{"url":"https://api.github.com/repos/x3dom/x3dom/issues/821","repository_url":"https://api.github.com/repos/x3dom/x3dom","labels_url":"https://api.github.com/repos/x3dom/x3dom/issues/821/labels{/name}","comments_url":"https://api.github.com/repos/x3dom/x3dom/issues/821/comments","events_url":"https://api.github.com/repos/x3dom/x3dom/issues/821/events","html_url":"https://github.com/x3dom/x3dom/issues/821","id":297873780,"number":821,"title":"zNear bug: shootRay() returns incorrect coordinates when zNear is comparable to crossing distance","user":{"login":"okdzhimiev","id":7122484,"avatar_url":"https://avatars3.githubusercontent.com/u/7122484?v=4","gravatar_id":"","url":"https://api.github.com/users/okdzhimiev","html_url":"https://github.com/okdzhimiev","followers_url":"https://api.github.com/users/okdzhimiev/followers","following_url":"https://api.github.com/users/okdzhimiev/following{/other_user}","gists_url":"https://api.github.com/users/okdzhimiev/gists{/gist_id}","starred_url":"https://api.github.com/users/okdzhimiev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okdzhimiev/subscriptions","organizations_url":"https://api.github.com/users/okdzhimiev/orgs","repos_url":"https://api.github.com/users/okdzhimiev/repos","events_url":"https://api.github.com/users/okdzhimiev/events{/privacy}","received_events_url":"https://api.github.com/users/okdzhimiev/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2018-02-16T18:10:26Z","updated_at":"2018-02-21T02:52:42Z","closed_at":"2018-02-21T02:52:42Z","author_association":"NONE","body":"Hi,\r\nWhile implementing dragging of a sphere over a surface (using shootRay function) I have noticed that for 'close' objects the ray's pickPosition is incorrect which results in in placing center of the sphere farther along the ray than it should by zNear value.\r\n\r\nFIX:\r\nCouldn't find a place in the x3dom.js right away, so I made a fix in the outer code:\r\n[x3dom_functions.js#L360](https://github.com/Elphel/x3domlet/blob/master/js/x3dom_functions.js#L360)\r\n\r\n[Demo](https://community.elphel.com/3d+map/viewer.html?path=1488237915_992276&ver=x3d316&rating=5) - move cursor around with **ctrl** pressed.\r\n\r\nHere's a cleaner version:\r\n```\r\nvar Element = document.getElementById('x3d_id');\r\n\r\nfunction shootRay_fixed(x,y){\r\n  var ray =  Element.runtime.shootRay(x,y);\r\n  ray.pickPosition = zNear_bug_correction(ray.pickPosition);\r\n  return ray;\r\n}\r\n\r\nfunction zNear_bug_correction(vec){\r\n  var mat = Element.runtime.viewMatrix();\r\n  var zNear = Element.runtime.viewpoint().getNear();\r\n\r\n  var vec_cam = mat.multFullMatrixPnt(vec);\r\n  var z1 = vec_cam.z + zNear;\r\n  var zratio = z1 / vec_cam.z;\r\n\r\n  vec_cam.x = zratio*vec_cam.x;\r\n  vec_cam.y = zratio*vec_cam.y;\r\n  vec_cam.z = z1;\r\n\r\n  vec_out = mat.inverse().multFullMatrixPnt(vec_cam);\r\n  return vec_out;\r\n}\r\n```\r\n\r\n\r\n"}}
{"actor":{"display_login":"andreasplesch"}}