{"_id":"perspective-camera","_rev":"8-b19ab512b733a4baf4ebdbf3223895e9","name":"perspective-camera","description":"a high-level 3D perspective camera","dist-tags":{"latest":"2.0.1"},"versions":{"1.0.0":{"name":"perspective-camera","version":"1.0.0","description":"a high-level 3D perspective camera","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"camera-picking-ray":"^1.0.0","camera-unproject":"^1.0.1","defined":"^1.0.0","gl-mat4":"^1.1.3","gl-vec3":"^1.0.3","object-assign":"^2.0.0","ray-3d":"^1.0.2"},"devDependencies":{"2d-context":"^1.2.0","array-range":"^1.0.1","browserify":"^10.2.0","budo":"^4.0.0","bunny":"^1.0.1","camera-project":"^1.0.2","canvas-fit-loop":"^1.0.2","draw-triangles-2d":"^1.0.0","garnish":"^2.1.3","icosphere":"^1.0.0","tape":"^4.0.0","touch-position":"^1.0.3","uglify-js":"^2.4.21"},"scripts":{"start":"budo demo/canvas.js --live --verbose | garnish","build":"browserify demo/canvas.js | uglifyjs -cm > bundle.js"},"keywords":["perspective","projection","rendering","3d","webgl","glsl","stackgl","gl-mat4","matrix","matrices","mat4","ray","pick","intersection"],"repository":{"type":"git","url":"git://github.com/Jam3/perspective-camera.git"},"homepage":"https://github.com/Jam3/perspective-camera","bugs":{"url":"https://github.com/Jam3/perspective-camera/issues"},"gitHead":"551d01ab0dbea64289c690fcf99d7d226f1b7bdb","_id":"perspective-camera@1.0.0","_shasum":"834fdd32e59490db8012eb720c3e5f6eac12de6c","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"834fdd32e59490db8012eb720c3e5f6eac12de6c","tarball":"https://registry.npmjs.org/perspective-camera/-/perspective-camera-1.0.0.tgz","integrity":"sha512-4PDqM4JE/yDD2RDwbzc2JnmQ4vrlD+4qY9YPD2mEdyt2t1y5RCxIv469CMtpFUpBlA1Qp3A0w/qhbSbVtxuSTQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEflmqpKyNyfOgj6ZAJvamoyXuJLvJBcs4sZpMBUXF/oAiEA3fZoS0IfBCNmaRnyblmu50HSFDCSINJeOOfAaFDhnk4="}]},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}]},"1.0.1":{"name":"perspective-camera","version":"1.0.1","description":"a high-level 3D perspective camera","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"camera-picking-ray":"^1.0.0","camera-unproject":"^1.0.1","defined":"^1.0.0","gl-mat4":"^1.1.3","gl-vec3":"^1.0.3","camera-project":"^1.0.2","object-assign":"^2.0.0","ray-3d":"^1.0.2"},"devDependencies":{"2d-context":"^1.2.0","array-range":"^1.0.1","browserify":"^10.2.0","budo":"^4.0.0","bunny":"^1.0.1","canvas-fit-loop":"^1.0.2","draw-triangles-2d":"^1.0.0","garnish":"^2.1.3","icosphere":"^1.0.0","tape":"^4.0.0","touch-position":"^1.0.3","uglify-js":"^2.4.21"},"scripts":{"start":"budo demo/canvas.js --live --verbose | garnish","build":"browserify demo/canvas.js | uglifyjs -cm > bundle.js"},"keywords":["perspective","projection","rendering","3d","webgl","glsl","stackgl","gl-mat4","matrix","matrices","mat4","ray","pick","intersection"],"repository":{"type":"git","url":"git://github.com/Jam3/perspective-camera.git"},"homepage":"https://github.com/Jam3/perspective-camera","bugs":{"url":"https://github.com/Jam3/perspective-camera/issues"},"gitHead":"eab5d6a061d6ad1f037980e24e9f98c21c68a55b","_id":"perspective-camera@1.0.1","_shasum":"3719b1b2dfb8c4901ca6e659f1f066213689ce00","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"3719b1b2dfb8c4901ca6e659f1f066213689ce00","tarball":"https://registry.npmjs.org/perspective-camera/-/perspective-camera-1.0.1.tgz","integrity":"sha512-qRkKABWh174uSDDAbZyxjxtQpctBr032l/tdgjH6nlWIxfBm5yaCs6oIAJ/buizXzGm49IzilfApi5eptd7kfg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD0ItpwykEPHocRU//YkgZbfN9422zyxCJ8ieMuOy8F4gIgPnWdKMPAk6twht9um+sOudaghWVqfhDVs1UoDg/pBks="}]},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}]},"2.0.0":{"name":"perspective-camera","version":"2.0.0","description":"a high-level 3D perspective camera","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"camera-picking-ray":"^1.0.0","camera-project":"^1.0.2","camera-unproject":"^1.0.1","canvas-loop":"^1.0.4","defined":"^1.0.0","gl-mat4":"^1.1.3","gl-vec3":"^1.0.3","object-assign":"^2.0.0","ray-3d":"^1.0.2"},"devDependencies":{"2d-context":"^1.2.0","array-range":"^1.0.1","browserify":"^10.2.0","budo":"^4.0.0","bunny":"^1.0.1","draw-triangles-2d":"^1.0.0","garnish":"^2.1.3","icosphere":"^1.0.0","tape":"^4.0.0","touch-position":"^1.0.3","uglify-js":"^2.4.21"},"scripts":{"start":"budo demo/canvas.js:bundle.js --live --verbose | garnish","build":"browserify demo/canvas.js | uglifyjs -cm > bundle.js"},"keywords":["perspective","projection","rendering","3d","webgl","glsl","stackgl","gl-mat4","matrix","matrices","mat4","ray","pick","intersection"],"repository":{"type":"git","url":"git://github.com/Jam3/perspective-camera.git"},"homepage":"https://github.com/Jam3/perspective-camera","bugs":{"url":"https://github.com/Jam3/perspective-camera/issues"},"gitHead":"db51d87f84b8e42a9292bd9b0e23842038444561","_id":"perspective-camera@2.0.0","_shasum":"361c5bd5e4ee57aad4983890cd086d9b46f0f7bf","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"361c5bd5e4ee57aad4983890cd086d9b46f0f7bf","tarball":"https://registry.npmjs.org/perspective-camera/-/perspective-camera-2.0.0.tgz","integrity":"sha512-4LpupHe8O5rt+C3PA0F5FwQARqmoeVRlnmOl3dIRuY1aIP+MaY2iPhehs1t6uFXh6bsLwVhI1IyA/QrxeW0y2g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBFLPQF1KjqCC90OJ9QovCFprFJ819EbSQ7xsk/FPyFkAiB9bXB9Xjm/9mxuCOG2T0vLxq1O+QHFfCOSPekHb5F60w=="}]},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}]},"2.0.1":{"name":"perspective-camera","version":"2.0.1","description":"a high-level 3D perspective camera","main":"index.js","license":"MIT","author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"camera-picking-ray":"^1.0.0","camera-project":"^1.0.2","camera-unproject":"^1.0.1","defined":"^1.0.0","gl-mat4":"^1.1.3","gl-vec3":"^1.0.3","object-assign":"^2.0.0","ray-3d":"^1.0.2"},"devDependencies":{"canvas-loop":"^1.0.4","2d-context":"^1.2.0","array-range":"^1.0.1","browserify":"^10.2.0","budo":"^4.0.0","bunny":"^1.0.1","draw-triangles-2d":"^1.0.0","garnish":"^2.1.3","icosphere":"^1.0.0","tape":"^4.0.0","touch-position":"^1.0.3","uglify-js":"^2.4.21"},"scripts":{"start":"budo demo/canvas.js:bundle.js --live --verbose | garnish","build":"browserify demo/canvas.js | uglifyjs -cm > bundle.js"},"keywords":["perspective","projection","rendering","3d","webgl","glsl","stackgl","gl-mat4","matrix","matrices","mat4","ray","pick","intersection"],"repository":{"type":"git","url":"git://github.com/Jam3/perspective-camera.git"},"homepage":"https://github.com/Jam3/perspective-camera","bugs":{"url":"https://github.com/Jam3/perspective-camera/issues"},"gitHead":"0692fab05c521cfbc99f4fb00bbd0fef7c465a76","_id":"perspective-camera@2.0.1","_shasum":"7593e47eba0b7038b81ce698db344f125a3b3625","_from":".","_npmVersion":"2.14.5","_nodeVersion":"0.12.7","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"7593e47eba0b7038b81ce698db344f125a3b3625","tarball":"https://registry.npmjs.org/perspective-camera/-/perspective-camera-2.0.1.tgz","integrity":"sha512-x1HuRatZxklmQxbVO6Tk5ONoDDOVoSCS/Lgp8ROxouLfPv83p68FUw9b4uw9VDugvnvRQl6YPoOYYbuaGmcYoQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCf+SnVrAYpl8DuWKqu47ivFkjAbGt+sh34BA/HKmYygwIgP4kuaQDTZRsSeIbbNgDmESgeEdqy1abchuAq/tSgc8M="}]},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}]}},"readme":"# perspective-camera\n\n[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)\n\n[![demo-image](http://i.imgur.com/anR1By6.png)](http://jam3.github.io/perspective-camera/)\n\n[demo](http://jam3.github.io/perspective-camera/) - [source](demo/canvas.js)\n\nA high-level 3D perspective camera with a familiar and convenient interface, built from modular pieces.\n\n```js\nvar createCamera = require('perspective-camera')\n\nvar camera = createCamera({\n  fov: Math.PI/4,\n  near: 0.01,\n  far: 100,\n  viewport: [0, 0, width, height]\n})\n\n//set up our camera\ncamera.translate([ x, y, z ])\ncamera.lookAt([ 0, 0, 0 ])\ncamera.update()\n\n//do some 3D hit-testing\nvar ray = camera.createPickingRay(mouseInput)\n\nif (ray.intersectsSphere(center, radius)) {\n  console.log(\"Mouse hit 3D sphere!\")\n}\n```\n\nSee [demo/canvas.js](demo/canvas.js) for a full example, using Canvas2D.\n\n## Usage\n\n[![NPM](https://nodei.co/npm/perspective-camera.png)](https://www.npmjs.com/package/perspective-camera)\n\n#### `camera = createCamera([opts])`\n\nCreates a new camera with options:\n\n- `fov` field of view in radians, default `Math.PI / 4`\n- `far` the far range, default `100`\n- `near` the near range, default `1 / 100`\n- `position` the camera position, default `[0, 0, 0]`\n- `direction` the camera direction, default `[0, 0, -1]`\n- `up` the camera up vector, default `[0, 1, 0]`\n- `viewport` the screen-space viewport bounds, default `[-1, -1, 1, 1]`\n\nThe `viewport` is used to determine the aspect ratio of the projection, as well as projecting and ray-picking.\n\n## methods\n\n#### `camera.update()`\n\nUpdates the camera projection and view matrices from the camera's current state (position, direction, viewport, etc). \n\n#### `camera.identity()`\n\nResets the `position`, `direction`, `up`, `projection` and `view` values to their identity; the defaults described in the constructor.\n\n#### `camera.translate(vec3)`\n\nTranslates this camera's `position` by the given `vec3`.\n\n#### `camera.lookAt(vec3)`\n\nUpdates the `direction` and `up` to look at the given `vec3` target.\n\n#### `camera.project(vec3)`\n\n[Projects](https://github.com/Jam3/camera-project) the world space 3D point `vec3` into 2D screen-space based on this camera's `viewport` bounds. Returns a new `vec4` point with `z` and `w` components representing the computed depth (similar to `gl_FragCoord`).\n\n#### `camera.unproject(vec3)`\n\n[Unprojects](https://github.com/Jam3/camera-unproject) the screen-space point into 3D world-space. The Z of the screen-space point is between 0 (near plane) and 1 (far plane).\n\n#### `camera.createPickingRay(vec2)`\n\nCreates a new picking ray from the 2D screen-space `vec2` point (i.e. the mouse).\n\nThe ray is an instance of [ray-3d](https://github.com/Jam3/ray-3d), and it can be used for hit-testing.\n\n```js\nvar ray = camera.createPickingRay(mouse)\nif (ray.intersectsSphere(center, radius))\n  console.log(\"Hit!\")\n```\n\n## properties\n\n#### `camera.viewport`\n\nA `[x, y, width, height]` array defining the viewport in screen space.\n\n#### `camera.projection`, `camera.view`\n\nThe 4x4 projection and view matrices, computed after a call to `update()`. \n\n#### `camera.position`, `camera.direction`, `camera.up`\n\nThe current position, direction, and up vectors.\n\n## See Also\n\n- [camera-unproject](https://www.npmjs.com/package/camera-unproject)\n- [camera-project](https://www.npmjs.com/package/camera-project)\n- [camera-picking-ray](https://www.npmjs.com/package/camera-picking-ray)\n- [ray-3d](https://www.npmjs.com/package/ray-3d)\n- [ray-sphere-intersection](https://www.npmjs.com/package/ray-sphere-intersection)\n- [ray-plane-intersection](https://www.npmjs.com/package/ray-plane-intersection)\n- [ray-triangle-intersection](https://www.npmjs.com/package/ray-triangle-intersection)\n\n## License\n\nMIT, see [LICENSE.md](http://github.com/Jam3/perspective-camera/blob/master/LICENSE.md) for details.\n","maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"},{"name":"tatumcreative","email":"tatum.creative@gmail.com"}],"time":{"modified":"2022-06-23T19:04:12.493Z","created":"2015-05-15T17:58:18.049Z","1.0.0":"2015-05-15T17:58:18.049Z","1.0.1":"2015-05-15T19:08:00.214Z","2.0.0":"2015-09-14T00:06:33.672Z","2.0.1":"2015-09-26T18:35:23.528Z"},"homepage":"https://github.com/Jam3/perspective-camera","keywords":["perspective","projection","rendering","3d","webgl","glsl","stackgl","gl-mat4","matrix","matrices","mat4","ray","pick","intersection"],"repository":{"type":"git","url":"git://github.com/Jam3/perspective-camera.git"},"author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"bugs":{"url":"https://github.com/Jam3/perspective-camera/issues"},"license":"MIT","readmeFilename":"README.md","users":{"gregorynicholas":true}}