{"_id":"camera-picking-ray","_rev":"4-19aab36f79667593a3d14580521a3785","name":"camera-picking-ray","description":"creates a picking ray for a 2D/3D camera","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"camera-picking-ray","version":"1.0.0","description":"creates a picking ray for a 2D/3D camera","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"camera-unproject":"^1.0.1","gl-vec3":"^1.0.3"},"devDependencies":{"gl-mat4":"^1.1.3","gl-vec3":"^1.0.3","tape":"^4.0.0","test-fuzzy-array":"^1.0.1"},"scripts":{"test":"node test.js"},"keywords":["pick","picking","intersect","intersection","ray","rays","hit","test","unproject","project","collision","mouse","touch","2d","3d","projection","perspective"],"repository":{"type":"git","url":"git://github.com/Jam3/camera-picking-ray.git"},"homepage":"https://github.com/Jam3/camera-picking-ray","bugs":{"url":"https://github.com/Jam3/camera-picking-ray/issues"},"gitHead":"1aed76a5a0716a0ea471f6c617f9322958d517e8","_id":"camera-picking-ray@1.0.0","_shasum":"9cb05d97e2cba24d538440575acc8367aea514cc","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"9cb05d97e2cba24d538440575acc8367aea514cc","tarball":"https://registry.npmjs.org/camera-picking-ray/-/camera-picking-ray-1.0.0.tgz","integrity":"sha512-pyKhGmml/+qtuE1PikMC+Nbpm692HkJ/t/s5UvjLaKE4HavC3+Tmmy6SkIBkx7nIhY2V0KFk5wc/JSLk790Kag==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDFmGjgPSqSVYa4PezjqRocXdNU8kOVvS6SAzYDQtdxHAiAI7DiYhhEsCb8SRCd+moN/RAJUh4R8U/3VXR4d5UA7fQ=="}]},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}]},"1.0.1":{"name":"camera-picking-ray","version":"1.0.1","description":"creates a picking ray for a 2D/3D camera","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"camera-unproject":"^1.0.1","gl-vec3":"^1.0.3"},"devDependencies":{"gl-mat4":"^1.1.3","gl-vec3":"^1.0.3","tape":"^4.0.0","test-fuzzy-array":"^1.0.1"},"scripts":{"test":"node test.js"},"keywords":["pick","picking","intersect","intersection","ray","rays","hit","test","unproject","project","collision","mouse","touch","2d","3d","projection","perspective"],"repository":{"type":"git","url":"git://github.com/Jam3/camera-picking-ray.git"},"homepage":"https://github.com/Jam3/camera-picking-ray","bugs":{"url":"https://github.com/Jam3/camera-picking-ray/issues"},"gitHead":"446aecdd8e83c339a7d90688a70cb075897b8424","_id":"camera-picking-ray@1.0.1","_shasum":"49567a4edc2de5bc13e4b6fd959520bf13a30490","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"49567a4edc2de5bc13e4b6fd959520bf13a30490","tarball":"https://registry.npmjs.org/camera-picking-ray/-/camera-picking-ray-1.0.1.tgz","integrity":"sha512-gjZ7L/zmuM+/3CqDrEIDSJ2fXemoANW9mr31HxeJ1SaBw1n/hJU7IOQwcSVqq84/5BCwG3CSEMRyLv9zkeKIsg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDLGPhi167bsKZ1RIKw1e44dnz8EK+IYzBZCLzZIK5jxwIgIS1HlG3FcXDzR+VFYxkEn5tnsbvrbAbuThZZD41MftA="}]},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}]}},"readme":"# camera-picking-ray\n\n[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)\n\nCreates a picking ray for a camera. Commonly used for mouse interaction in 2D and 3D games.\n\nThe camera is assumed to have a `projection` and `view` matrix, which can be combined and inverted to form `invProjView`. \n\n```js\nvar origin = [0, 0, 0]\nvar direction = [0, 0, 0]\n\n//compute ray and store it in (origin, direction)\npick(origin, direction, mouse, viewport, invProjView)\n\nconsole.log(origin, direction)\n```\n\nFull example, hit-testing against a 3D sphere:\n\n```js\nvar mat4 = require('gl-mat4')\nvar pick = require('camera-picking-ray')\nvar intersect = require('ray-sphere-intersection')\n\n//your camera matrices\nvar projection = ...\nvar view = ...\nvar projView = mat4.multiply([], projection, view)\nvar invProjView = mat4.invert([], projView)\n\nvar mouse = [ screenX, screenHeight - screenY ]\nvar viewport = [ 0, 0, screenWidth, screenHeight ]\n\nvar ray = {\n  ro: [0, 0, 0],\n  rd: [0, 0, 0]\n}\n\n//store result in ray (origin, direction)\npick(ray.ro, ray.rd, mouse, viewport, invProjView)\n\n//let's see if the mouse hit a 3D sphere...\nvar center = [0, 0, 0],\n    radius = 1.5\nvar hit = intersect([], ray.ro, ray.rd, center, radius)\n\nif (hit) {\n  console.log(\"Mouse hit the sphere at:\", hit)\n}\n```\n\nPRs welcome.\n\n## Usage\n\n[![NPM](https://nodei.co/npm/camera-picking-ray.png)](https://www.npmjs.com/package/camera-picking-ray)\n\n#### `pick(origin, direction, mouse, viewport, invProjView)`\n\nCreates a picking ray for the given `mouse` screen-space position (vec2) and `viewport` screen-space bounds (x, y, width, height). `invProjView` is the inverse of the combined `projection * view` matrix for your camera.\n\nStores the resulting ray in the first two parameters: `origin` (vec3) and `direction` (vec3).\n\n## See Also\n\n- [ray-sphere-intersection](https://www.npmjs.com/package/ray-sphere-intersection)\n- [ray-triangle-intersection](https://www.npmjs.com/package/ray-triangle-intersection)\n- [ray-plane-intersection](https://www.npmjs.com/package/ray-plane-intersection)\n- [ray-aabb](https://www.npmjs.com/package/ray-aabb)\n- [camera-unproject](https://www.npmjs.com/package/camera-unproject)\n\n## License\n\nMIT, see [LICENSE.md](http://github.com/Jam3/camera-picking-ray/blob/master/LICENSE.md) for details.\n","maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"time":{"modified":"2022-06-13T05:30:37.757Z","created":"2015-05-15T14:53:12.855Z","1.0.0":"2015-05-15T14:53:12.855Z","1.0.1":"2015-05-15T17:09:04.668Z"},"homepage":"https://github.com/Jam3/camera-picking-ray","keywords":["pick","picking","intersect","intersection","ray","rays","hit","test","unproject","project","collision","mouse","touch","2d","3d","projection","perspective"],"repository":{"type":"git","url":"git://github.com/Jam3/camera-picking-ray.git"},"author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"bugs":{"url":"https://github.com/Jam3/camera-picking-ray/issues"},"license":"MIT","readmeFilename":"README.md"}